Determine if user can access the requested page?

后端 未结 7 1405
小鲜肉
小鲜肉 2021-01-05 10:36

I have an ASP.Net website with multiple roles, each with access to a separate directory (i.e. admin users can access /admin, shoppers can access /shop etc), using a shared l

7条回答
  •  -上瘾入骨i
    2021-01-05 11:24

    I ended up doing this in the page_load event of the login page:

    if (User.Identity.IsAuthenticated)
    {
        LoginErrorDetails.Text = "You are not authorized to view the requested page";
    }
    

    The thinking being, if an authenticated user ends up at the login page, they have either been sent their as a result of trying to access an page they are not authorized to view, or they have authenticated and then manually gone to the log in page (unlikely).

    A further action would be to send the user to the relevant home page whenever they visit the login page, if they are already authenticated.

提交回复
热议问题