How to redirect after Azure AD authentication to different controller action in ASP Net Core MVC

前端 未结 3 1861
孤街浪徒
孤街浪徒 2021-01-14 18:26

I have setup my ASP Net Core 2.0 project to authenticate with Azure AD (using the standard Azure AD Identity Authentication template in VS2017 which uses OIDC). Everything i

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-14 18:52

    The default behavior is: user will be redirected to the original page. For example, user is not authenticated and access Index page, after authenticated, he will be redirected to Index page; user is not authenticated and access Contact page, after authenticated, he will be redirected to Contact page.

    As a workaround, you can modify the default website route to redirect user to specific controller/action:

    app.UseMvc(routes =>
    {
        routes.MapRoute(
            name: "default",
            template: "{controller=Account}/{action=CheckSignIn}/{id?}"
        );
    });
    

    After your custom logic, you could redirect user to your truly default page(Home/Index).

提交回复
热议问题