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> 

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
braveen kumar
  • 11
  • 1
  • 2
  • 6

2 Answers2

0

Can you do this in your login button click event:

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

you need to set role value in your validate user code.

janhartmann
  • 14,713
  • 15
  • 82
  • 138
SarahX
  • 61
  • 2
  • 6
  • i dont get how to use that.can you assist me in that because i'm kinda new in using aspx and also vb.how to implement that code?do assist me.thanks – braveen kumar Nov 09 '11 at 18:30
  • the case it shows syntax error...i had got this code but yet its not that helpful If (Session("Loggedin") = 1) Then End If If (GetUserTypeFromUserID(userID) = "admin") Then Response.Redirect("/admin/AdminMainPage.aspx") Else End If If ((GetUserTypeFromUserID(userID) = "staff")) Then Response.Redirect("StaffMainPage.aspx") Else Response.Redirect("MainPage.aspx") End If – braveen kumar Nov 09 '11 at 18:41
0

Just saw your re-edited question... What is your navigation like? What controls do you use? what kind of MembershipProvider (if any) do you use?

You may still try to use a treeView or a menu control (bound to a sitemap file). Using these controls allows you to make use of securityTrimming (see msdn for details).

eg (from 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>

This attribute will change the visibility of links appearing in your navigation controls. For example users with a role admin - will only see those links they are allowed to navigate to.

Could you please show us your navigation controls? thx in advance

Pilgerstorfer Franz
  • 8,303
  • 3
  • 41
  • 54
  • thanks for the reply.Well i'm using a normal asp.net login control which available in the development tool.i have 3 roles all together where it is user,admin and staff with three different folders all together.hw is it to use that case and where to apply it??please do assist me..thanks in advance. – braveen kumar Nov 09 '11 at 18:31
  • so you are using a membership provider? what kind of? could you post / edit your post and add your web.config membership + role settings pls! – Pilgerstorfer Franz Nov 09 '11 at 21:25
  • This is the web config for staff page This is for admin page – braveen kumar Nov 10 '11 at 03:48
  • i just added your config snippets to your question - but i am still missing some membership Provider configuration.. could please post it here or add it to your question! – Pilgerstorfer Franz Nov 10 '11 at 08:31
  • where can i find the membership provider?is it from the databse or where? – braveen kumar Nov 10 '11 at 16:37
  • To be able to use memberships and roles asp.net has to store/manage them. there are some possibilites (sql server, windows, ...) usually there is a membership tag in your root web.config. you may try to find it by using the webSite administration tool, too. – Pilgerstorfer Franz Nov 10 '11 at 16:51
  • there are 3 roles there which is adminstrator,user and staff – braveen kumar Nov 10 '11 at 17:49