Determine if user can access the requested page?

后端 未结 7 1495
小鲜肉
小鲜肉 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条回答
  •  我在风中等你
    2021-01-05 11:38

    One other option is to set a session variable when you're checking rights, and displaying that on the login page.

    So you could do:

    if(!User.IsInRole("shopper"))
    {
        session("denied") = "You don't have access to shop";
        response.redirect("/login");
    }
    

    Then in the login page:

    if ( session("denied") != "" ) {
       message.text = session("denied");
       session("denied") = "";
    }
    

提交回复
热议问题