问题描述
我有一个Middleware
执行身份验证,然后应该重新路由到Blazor
Web应用程序.
I have a Middleware
which performs an authentification and should then reroute to a Blazor
web application.
问题是我将token
放入请求查询中,并希望将其放入请求正文中.
The problem is that I get the token
put in the request query and I want it in the body of the request.
中间件:
public async Task Invoke(HttpContext context) {
string token = context.Request.Query["token"];
if (!context.User.Identity.IsAuthenticated) {
//do some logic to authenticate
}
else
await this.next(context);
}
配置:
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseResponseCompression();
app.UseAuthentication();
app.UseMiddleware<MultiAuthWare>();
app.UseMvc(routes => {
routes.MapRoute(name: "default", template: "{controller}/{action}/{id?}");
});
app.UseBlazor<Client.Startup>();
}
Blazor入口点:
Blazor entry point:
服务器重定向到http://localhost:[portno]/?token=[a string]
,我不知道为什么.我尝试设置Blazor
入口页面的两个路由的任何人都不会加载它.
The server redirects to : http://localhost:[portno]/?token=[a string]
and I do not know why.Any who i have tried setting both routes for the entry page of Blazor
and it does not load it.
@page "/"
@page "/?token={token}"
@inherits HomeBase
@functions()
{
}
PS:我不明白为什么服务器将token
放在查询字符串中?
PS: I do not understand why does the server put the token
in the query string ?
推荐答案
1)要从get参数中检索token
,您应该解析当前网址,您可以在HomeBase
中完成该操作:
1) To retrieve token
from get parameters you should to parse current url, you can do it in your HomeBase
:
var url = UriHelper.GetAbsoluteUri(); // By injection (see link)
var uriBuilder = new UriBuilder(url); // System namespace
var q = System.Web.HttpUtility.ParseQueryString(uriBuilder.Query);
var token = q["token"];
2)当您谈论在体内发送令牌时,我不理解您问题的第二部分.
2) I don't understand the second part of your question, when you talk about to send token in body.
更多信息,请访问在Blazor组件中获取当前网址
这篇关于如何使用令牌重定向到Blazor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!