小编Wil*_*iam的帖子

忽略特定操作的控制器路由属性

我的控制器上有很多操作,如果可能的话,我只想将特定路由用于一个操作。我正在寻找一种方法来覆盖在控制器级别定义的路由。

[Route("api/candidate/attached-file")]
public class AttachedFileController : Controller
    {
        //overriding controller route
        [HttpPost("api/candidate/{id}/attached-file")]
        public async Task<IActionResult> AttachFile(string id, [FromBody] AttachedFile file)
        {
            ...
        }

        //using controller route
        [HttpGet("{id}")]
        public ActionResult Get(string id) {}

        [HttpGet]
        public ActionResult GetAll() {}

        ...
    }
Run Code Online (Sandbox Code Playgroud)

c# routing asp.net-core

8
推荐指数
1
解决办法
1921
查看次数

Upload progress using HttpClient in Blazor Wasm

I'm trying to get file upload progress inside a blazor web assembly app.

var handler = new ProgressMessageHandler();
handler.InnerHandler = new WebAssemblyHttpMessageHandler();
handler.HttpSendProgress += (object sender, HttpProgressEventArgs e) =>
{
    Console.WriteLine("bytes transfered= " + e.BytesTransferred.ToString());
    Console.WriteLine("total bytes= " + e.TotalBytes.ToString());
    Console.WriteLine("progress percentage= " + e.ProgressPercentage.ToString());
};

var http = new HttpClient(handler);
http.BaseAddress = new Uri(NavigationManager.BaseUri);
await http.PostJsonAsync("api/...", attachedFile);

Console.WriteLine("Done");
Run Code Online (Sandbox Code Playgroud)

I came up with the following code, but when I upload a file I get a single event instantly reporting 100% …

.net c# dotnet-httpclient blazor blazor-client-side

5
推荐指数
0
解决办法
2072
查看次数