Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

RedirectFromLoginPageEx - Specify how many days the auth cookie lasts

Total Hit ( 1288)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


Click here to copy the following block
' A custom routine that works like FormsAuthentication.RedirectFromLoginPage
' but lets you control the authentication cookie's expiration date
' Example: create an auth cookie that lasts 7 days
' RedirectFromLoginPageEx(username, persistent, 7)

Function RedirectFromLoginPageEx(ByVal username As String, _
  ByVal persistentCookie As Boolean, Optional ByVal expirationDays As Integer _
  = -1) As Boolean
  ' Get the URL of the requested resource.
  Dim url As String = FormsAuthentication.GetRedirectUrl(username, _
    persistentCookie)
  ' Create the authentication cookie.
  ' (The cookie path can be omitted, because it defaults to "/",
  ' the entire site.)
  FormsAuthentication.SetAuthCookie(username, persistentCookie, "/")

  If persistentCookie And expirationDays > 0 Then
    ' Get a reference to the cookie just created.
    Dim cookie As HttpCookie = Response.Cookies _
      (FormsAuthentication.FormsCookieName)
    ' Set its expiration date.
    cookie.Expires = Now.AddDays(expirationDays)
    ' Ensure the cookie can travel only over https.
    'cookie.Secure = True
  End If

  ' Redirect to the resource that was requested originally.
  Response.Redirect(url)
End Function


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.