Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Oct 2002
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question ASP.NET FormsAuthentication

    Anyone know how to use forms auth with C# to validate a user on a web app? I want to check to see if the user is logged in and if not, send them to the login page. The clincher is I am not using the persistant cookie with the forms auth method. How do I do it without the cookie?
    slyfox2099
    slyfox2099@yahoo.com

  • #2
    Regular Coder
    Join Date
    Dec 2002
    Location
    France
    Posts
    522
    Thanks
    0
    Thanked 0 Times in 0 Posts

    httpModule

    I use a httpModule (and VB NET) and HttpCookie

    but the syntax is (you nust adapt for C#)

    Private Sub Authentification()

    Dim __authTicket As FormsAuthenticationTicket
    Dim __encryptedTicket As String
    Dim __authCookie As HttpCookie

    If anyBoolean Then
    __authTicket = New FormsAuthenticationTicket(1, User.Text, DateTime.Now, DateTime.Now.AddMinutes(60), False, __anyRole)
    Else
    __authTicket = New FormsAuthenticationTicket(1, __anyUnKnownVariable, DateTime.Now, DateTime.Now.AddMinutes(15), False, zeroRole)
    End If

    __encryptedTicket = FormsAuthentication.Encrypt(__authTicket)
    __authCookie = New HttpCookie(FormsAuthentication.FormsCookieName, __encryptedTicket)
    HttpContext.Current.Response.Cookies.Add(__authCookie)

    go to your page
    End Sub


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •