slyfox2099
10-07-2003, 07:41 PM
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?
angiras
10-08-2003, 04:19 AM
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