0

let's say i have two privileges : Admin and Host and i have a default page.

after logging in : admin users can see everything but host users can't see few buttons in the page

so am i supposed to duplicate the default page? or is there a way to disable the buttons on redirection to the default page?

  If Login1.Password = Session("pwd") Then
        Response.Redirect("profile_test_1.aspx")
    End If

note that I'm using web applications

Thank you :)

4

2 回答 2

0

您可以创建一个将在验证用户后运行的子程序。您可以传递一个布尔值管理员,子将隐藏/显示所需的按钮。您可以根据您传递用户角色的方式在 postback 或 page_load 上调用它。

伪代码:

Sub SetPermissions(Byval blAdmin as boolean)

    If blAdmin Then
        'Insert code to showbuttons; ie. btnAdminOnly.Visible = True
    Else
        'Insert code to hide buttons; ie. btnAdminOnly.Visible = False
    End If

End Sub
于 2013-08-22T13:23:39.650 回答
0

我使用 C#,但我很确定这也适合 VB。您可以使用LoginViewweb 控件,当然也可以将所有内容保存在同一页面中。

例子

<asp:LoginView ID="LoginView1" Runat="server">
  <LoggedInTemplate>
   <asp:LoginName ID="LoginName1" Runat="server" 
                  FormatString ="Welcome, {0}"/>
   <br />
    <asp:HyperLink ID="HyperLink1" Runat="server" 
      NavigateUrl="~/MemberPages/ChangePassword.aspx">
      Change Password
    </asp:HyperLink>
  </LoggedInTemplate>
  <AnonymousTemplate>
    <asp:Login id="Login1" runat="server" 
        CreateUserText="Create a new user..."
        CreateUserUrl="~/Register.aspx" 
        PasswordRecoveryUrl="~/Recovery.aspx" 
        UserNameLabelText="E-mail address:" />
  </AnonymousTemplate>
</asp:LoginView>

在此示例中,我为登录用户和匿名用户分隔块,但您可以基于Roles.

来源:http: //msdn.microsoft.com/en-us/library/ms178329%28v=vs.90%29.aspx

于 2013-08-22T13:13:25.910 回答