adding cookie

From: masoud bayan (masoud_bayan_at_hotmail.com)
Date: 07/29/04


Date: Thu, 29 Jul 2004 11:42:24 -0400

I have a forms authenticated asp.net web application. in login page there is a check box which when is checked user name should be kept for next login time.
I know there is an option as --- FormsAuthentication.RedirectFromLoginPage(txtUserName.Text, chkRemember.checked) ----- to persist cookie across sessions but my application is different. I just want to save user name in a cookie (not authorized user) in order that when he opens browser and redirect his browser to login page he has not to enter his user name in user name text box. to do this in an non forms authentication based app I used to just add following code in login page:
Dim objCookie As HttpCookie

If chkPersist.Enabled Then

objCookie = New HttpCookie("strUsername", txtUserName.Text)

objCookie.Expires = DateAdd("yyyy", 1, Now())

Else

objCookie = New HttpCookie("strUsername", "")

objCookie.Expires = Now

End If

Response.Cookies.Add(objCookie)

and also in the beginning of login page whenever always check for this cookie and retrieve user name and show in text box.

but now with forms authentication when I add such a cookie to cookies I can not access it later.

Please let me have your experience or comments in this regards.

Thanks



Relevant Pages

  • RE: A little problem with Forms authentication :-(
    ... I'm using forms authentication and the user is getting authenticated no ... should be redirected to the login page. ... I've set the time out for the cookie to the test value of 1 ... redirect from login bit because as I understand it, ...
    (microsoft.public.dotnet.framework.aspnet)
  • RE: Forms authentication cookie handling question (C#)
    ... programmatically generate forms authentication ticket and set it in ASP.NET ... You use the Login control's "Authentication" event to do the user ... LoginControl's default code logic to generate authentication cookie. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Forms Authentication Name property
    ... you specify the name to be used for the authentication ... login page, then this can work. ... A cookie is saved by the BROWSER and ... The BROWSER chooses ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • Re: SSL Forms Authentication Redirect - Problem Redirecting out of HTTPS
    ... allowing an authentication cookie to be passed over an HTTP ... My login script goes into SSL just fine. ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • RE: Authentication Ticket Persistance
    ... applications which both use forms authentication. ... web.config that points the login page to the login page of the second ... The second application has one button which gets the cookie, ... My sample worked fine if both web applications were on the same machine ...
    (microsoft.public.dotnet.framework.aspnet.security)