Forms authorization, only want a few links

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Mar 2004
Posts: 634
Reputation: Slade has a spectacular aura about Slade has a spectacular aura about 
Solved Threads: 7
Slade's Avatar
Slade Slade is offline Offline
Practically a Master Poster

Forms authorization, only want a few links

 
0
  #1
May 16th, 2004
Hey all, I only want a few extra links to appear once authorized and not have the whole web app off limits by using deny users="?". I want it much the same as daniweb, the userCP link isn't visible until a user has logged in, how do I do this in VB .NET?
Formerly known as Slade.
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 634
Reputation: Slade has a spectacular aura about Slade has a spectacular aura about 
Solved Threads: 7
Slade's Avatar
Slade Slade is offline Offline
Practically a Master Poster

Re: Forms authorization, only want a few links

 
0
  #2
May 16th, 2004
I got it working guys! and for your reference, I will show you the code.

My Web.Config:
  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <configuration>
  3. <appSettings>
  4. <add key="strSqlConnectionString" value="server=SLADE;database=sladesfaculty;"/>
  5. <add key="strWebAdminEmail" value="slade@sladesfaculty.com" />
  6. <add key="strWebDevEmail" value="ninjawatch@sladesfaculty.com" />
  7. </appSettings>
  8. <system.web>
  9.  
  10. <!-- DYNAMIC DEBUG COMPILATION
  11. Set compilation debug="true" to insert debugging symbols (.pdb information)
  12. into the compiled page. Because this creates a larger file that executes
  13. more slowly, you should set this value to true only when debugging and to
  14. false at all other times. For more information, refer to the documentation about
  15. debugging ASP.NET files.
  16. -->
  17. <compilation defaultLanguage="vb" debug="true" />
  18.  
  19. <!-- CUSTOM ERROR MESSAGES
  20. Set customErrors mode="On" or "RemoteOnly" to enable custom error messages, "Off" to disable.
  21. Add <error> tags for each of the errors you want to handle.
  22.  
  23. "On" Always display custom (friendly) messages.
  24. "Off" Always display detailed ASP.NET error information.
  25. "RemoteOnly" Display custom (friendly) messages only to users not running
  26. on the local Web server. This setting is recommended for security purposes, so
  27. that you do not display application detail information to remote clients.
  28. -->
  29. <customErrors mode="Off" />
  30.  
  31. <!-- AUTHENTICATION
  32. This section sets the authentication policies of the application. Possible modes are "Windows",
  33. "Forms", "Passport" and "None"
  34.  
  35. "None" No authentication is performed.
  36. "Windows" IIS performs authentication (Basic, Digest, or Integrated Windows) according to
  37. its settings for the application. Anonymous access must be disabled in IIS.
  38. "Forms" You provide a custom form (Web page) for users to enter their credentials, and then
  39. you authenticate them in your application. A user credential token is stored in a cookie.
  40. "Passport" Authentication is performed via a centralized authentication service provided
  41. by Microsoft that offers a single logon and core profile services for member sites.
  42. -->
  43. <authentication mode="Forms">
  44. <forms name="SFWeb" loginUrl="FacLogin.aspx" protection="All" path="/" timeout="30">
  45. <credentials passwordFormat = "Clear">
  46. <user name="Slade" password="test"/>
  47. <user name="Scod" password="test"/>
  48. <user name="Boonta" password="test"/>
  49. <user name="Zorbskie" password="test"/>
  50. <user name="Head_Hunter" password="test"/>
  51. </credentials>
  52. </forms>
  53. </authentication>
  54.  
  55. <!-- AUTHORIZATION
  56. This section sets the authorization policies of the application. You can allow or deny access
  57. to application resources by user or role. Wildcards: "*" mean everyone, "?" means anonymous
  58. (unauthenticated) users.
  59. -->
  60. <authorization>
  61. <allow users="*" /> <!-- Allow all users -->
  62.  
  63. <!-- <allow users="[comma separated list of users]"
  64. roles="[comma separated list of roles]"/>
  65. <deny users="[comma separated list of users]"
  66. roles="[comma separated list of roles]"/>
  67. -->
  68. </authorization>
  69.  
  70. <!-- APPLICATION-LEVEL TRACE LOGGING
  71. Application-level tracing enables trace log output for every page within an application.
  72. Set trace enabled="true" to enable application trace logging. If pageOutput="true", the
  73. trace information will be displayed at the bottom of each page. Otherwise, you can view the
  74. application trace log by browsing the "trace.axd" page from your web application
  75. root.
  76. -->
  77. <trace enabled="false" requestLimit="10" pageOutput="false" traceMode="SortByTime" localOnly="true" />
  78.  
  79.  
  80. <!-- SESSION STATE SETTINGS
  81. By default ASP.NET uses cookies to identify which requests belong to a particular session.
  82. If cookies are not available, a session can be tracked by adding a session identifier to the URL.
  83. To disable cookies, set sessionState cookieless="true".
  84. -->
  85. <sessionState
  86. mode="InProc"
  87. stateConnectionString="tcpip=127.0.0.1:42424"
  88. sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes"
  89. cookieless="false"
  90. timeout="20"
  91. />
  92.  
  93. <!-- GLOBALIZATION
  94. This section sets the globalization settings of the application.
  95. -->
  96. <globalization requestEncoding="utf-8" responseEncoding="utf-8" />
  97.  
  98. </system.web>
  99.  
  100. </configuration>

My Login VB code:
  1. Imports System.Web.Security
  2. Public Class FacLogin
  3. Inherits System.Web.UI.Page
  4.  
  5.  
  6. #Region " Web Form Designer Generated Code "
  7.  
  8. 'This call is required by the Web Form Designer.
  9. <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
  10.  
  11. End Sub
  12. Protected WithEvents Label1 As System.Web.UI.WebControls.Label
  13. Protected WithEvents txtUser As System.Web.UI.WebControls.TextBox
  14. Protected WithEvents vUserName As System.Web.UI.WebControls.RequiredFieldValidator
  15. Protected WithEvents Label2 As System.Web.UI.WebControls.Label
  16. Protected WithEvents txtPass As System.Web.UI.WebControls.TextBox
  17. Protected WithEvents vUserPass As System.Web.UI.WebControls.RequiredFieldValidator
  18. Protected WithEvents chkPersist As System.Web.UI.WebControls.CheckBox
  19. Protected WithEvents cmdLogin As System.Web.UI.HtmlControls.HtmlInputButton
  20. Protected WithEvents lblStatus As System.Web.UI.WebControls.Label
  21. Protected WithEvents lblCurrentUser As System.Web.UI.WebControls.Label
  22.  
  23. 'NOTE: The following placeholder declaration is required by the Web Form Designer.
  24. 'Do not delete or move it.
  25. Private designerPlaceholderDeclaration As System.Object
  26.  
  27. Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
  28. 'CODEGEN: This method call is required by the Web Form Designer
  29. 'Do not modify it using the code editor.
  30. InitializeComponent()
  31. End Sub
  32.  
  33. #End Region
  34.  
  35. Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  36. 'Put user code to initialize the page here
  37. 'verify authentication
  38. If User.Identity.IsAuthenticated Then
  39. 'display Credential information
  40. lblCurrentUser.Text = "Current User: <b>" & User.Identity.Name & "</b>" & _
  41. "<br>Authentication Used : <b>" & User.Identity.AuthenticationType & "</b>"
  42.  
  43. End If
  44. End Sub
  45.  
  46.  
  47. Private Sub cmdLogin_ServerClick(ByVal sender As System.Object, ByVal e As System.EventArgs) _
  48. Handles cmdLogin.ServerClick
  49. If FormsAuthentication.Authenticate(txtUser.Text, txtPass.Text) Then
  50. FormsAuthentication.RedirectFromLoginPage(txtUser.Text, chkPersist.Checked)
  51. Else
  52. lblStatus.Text = "Not Authenticated"
  53. If CInt(ViewState("Tries")) > 1 Then
  54. Response.Redirect("Denied.aspx")
  55. Else
  56. ' Otherwise, increment number of tries.
  57. ViewState("Tries") = CInt(ViewState("Tries")) + 1
  58. End If
  59. End If
  60.  
  61. 'Dim tkt As FormsAuthenticationTicket
  62. 'Dim cookiestr As String
  63. 'Dim ck As HttpCookie
  64.  
  65. 'tkt = New FormsAuthenticationTicket(1, txtUser.Text, DateTime.Now(), _
  66. 'DateTime.Now.AddMinutes(30), chkPersist.Checked, "your custom data")
  67. 'cookiestr = FormsAuthentication.Encrypt(tkt)
  68. 'ck = New HttpCookie(FormsAuthentication.FormsCookieName(), cookiestr)
  69.  
  70. 'If (chkPersist.Checked) Then ck.Expires = tkt.Expiration
  71. 'ck.Path = FormsAuthentication.FormsCookiePath()
  72. 'Response.Cookies.Add(ck)
  73.  
  74. 'Dim strRedirect As String
  75. 'strRedirect = Request("ReturnURL")
  76. 'If strRedirect <> "" Then
  77. 'Response.Redirect(strRedirect, True)
  78. 'Else
  79. ' strRedirect = "default.aspx"
  80. ' Response.Redirect(strRedirect, True)
  81. 'End If
  82. 'Else
  83. 'Response.Redirect("FacLogon.aspx", True)
  84. 'End If
  85.  
  86. 'If CInt(ViewState("Tries")) > 1 Then
  87. 'Response.Redirect("Denied.aspx")
  88. 'Else
  89. ' Otherwise, increment number of tries.
  90. ' ViewState("Tries") = CInt(ViewState("Tries")) + 1
  91. 'End If
  92.  
  93. End Sub
  94.  
  95.  
  96. End Class
I'm not going to post any more because otherwise it's going to get too big but if you wanna know what I put in the header control or anything else, just ask.
Last edited by slade; May 16th, 2004 at 2:25 am. Reason: WYSIWYG wasn't a WYSIWYG
Formerly known as Slade.
Reply With Quote Quick reply to this message  
Join Date: Feb 2003
Posts: 793
Reputation: Paladine has a spectacular aura about Paladine has a spectacular aura about Paladine has a spectacular aura about 
Solved Threads: 27
Team Colleague
Paladine's Avatar
Paladine Paladine is offline Offline
Master Poster

Re: Forms authorization, only want a few links

 
0
  #3
May 16th, 2004
Code looks good Slade, but it is 2:30am and I am not following it as well as I should. I want go through your discovery and see what it is all about tomorrow.

Good post!
Assistant Manager, Pharmacy Informatics
Wordpress Learning Blog
Updated : ASP.Net Login Code
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 634
Reputation: Slade has a spectacular aura about Slade has a spectacular aura about 
Solved Threads: 7
Slade's Avatar
Slade Slade is offline Offline
Practically a Master Poster

Re: Forms authorization, only want a few links

 
0
  #4
May 16th, 2004
lol, sorry about all the comments in there too, I was debugging and forgot to remove them before posting. I might wait until I'm fully finished the internal GUI before I post the code. ahhh what the hey, here's the header:
  1. Imports System.Web.Security
  2. Imports sladesfaculty.header
  3. Public Class header
  4. Inherits System.Web.UI.UserControl
  5.  
  6.  
  7. #Region " Web Form Designer Generated Code "
  8.  
  9. 'This call is required by the Web Form Designer.
  10. <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
  11.  
  12. End Sub
  13. Protected WithEvents imgHome As System.Web.UI.WebControls.ImageButton
  14. Protected WithEvents imgForums As System.Web.UI.WebControls.ImageButton
  15. Protected WithEvents imgGallery As System.Web.UI.WebControls.ImageButton
  16. Protected WithEvents imgLinks As System.Web.UI.WebControls.ImageButton
  17. Protected WithEvents imgMission As System.Web.UI.WebControls.ImageButton
  18. Protected WithEvents imgMembers As System.Web.UI.WebControls.ImageButton
  19. Protected WithEvents imgFacLogin As System.Web.UI.WebControls.ImageButton
  20. Protected WithEvents lblTest As System.Web.UI.WebControls.Label
  21.  
  22. 'NOTE: The following placeholder declaration is required by the Web Form Designer.
  23. 'Do not delete or move it.
  24. Private designerPlaceholderDeclaration As System.Object
  25.  
  26. Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
  27. 'CODEGEN: This method call is required by the Web Form Designer
  28. 'Do not modify it using the code editor.
  29. InitializeComponent()
  30. End Sub
  31.  
  32. #End Region
  33.  
  34. Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  35. 'verify authentication
  36. 'Put user code to initialize the page here
  37. 'verify authentication
  38. If Page.User.Identity.IsAuthenticated Then
  39. 'display Credential information
  40. lblTest.Text = "Current User:<b>&nbsp;" & Page.User.Identity.Name
  41.  
  42. End If
  43.  
  44. Dim currentpage As String
  45. currentpage = Request.RawUrl
  46. Select Case currentpage
  47. Case "/sladesfaculty/default.aspx"
  48. imgHome.ImageUrl = "/sladesfaculty/Images/Navigation/homeactv.gif"
  49. imgForums.ImageUrl = "/sladesfaculty/Images/Navigation/foruminac.gif"
  50. imgGallery.ImageUrl = "/sladesfaculty/Images/Navigation/galryinac.gif"
  51. imgLinks.ImageUrl = "/sladesfaculty/Images/Navigation/lnksinac.gif"
  52. imgMission.ImageUrl = "/sladesfaculty/Images/Navigation/msninac.gif"
  53. imgMembers.ImageUrl = "/sladesfaculty/Images/Navigation/mbrsinac.gif"
  54.  
  55. Case "/sladesfaculty/Default.aspx"
  56. imgHome.ImageUrl = "/sladesfaculty/Images/Navigation/homeactv.gif"
  57. imgForums.ImageUrl = "/sladesfaculty/Images/Navigation/foruminac.gif"
  58. imgGallery.ImageUrl = "/sladesfaculty/Images/Navigation/galryinac.gif"
  59. imgLinks.ImageUrl = "/sladesfaculty/Images/Navigation/lnksinac.gif"
  60. imgMission.ImageUrl = "/sladesfaculty/Images/Navigation/msninac.gif"
  61. imgMembers.ImageUrl = "/sladesfaculty/Images/Navigation/mbrsinac.gif"
  62.  
  63. Case "/sladesfaculty/Forums.aspx"
  64. imgHome.ImageUrl = "/sladesfaculty/Images/Navigation/homeinac.gif"
  65. imgForums.ImageUrl = "/sladesfaculty/Images/Navigation/forumactv.gif"
  66. imgGallery.ImageUrl = "/sladesfaculty/Images/Navigation/galryinac.gif"
  67. imgLinks.ImageUrl = "/sladesfaculty/Images/Navigation/lnksinac.gif"
  68. imgMission.ImageUrl = "/sladesfaculty/Images/Navigation/msninac.gif"
  69. imgMembers.ImageUrl = "/sladesfaculty/Images/Navigation/mbrsinac.gif"
  70.  
  71. Case "/sladesfaculty/Gallery.aspx"
  72. imgHome.ImageUrl = "/sladesfaculty/Images/Navigation/homeinac.gif"
  73. imgForums.ImageUrl = "/sladesfaculty/Images/Navigation/foruminac.gif"
  74. imgGallery.ImageUrl = "/sladesfaculty/Images/Navigation/galryactv.gif"
  75. imgLinks.ImageUrl = "/sladesfaculty/Images/Navigation/lnksinac.gif"
  76. imgMission.ImageUrl = "/sladesfaculty/Images/Navigation/msninac.gif"
  77. imgMembers.ImageUrl = "/sladesfaculty/Images/Navigation/mbrsinac.gif"
  78.  
  79. Case "/sladesfaculty/Links.aspx"
  80. imgHome.ImageUrl = "/sladesfaculty/Images/Navigation/homeinac.gif"
  81. imgForums.ImageUrl = "/sladesfaculty/Images/Navigation/foruminac.gif"
  82. imgGallery.ImageUrl = "/sladesfaculty/Images/Navigation/galryinac.gif"
  83. imgLinks.ImageUrl = "/sladesfaculty/Images/Navigation/lnksactv.gif"
  84. imgMission.ImageUrl = "/sladesfaculty/Images/Navigation/msninac.gif"
  85. imgMembers.ImageUrl = "/sladesfaculty/Images/Navigation/mbrsinac.gif"
  86.  
  87. Case "/sladesfaculty/Mission.aspx"
  88. imgHome.ImageUrl = "/sladesfaculty/Images/Navigation/homeinac.gif"
  89. imgForums.ImageUrl = "/sladesfaculty/Images/Navigation/foruminac.gif"
  90. imgGallery.ImageUrl = "/sladesfaculty/Images/Navigation/galryinac.gif"
  91. imgLinks.ImageUrl = "/sladesfaculty/Images/Navigation/lnksinac.gif"
  92. imgMission.ImageUrl = "/sladesfaculty/Images/Navigation/msnactv.gif"
  93. imgMembers.ImageUrl = "/sladesfaculty/Images/Navigation/mbrsinac.gif"
  94.  
  95. Case "/sladesfaculty/Members.aspx"
  96. imgHome.ImageUrl = "/sladesfaculty/Images/Navigation/homeinac.gif"
  97. imgForums.ImageUrl = "/sladesfaculty/Images/Navigation/foruminac.gif"
  98. imgGallery.ImageUrl = "/sladesfaculty/Images/Navigation/galryinac.gif"
  99. imgLinks.ImageUrl = "/sladesfaculty/Images/Navigation/lnksinac.gif"
  100. imgMission.ImageUrl = "/sladesfaculty/Images/Navigation/msninac.gif"
  101. imgMembers.ImageUrl = "/sladesfaculty/Images/Navigation/mbrsactv.gif"
  102. End Select
  103.  
  104.  
  105.  
  106. End Sub
  107.  
  108. Private Sub imgHome_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles imgHome.Click
  109. Response.Redirect("Default.aspx")
  110. End Sub
  111.  
  112. Private Sub imgForums_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles imgForums.Click
  113. Response.Redirect("Forums.aspx")
  114. End Sub
  115.  
  116. Private Sub imgGallery_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles imgGallery.Click
  117. Response.Redirect("Gallery.aspx")
  118. End Sub
  119.  
  120. Private Sub imgLinks_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles imgLinks.Click
  121. Response.Redirect("Links.aspx")
  122. End Sub
  123.  
  124. Private Sub imgMission_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles imgMission.Click
  125. Response.Redirect("Mission.aspx")
  126. End Sub
  127.  
  128. Private Sub imgMembers_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles imgMembers.Click
  129. Response.Redirect("Members.aspx")
  130. End Sub
  131.  
  132. Private Sub imgFacLogin_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles imgFacLogin.Click
  133. Response.Redirect("FacLogin.aspx")
  134. End Sub
  135. End Class
  136.  
I had trouble with this because since it is a control, you can't just pull the authentication values out ie,
  1. If User.Identity.IsAuthenticated Then
  2. 'display Credential information
  3. lblTest.Text = "Current User:<b>&nbsp;" & User.Identity.Name
  4.  
That wont work because you have to pull the authentication values from the cookies on the page, so I had to put:
  1. If Page.User.Identity.IsAuthenticated Then
  2. 'display Credential information
  3. lblTest.Text = "Current User:<b>&nbsp;" & Page.User.Identity.Name
  4.  
By the way, the code for the login is awesome because if the password is incorrect after three tries, the user is redirected to a page called "Denied.aspx" with the following code:
  1. If CInt(ViewState("Tries")) > 1 Then
  2. Response.Redirect("Denied.aspx")
  3. Else
  4. ' Otherwise, increment number of tries.
  5. ViewState("Tries") = CInt(ViewState("Tries")) + 1
  6. End If
  7.  
Also, remember when you are working with forms authentication to always include the following at the top of each page:
  1. Imports System.Web.Security
I'm not sure an amaeture like me should be giving out tips but what the hey. Remember when editing the web.config it is EXTREMELY sensitive, one wrong capital somewhere, one incorrect character and the whole code is stuffed. I highly recommend not just copying and pasting it off the web (personal experiece:o). If you want to see the asp code for the logon page, it's as attached, for some reason it wouldn't let me post it as code *shrugs*. If you would like to know any more, just post back!

Slade (I'm getting better at this I think)
Attached Files
File Type: txt FacLogon.aspx.txt (3.2 KB, 11 views)
Formerly known as Slade.
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 634
Reputation: Slade has a spectacular aura about Slade has a spectacular aura about 
Solved Threads: 7
Slade's Avatar
Slade Slade is offline Offline
Practically a Master Poster

Re: Forms authorization, only want a few links

 
0
  #5
May 16th, 2004
I am so glad I posted all of this, my hard drive crashed this morning.
Formerly known as Slade.
Reply With Quote Quick reply to this message  
Join Date: Feb 2003
Posts: 793
Reputation: Paladine has a spectacular aura about Paladine has a spectacular aura about Paladine has a spectacular aura about 
Solved Threads: 27
Team Colleague
Paladine's Avatar
Paladine Paladine is offline Offline
Master Poster

Re: Forms authorization, only want a few links

 
0
  #6
May 17th, 2004
Ah man, that sucks.
Assistant Manager, Pharmacy Informatics
Wordpress Learning Blog
Updated : ASP.Net Login Code
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 634
Reputation: Slade has a spectacular aura about Slade has a spectacular aura about 
Solved Threads: 7
Slade's Avatar
Slade Slade is offline Offline
Practically a Master Poster

Re: Forms authorization, only want a few links

 
0
  #7
May 17th, 2004
ooooh yes. I think I might post an article on forms authorization, it took me a while to get it to do what I want to do.
Formerly known as Slade.
Reply With Quote Quick reply to this message  
Join Date: Feb 2003
Posts: 793
Reputation: Paladine has a spectacular aura about Paladine has a spectacular aura about Paladine has a spectacular aura about 
Solved Threads: 27
Team Colleague
Paladine's Avatar
Paladine Paladine is offline Offline
Master Poster

Re: Forms authorization, only want a few links

 
0
  #8
May 23rd, 2004
Look forward to seeing that article.
Assistant Manager, Pharmacy Informatics
Wordpress Learning Blog
Updated : ASP.Net Login Code
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 634
Reputation: Slade has a spectacular aura about Slade has a spectacular aura about 
Solved Threads: 7
Slade's Avatar
Slade Slade is offline Offline
Practically a Master Poster

Re: Forms authorization, only want a few links

 
0
  #9
May 23rd, 2004
You will see it as soon as I get my computer up and running again lol
Formerly known as Slade.
Reply With Quote Quick reply to this message  
Join Date: Nov 2005
Posts: 4
Reputation: miragefighter is an unknown quantity at this point 
Solved Threads: 1
miragefighter miragefighter is offline Offline
Newbie Poster

Re: Forms authorization, only want a few links

 
0
  #10
Nov 21st, 2005
Originally Posted by incognito
lol, sorry about all the comments in there too, I was debugging and forgot to remove them before posting. I might wait until I'm fully finished the internal GUI before I post the code. ahhh what the hey, here's the header:
  1. Imports System.Web.Security
  2. Imports sladesfaculty.header
  3. Public Class header
  4. Inherits System.Web.UI.UserControl
  5.  
  6.  
  7. #Region " Web Form Designer Generated Code "
  8.  
  9. 'This call is required by the Web Form Designer.
  10. <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
  11.  
  12. End Sub
  13. Protected WithEvents imgHome As System.Web.UI.WebControls.ImageButton
  14. Protected WithEvents imgForums As System.Web.UI.WebControls.ImageButton
  15. Protected WithEvents imgGallery As System.Web.UI.WebControls.ImageButton
  16. Protected WithEvents imgLinks As System.Web.UI.WebControls.ImageButton
  17. Protected WithEvents imgMission As System.Web.UI.WebControls.ImageButton
  18. Protected WithEvents imgMembers As System.Web.UI.WebControls.ImageButton
  19. Protected WithEvents imgFacLogin As System.Web.UI.WebControls.ImageButton
  20. Protected WithEvents lblTest As System.Web.UI.WebControls.Label
  21.  
  22. 'NOTE: The following placeholder declaration is required by the Web Form Designer.
  23. 'Do not delete or move it.
  24. Private designerPlaceholderDeclaration As System.Object
  25.  
  26. Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
  27. 'CODEGEN: This method call is required by the Web Form Designer
  28. 'Do not modify it using the code editor.
  29. InitializeComponent()
  30. End Sub
  31.  
  32. #End Region
  33.  
  34. Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  35. 'verify authentication
  36. 'Put user code to initialize the page here
  37. 'verify authentication
  38. If Page.User.Identity.IsAuthenticated Then
  39. 'display Credential information
  40. lblTest.Text = "Current User:<b>&nbsp;" & Page.User.Identity.Name
  41.  
  42. End If
  43.  
  44. Dim currentpage As String
  45. currentpage = Request.RawUrl
  46. Select Case currentpage
  47. Case "/sladesfaculty/default.aspx"
  48. imgHome.ImageUrl = "/sladesfaculty/Images/Navigation/homeactv.gif"
  49. imgForums.ImageUrl = "/sladesfaculty/Images/Navigation/foruminac.gif"
  50. imgGallery.ImageUrl = "/sladesfaculty/Images/Navigation/galryinac.gif"
  51. imgLinks.ImageUrl = "/sladesfaculty/Images/Navigation/lnksinac.gif"
  52. imgMission.ImageUrl = "/sladesfaculty/Images/Navigation/msninac.gif"
  53. imgMembers.ImageUrl = "/sladesfaculty/Images/Navigation/mbrsinac.gif"
  54.  
  55. Case "/sladesfaculty/Default.aspx"
  56. imgHome.ImageUrl = "/sladesfaculty/Images/Navigation/homeactv.gif"
  57. imgForums.ImageUrl = "/sladesfaculty/Images/Navigation/foruminac.gif"
  58. imgGallery.ImageUrl = "/sladesfaculty/Images/Navigation/galryinac.gif"
  59. imgLinks.ImageUrl = "/sladesfaculty/Images/Navigation/lnksinac.gif"
  60. imgMission.ImageUrl = "/sladesfaculty/Images/Navigation/msninac.gif"
  61. imgMembers.ImageUrl = "/sladesfaculty/Images/Navigation/mbrsinac.gif"
  62.  
  63. Case "/sladesfaculty/Forums.aspx"
  64. imgHome.ImageUrl = "/sladesfaculty/Images/Navigation/homeinac.gif"
  65. imgForums.ImageUrl = "/sladesfaculty/Images/Navigation/forumactv.gif"
  66. imgGallery.ImageUrl = "/sladesfaculty/Images/Navigation/galryinac.gif"
  67. imgLinks.ImageUrl = "/sladesfaculty/Images/Navigation/lnksinac.gif"
  68. imgMission.ImageUrl = "/sladesfaculty/Images/Navigation/msninac.gif"
  69. imgMembers.ImageUrl = "/sladesfaculty/Images/Navigation/mbrsinac.gif"
  70.  
  71. Case "/sladesfaculty/Gallery.aspx"
  72. imgHome.ImageUrl = "/sladesfaculty/Images/Navigation/homeinac.gif"
  73. imgForums.ImageUrl = "/sladesfaculty/Images/Navigation/foruminac.gif"
  74. imgGallery.ImageUrl = "/sladesfaculty/Images/Navigation/galryactv.gif"
  75. imgLinks.ImageUrl = "/sladesfaculty/Images/Navigation/lnksinac.gif"
  76. imgMission.ImageUrl = "/sladesfaculty/Images/Navigation/msninac.gif"
  77. imgMembers.ImageUrl = "/sladesfaculty/Images/Navigation/mbrsinac.gif"
  78.  
  79. Case "/sladesfaculty/Links.aspx"
  80. imgHome.ImageUrl = "/sladesfaculty/Images/Navigation/homeinac.gif"
  81. imgForums.ImageUrl = "/sladesfaculty/Images/Navigation/foruminac.gif"
  82. imgGallery.ImageUrl = "/sladesfaculty/Images/Navigation/galryinac.gif"
  83. imgLinks.ImageUrl = "/sladesfaculty/Images/Navigation/lnksactv.gif"
  84. imgMission.ImageUrl = "/sladesfaculty/Images/Navigation/msninac.gif"
  85. imgMembers.ImageUrl = "/sladesfaculty/Images/Navigation/mbrsinac.gif"
  86.  
  87. Case "/sladesfaculty/Mission.aspx"
  88. imgHome.ImageUrl = "/sladesfaculty/Images/Navigation/homeinac.gif"
  89. imgForums.ImageUrl = "/sladesfaculty/Images/Navigation/foruminac.gif"
  90. imgGallery.ImageUrl = "/sladesfaculty/Images/Navigation/galryinac.gif"
  91. imgLinks.ImageUrl = "/sladesfaculty/Images/Navigation/lnksinac.gif"
  92. imgMission.ImageUrl = "/sladesfaculty/Images/Navigation/msnactv.gif"
  93. imgMembers.ImageUrl = "/sladesfaculty/Images/Navigation/mbrsinac.gif"
  94.  
  95. Case "/sladesfaculty/Members.aspx"
  96. imgHome.ImageUrl = "/sladesfaculty/Images/Navigation/homeinac.gif"
  97. imgForums.ImageUrl = "/sladesfaculty/Images/Navigation/foruminac.gif"
  98. imgGallery.ImageUrl = "/sladesfaculty/Images/Navigation/galryinac.gif"
  99. imgLinks.ImageUrl = "/sladesfaculty/Images/Navigation/lnksinac.gif"
  100. imgMission.ImageUrl = "/sladesfaculty/Images/Navigation/msninac.gif"
  101. imgMembers.ImageUrl = "/sladesfaculty/Images/Navigation/mbrsactv.gif"
  102. End Select
  103.  
  104.  
  105.  
  106. End Sub
  107.  
  108. Private Sub imgHome_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles imgHome.Click
  109. Response.Redirect("Default.aspx")
  110. End Sub
  111.  
  112. Private Sub imgForums_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles imgForums.Click
  113. Response.Redirect("Forums.aspx")
  114. End Sub
  115.  
  116. Private Sub imgGallery_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles imgGallery.Click
  117. Response.Redirect("Gallery.aspx")
  118. End Sub
  119.  
  120. Private Sub imgLinks_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles imgLinks.Click
  121. Response.Redirect("Links.aspx")
  122. End Sub
  123.  
  124. Private Sub imgMission_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles imgMission.Click
  125. Response.Redirect("Mission.aspx")
  126. End Sub
  127.  
  128. Private Sub imgMembers_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles imgMembers.Click
  129. Response.Redirect("Members.aspx")
  130. End Sub
  131.  
  132. Private Sub imgFacLogin_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles imgFacLogin.Click
  133. Response.Redirect("FacLogin.aspx")
  134. End Sub
  135. End Class
  136.  
I had trouble with this because since it is a control, you can't just pull the authentication values out ie,
  1. If User.Identity.IsAuthenticated Then
  2. 'display Credential information
  3. lblTest.Text = "Current User:<b>&nbsp;" & User.Identity.Name
  4.  
That wont work because you have to pull the authentication values from the cookies on the page, so I had to put:
  1. If Page.User.Identity.IsAuthenticated Then
  2. 'display Credential information
  3. lblTest.Text = "Current User:<b>&nbsp;" & Page.User.Identity.Name
  4.  
By the way, the code for the login is awesome because if the password is incorrect after three tries, the user is redirected to a page called "Denied.aspx" with the following code:
  1. If CInt(ViewState("Tries")) > 1 Then
  2. Response.Redirect("Denied.aspx")
  3. Else
  4. ' Otherwise, increment number of tries.
  5. ViewState("Tries") = CInt(ViewState("Tries")) + 1
  6. End If
  7.  
Also, remember when you are working with forms authentication to always include the following at the top of each page:
  1. Imports System.Web.Security
I'm not sure an amaeture like me should be giving out tips but what the hey. Remember when editing the web.config it is EXTREMELY sensitive, one wrong capital somewhere, one incorrect character and the whole code is stuffed. I highly recommend not just copying and pasting it off the web (personal experiece:o). If you want to see the asp code for the logon page, it's as attached, for some reason it wouldn't let me post it as code *shrugs*. If you would like to know any more, just post back!

Slade (I'm getting better at this I think)
The codes look great, I'm looking beyond the authentication stage, once user login, how to retrieve this particular user's data from the database (SQL Server)? I want to retrieve the user's data from database based on the user's login, eg. User.Identity.Name, then display the data inside the textboxes. Any idea how to get data and display in the textbox? Thanks
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC