将管理员页面和用户重定向到用户页面

时间:2011-11-09 13:59:05

标签: asp.net vb.net authentication response.redirect asp.net-roles

我在这里遇到了一些问题。当用户输入他们的ID时,它将显示主页面及其用户,但是当管理员输入他们的ID时,它将进入用户的主页面,我必须点击顶部超链接上的管理站点,它会自动注销,一旦我输入返回管理员passwrd,然后只重定向到admin page.how使其像用户输入他们的passwrd一样重定向到用户页面,一旦管理员在登录时输入管理员密码,它会重定向到管理员?我在这里有3个角色,这是管理员,工作人员和用户.Hereby我将为您提供我的aspx代码以及我在程序后面运行的vb代码。请帮助我。谢谢

ASPX

   <asp:Login ID="Login1" runat="server" BackColor="#009933" BorderColor="Red" 
        BorderPadding="4" BorderStyle="Ridge" BorderWidth="1px" Font-Names="Verdana" 
        Font-Size="0.8em" ForeColor="Red" 
        DestinationPageUrl="~/MainPage.aspx" style="text-align: center" Height="171px" 
                    Width="266px"  VisibleWhenLoggedIn="True" TextLayout="TextOnTop">
        <TextBoxStyle Font-Size="0.8em" />
        <LoginButtonStyle BackColor="#FFFBFF" BorderColor="#CCCCCC" BorderStyle="Solid" 
            BorderWidth="1px" Font-Names="Verdana" Font-Size="0.8em" ForeColor="#284775" />
        <InstructionTextStyle Font-Italic="True" ForeColor="Black" />
        <TitleTextStyle BackColor="#5D7B9D" Font-Bold="True" Font-Size="0.9em" 
            ForeColor="White" />

    </asp:Login>

VB

Partial Class Login

  Inherits System.Web.UI.Page

End Class
员工文件夹

web.config

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
    <system.web> 
        <authorization> 
            <allow roles="staff" /> <deny users="" /> 
        </authorization> 
    </system.web> 
</configuration> 
admin 文件夹

web.config

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
    <system.web> 
        <authorization> 
            <allow roles="adminstrator" /> <deny users="" /> 
        </authorization> 
    </system.web> 
</configuration>

web.config - root

<configuration> 
    <appSettings/> 
    <connectionStrings> 
        <add name="ConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/> 
        <add name="ASPNETDBConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Se7en\Desktop\Personal\VIVA\1\App_‌​Data\ASPNETDB.MDF;Integrated Security=True;Connect Timeout=30;User Instance=True" providerName="System.Data.SqlClient"/> 
    </connectionStrings> 

2 个答案:

答案 0 :(得分:0)

您可以在登录按钮点击事件中执行此操作:

switch (role)
    {
     case 0:
      Response.Redirect("MainPage.aspx");
      break;
     case 1:
      Response.Redirect("StaffPage.aspx");
      break;
     case 2:
      Response.Redirect("UserPage.aspx");
      break;
}

您需要在验证用户代码中设置角色值。

答案 1 :(得分:0)

刚刚看到您重新编辑的问题...您的导航是什么样的?您使用了哪些控件?你使用什么样的 MembershipProvider (如果有的话)?

您仍可以尝试使用treeView或菜单控件(绑定到站点地图文件)。使用这些控件可以使用 securityTrimming (有关详细信息,请参阅msdn)。

例如(来自msdn):

<system.web>
<!-- …other configuration settings -->
  <siteMap defaultProvider="XmlSiteMapProvider" enabled="true">
    <providers>
      <add name="XmlSiteMapProvider"
        description="Default SiteMap provider."
        type="System.Web.XmlSiteMapProvider "
        siteMapFile="Web.sitemap"
        securityTrimmingEnabled="true" />
    </providers>
  </siteMap>
</system.web>

此属性将更改导航控件中显示的链接的可见性。例如,具有角色管理员的用户 - 只会看到允许他们导航到的那些链接。

您能告诉我们您的导航控件吗? thx提前

相关问题