0

i'm having some problem over here. When user enter their id,it will show up the main page and its for user but when admin enter their id,it will enter the user's main page and i have to click admin site on the top hyperlink and it automatically logout and once i enter back admin passwrd and then only it redirect to admin page.how to make it like once user enter their passwrd it redirect to user page and once admin enter admin password in the login it redirect to admin ?I have 3 roles over here which are admin,staff and user.Hereby i'll provide you my aspx code and also my vb code which is running behind the program.please do assist me.thanks

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 for staff folder

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

web.config for admin folder

<?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> 

4

2 回答 2

0

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

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

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

于 2011-11-09T14:09:31.573 回答
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>

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

您能否向我们展示您的导航控件?提前谢谢

于 2011-11-09T14:10:01.673 回答