Base solution for your next web application
Open Closed

AbpMvcAuthorize Redirect to UnAuth Page Not Login #4049


User avatar
0
blewis created

I use the AbpMvcAuthorize attribute on many controller methods (not the entire controller) to grant privileges. However, if the user doesn't have that permission, the default action of the attribute seems to be to redirect back to the login page. Because I am using OpenID SSO, it redirects the user to the SSO login page. What I want to do is to just take them to a static "Unauthorized" page that I have created. Is that possible?

Thanks, Bryan


7 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    You can override HandleUnauthorizedRequest method of AbpMvcAuthorizeAttribute and redirect to unauthorized page.

  • User Avatar
    0
    dalepalmer created

    Could you do this to redirect to different login pages based on area?

    If so how?

    Thanks in advance

    Dale

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @DalePalmer,

    I think it is possible. Have you tried it ? Did you get an error ?

  • User Avatar
    0
    dalepalmer created

    Not too sure where to start on doing it to be honest.

    Is it an override just for the controller? Just a bit of guidance would be really appreciated.

    Thanks

    Dale

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @DalePalmer,

    Basically, you need to create a new attribute which is derived from AbpMvcAuthorizeAttribute. Then you need to override HandleUnauthorizedRequest method in it and use it in your controllers.

    But there might be an easier solution as well. Are you sing MVC 5.x, Web API or ASP.NET Core ?

  • User Avatar
    0
    dalepalmer created

    .net Core with JQuery

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Then you can define a custom middleware to handle this, please check this document for writing a custom middleware <a class="postlink" href="https://blogs.msdn.microsoft.com/dotnet/2016/09/19/custom-asp-net-core-middleware-example/">https://blogs.msdn.microsoft.com/dotnet ... e-example/</a>.