How to Redirect Users to an ASP.NET page when not Authorized?

前端 未结 6 918
小蘑菇
小蘑菇 2020-12-28 15:33

I need my users are redirected to AuthError.aspx page (\"You don\'t have the access to this page\") in the case when they are authenticated but try to access the page that t

6条回答
  •  长情又很酷
    2020-12-28 16:14

    For me the least hassle most benefit solution to this problem was to create another section (panel) in Login.aspx page with contents to be displayed to users who are authenticated (e.g. logged in) saying "Access denied" instead of the login form. When logged in user hits the page it means they most likely ended up here because they are not authenticated to access the page that redirected them here.

    In the login page I use this very simple code to switch visibility of the panel and login form:

    if (Request.IsAuthenticated)
    {
        LoginUser.Visible = false;
        AccessDeniedPanel.Visible = true;
    }
    

    It's dead simple and it works.

提交回复
热议问题