how to make masterPage contents visible based on role?

吃可爱长大的小学妹 提交于 2019-12-13 16:06:12

问题


I am developing an application with masterPage.

I want to put loginStatus, LoginName controls into masterPage.

now, I want these loginStatus and LoginName controls be visible only if the user is admin. (admin will exclusively navigate to login page and no Login/logout link, logged in username should be shown for non-admins)

how can I achieve this?


回答1:


There is a LoginView, which supports roles:

<asp:LoginView ID="LoginView1" runat="server">
    <RoleGroups>
        <asp:RoleGroup Roles="Admin">

        </asp:RoleGroup>
    </RoleGroups>
</asp:LoginView>



回答2:


Need to know more about your authentication setup, but if you're using the standard ASP.NET role manager, you should be able to do something like this:

loginControl.Visible = Page.User.IsInRole("Admin"); //or whatever the role is



回答3:


check the users role

    if (Page.User.IsInRole("admin"))
    {
        loginStatus.Visible = true;
    }


来源:https://stackoverflow.com/questions/7422267/how-to-make-masterpage-contents-visible-based-on-role

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!