简体   繁体   English

通过 HttpContext.Response 使用表单数据进行重定向

[英]Redirection with form data by HttpContext.Response

I have to redirect user to external identity provider while user is not authenticated, but I must do it with parameters sent as application/x-www-form-urlencoded.当用户未通过身份验证时,我必须将用户重定向到外部身份提供者,但我必须使用作为 application/x-www-form-urlencoded 发送的参数来执行此操作。 How can I do it?我该怎么做? This is my current code of AuthenticationHandler:这是我当前的 AuthenticationHandler 代码:

protected override async Task<AuthenticateResult> HandleRemoteAuthenticateAsync()
{
    Response.ContentType = "application/x-www-form-urlencoded";

    Response.Redirect($"{Options.Authority}/authorization");
}

Response.Redirect means it will tell the client to redirect. Response.Redirect 意味着它将告诉客户端重定向。 The redirect happened at the client and it will just return two 301 and 302 status codes.重定向发生在客户端,它只会返回两个 301 和 302 状态代码。

Details, you could refer to this article .详情,可以参考这篇文章

If you want to send some response body to client and redirect, you could get the url and body, then use js code to redirect to the right url and formdata.如果您想向客户端发送一些响应正文并重定向,您可以获取 url 和正文,然后使用 js 代码重定向到正确的 url 和 formdata。

why do you want to redirect users from the back-end (your server)?为什么要从后端(您的服务器)重定向用户? you can do it easily by JS! JS就可以轻松搞定!

you just need to prepare authentication parameters from the server and combine them with the third-party address and redirect users by JS你只需要从服务器准备认证参数,并结合第三方地址,通过JS重定向用户

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM