Home > Net >  Redirection with form data by HttpContext.Response
Redirection with form data by HttpContext.Response

Time:06-13

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. How can I do it? This is my current code of AuthenticationHandler:

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

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

CodePudding user response:

Response.Redirect means it will tell the client to redirect. The redirect happened at the client and it will just return two 301 and 302 status codes.

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.

CodePudding user response:

why do you want to redirect users from the back-end (your server)? you can do it easily by JS!

you just need to prepare authentication parameters from the server and combine them with the third-party address and redirect users by JS

  • Related