Redirect user after authentication with OpenIdConnect in ASP.Net MVC

后端 未结 2 1429
北恋
北恋 2021-01-05 06:31

I am using OpenIdConnect provider with Owin/Katana for authentication in my asp.net mvc application. OpenIdConnect Provide authenticates users against Active Directory. I wa

2条回答
  •  忘掉有多难
    2021-01-05 06:56

    To add to the accepted answer in case someone battles with this like I did. I found that the following options worked for me -

    Option 1

    //redirect to a page 
    context.AuthenticationTicket.Properties.RedirectUri = "Url";
    

    Option 2

    //redirect to a page      
    context.HandleResponse();
    context.Response.Redirect("/Error?message=" + context.Exception.Message);
    

    Be aware that the second option caused my HttpContext.User.Identity to be null. I suppose because HandlResponse discontinues all processing. Still useful if that is not a concern.

提交回复
热议问题