Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. FormsAuthentication

FormsAuthentication

Scheduled Pinned Locked Moved ASP.NET
designsysadminhelp
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mkanchha
    wrote on last edited by
    #1

    Hi to all, I am trying to use FormsAuthentication in my Project but I am getting some Problems. Code 1: Private Sub imgbtnSubmit_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles imgbtnSubmit.Click Try 'call the ValidateLogin function If ValidateUser(txtLoginId.Value.ToUpper, txtPassword.Value.ToUpper) Then If Request.Params("ReturnUrl") <> "" Then FormsAuthentication.RedirectFromLoginPage(txtLoginId.Value, True) Else If iStatus = 1 Then FormsAuthentication.SetAuthCookie(txtLoginId.Value, True) Server.Transfer("EntrySubscriberDtls.aspx") Else FormsAuthentication.SetAuthCookie(txtLoginId.Value, True) Server.Transfer("ViewSubscriberDtls.aspx") End If End If Else Response.Redirect("VendorLogin.aspx", True) End If Catch ex As Exception 'Throw error Message txtLoginId.Value = "" txtPassword.Value = "" lblErrorMsg.Text = "Invalid Username or Password" End Try End Sub Code 2: Function ValidateUser(ByVal UserName As String, ByVal Pssword As String) As Boolean Dim vsVndrPwd As String Dim dtVendorDet As New DataTable Try 'For cheking Valid UserName and Password Session("Username") = userName vsVndrPwd = Nothing dtVendorDet = Objallschoolinfo.ValidateLogin(txtLoginId.Value.ToUpper.Trim) iStatus = Convert.ToInt32(dtVendorDet.Rows(0).Item("bStatus")) vsVndrPwd = dtVendorDet.Rows(0).Item("vsPassword".ToUpper.Trim) Catch ex As Exception lblErrorMsg.Text = ex.Message End Try 'If Not Found the Record If (vsVndrPwd Is Nothing) Then Return False End If 'if Found the Record Return (String.Compare(vsVndrPwd.ToUpper.Trim, Pssword.ToUpper.Trim, False) = 0) End Function Code:3 Web.config file ----------------- Error: When iStatus=1 It's th

    W 1 Reply Last reply
    0
    • M Mkanchha

      Hi to all, I am trying to use FormsAuthentication in my Project but I am getting some Problems. Code 1: Private Sub imgbtnSubmit_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles imgbtnSubmit.Click Try 'call the ValidateLogin function If ValidateUser(txtLoginId.Value.ToUpper, txtPassword.Value.ToUpper) Then If Request.Params("ReturnUrl") <> "" Then FormsAuthentication.RedirectFromLoginPage(txtLoginId.Value, True) Else If iStatus = 1 Then FormsAuthentication.SetAuthCookie(txtLoginId.Value, True) Server.Transfer("EntrySubscriberDtls.aspx") Else FormsAuthentication.SetAuthCookie(txtLoginId.Value, True) Server.Transfer("ViewSubscriberDtls.aspx") End If End If Else Response.Redirect("VendorLogin.aspx", True) End If Catch ex As Exception 'Throw error Message txtLoginId.Value = "" txtPassword.Value = "" lblErrorMsg.Text = "Invalid Username or Password" End Try End Sub Code 2: Function ValidateUser(ByVal UserName As String, ByVal Pssword As String) As Boolean Dim vsVndrPwd As String Dim dtVendorDet As New DataTable Try 'For cheking Valid UserName and Password Session("Username") = userName vsVndrPwd = Nothing dtVendorDet = Objallschoolinfo.ValidateLogin(txtLoginId.Value.ToUpper.Trim) iStatus = Convert.ToInt32(dtVendorDet.Rows(0).Item("bStatus")) vsVndrPwd = dtVendorDet.Rows(0).Item("vsPassword".ToUpper.Trim) Catch ex As Exception lblErrorMsg.Text = ex.Message End Try 'If Not Found the Record If (vsVndrPwd Is Nothing) Then Return False End If 'if Found the Record Return (String.Compare(vsVndrPwd.ToUpper.Trim, Pssword.ToUpper.Trim, False) = 0) End Function Code:3 Web.config file ----------------- Error: When iStatus=1 It's th

      W Offline
      W Offline
      Walter_H
      wrote on last edited by
      #2

      hi! your problem is the Server.Transfer method in both cases. you have to do a Response.Redirect(...) with the client so that he gets the auth-cookie. have a look at the differences of both methods in your VS-help. Make sure that you catch ThreabAbortException which is thrown by Response.Redirect. in your case: Private Sub imgbtnSubmit_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles imgbtnSubmit.Click Try ... Catch exc as ThreadAbortException ' Do nothing here Catch ex As Exception 'Throw error Message txtLoginId.Value = "" txtPassword.Value = "" lblErrorMsg.Text = "Invalid Username or Password" End Try End Sub -walter

      M 1 Reply Last reply
      0
      • W Walter_H

        hi! your problem is the Server.Transfer method in both cases. you have to do a Response.Redirect(...) with the client so that he gets the auth-cookie. have a look at the differences of both methods in your VS-help. Make sure that you catch ThreabAbortException which is thrown by Response.Redirect. in your case: Private Sub imgbtnSubmit_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles imgbtnSubmit.Click Try ... Catch exc as ThreadAbortException ' Do nothing here Catch ex As Exception 'Throw error Message txtLoginId.Value = "" txtPassword.Value = "" lblErrorMsg.Text = "Invalid Username or Password" End Try End Sub -walter

        M Offline
        M Offline
        Mkanchha
        wrote on last edited by
        #3

        Thanks for you reply. Now, I change the Code: Try 'call the ValidateLogin function If ValidateUser(txtLoginId.Value.ToUpper, txtPassword.Value.ToUpper) Then If Request.Params("ReturnUrl") <> "" Then FormsAuthentication.RedirectFromLoginPage(txtLoginId.Value, True) Else If iStatus = 1 Then Response.Redirect("EntrySubscriberDtls.aspx") Else Response.Redirect("ViewSubscriberDtls.aspx") End If End If Else Response.Redirect("VendorLogin.aspx", True) lblErrorMsg.Text = "Invalid UserName or Password" End If Catch ex As Exception 'Throw error Message lblErrorMsg.Text = ex.Message End Try -------------------------- In Both Case: Error is:"Thread was being aborted." I am Using Backend code VB.NET and ASP.NET 1.1 Mohan Balal

        W 1 Reply Last reply
        0
        • M Mkanchha

          Thanks for you reply. Now, I change the Code: Try 'call the ValidateLogin function If ValidateUser(txtLoginId.Value.ToUpper, txtPassword.Value.ToUpper) Then If Request.Params("ReturnUrl") <> "" Then FormsAuthentication.RedirectFromLoginPage(txtLoginId.Value, True) Else If iStatus = 1 Then Response.Redirect("EntrySubscriberDtls.aspx") Else Response.Redirect("ViewSubscriberDtls.aspx") End If End If Else Response.Redirect("VendorLogin.aspx", True) lblErrorMsg.Text = "Invalid UserName or Password" End If Catch ex As Exception 'Throw error Message lblErrorMsg.Text = ex.Message End Try -------------------------- In Both Case: Error is:"Thread was being aborted." I am Using Backend code VB.NET and ASP.NET 1.1 Mohan Balal

          W Offline
          W Offline
          Walter_H
          wrote on last edited by
          #4

          As I said before, you have to catch System.Threading.ThreadAbortException. ThreadAbortException is thrown exactly after you do a Response.Redirect. This is normal and it's because the .NET-Framework informs itself that the current thread is beeing aborted. Your problem was that you generally catch every type of exception. Instead you must catch the ThreadAbortException BEFORE you catch any other Exception types. Before you go on, take a look on the documentation of "System.Threading.ThreadAbortException", afterwards it will be clear why you get the message "Thread was being aborted." so change your code to this: Try 'call the ValidateLogin function If ValidateUser(txtLoginId.Value.ToUpper, txtPassword.Value.ToUpper) Then If Request.Params("ReturnUrl") <> "" Then FormsAuthentication.RedirectFromLoginPage(txtLoginId.Value, True) Else If iStatus = 1 Then Response.Redirect("EntrySubscriberDtls.aspx") Else Response.Redirect("ViewSubscriberDtls.aspx") End If End If Else Response.Redirect("VendorLogin.aspx", True) lblErrorMsg.Text = "Invalid UserName or Password" End If Catch ex as System.Threading.ThreadAbortException ' Do nothing here, just catch the exception Catch ex As Exception 'Throw error Message lblErrorMsg.Text = ex.Message End Try hope that helps - walter

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups