Forms Auth keeps going to logon page

From: Andy Fraser (news_at_andyfraser.co.uk)
Date: 11/03/03


Date: Mon, 3 Nov 2003 21:46:36 -0000

Hi,

I am using forms authentication for a web application I am writing. I query
a SQL server database to find a matching username and password then create
an encrypted cookie. I then redirect to my main menu page. However, when I
select a menu and try to jump to another page, it keeps taking me back to my
logon page ! Can anybody suggest what I am doing wrong, I enclose a sample
of my web.config file and a sample of the code that creates the
authentication cookie.
Thanks in advance.

Andy

Web.Config

<authentication mode="None">
    <forms name=".RNWEBAUTH" loginUrl="RNLogon.aspx" protection="All"
timeout="60"></forms>
</authentication>
<authorization>
    <deny users="?" />
    <allow users="*" />
</authorization>

Logon.aspx

FormsAuthenticationTicket tkt = new FormsAuthenticationTicket( 1,

Username.Text,

DateTime.Now,

DateTime.Now.AddMinutes( 30 ),

false,

strAccess,

FormsAuthentication.FormsCookiePath );
//
// Hash the cookie for security
//
string hash = FormsAuthentication.Encrypt( tkt );
HttpCookie ck = new HttpCookie( FormsAuthentication.FormsCookieName,hash );

//
// Add cookie to the response
//
Response.Cookies.Add( ck );
Response.Cookies[ "UserID" ].Value = nUserID.ToString();
Response.Cookies[ "UserID" ].Expires = DateTime.MaxValue;
Response.Cookies[ "Access" ].Value = strAccess;
Response.Cookies[ "Access" ].Expires = DateTime.MaxValue;

//
// Jump to main menu page
//
Response.Redirect( strRedirect,true );



Relevant Pages

  • RE: Forms authentication cookie handling question (C#)
    ... I also replaced all of my ticket authentication code with the ... // Username and or password not found in our database... ... LoginControl's default code logic to generate authentication cookie. ...
    (microsoft.public.dotnet.framework.aspnet)
  • RE: Forms Authentication
    ... The DNS entry for my domain was not set corrretly, ... This should have overcome the cookie ... authentication ticketis not correctly set to the domain your ... Microsoft MSDN Online Support Lead ...
    (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: authentication cookie vs session cookie
    ... level of using authentication cookies on the client machines. ... authentication cookie on a manager's machine is stolen and used on a client ... > session variables as it relies on the session cookie that ASP.NET sends to ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • RE: forms authentication cookie problem
    ... authentication cookie. ... what's going on on the server. ... >324488 Forms Authentication and View State Fail ... >characters, the browser will still request the page, but ...
    (microsoft.public.dotnet.framework.aspnet.security)