Forms authentication failed for the request. Reason: The ticket supplied was invalid.

Recently I experienced a strange problem with custom login functionality based on Forms Authentication method. The visible issue is that sometimes I login successfully to my application, sometimes - I can’t. In all the cases the same login details are used. When I reviewed the Event Log I found the following error:

Event viewer error:
Event code: 4005
Event message: Forms authentication failed for the request. Reason: The ticket supplied was invalid.
Event time: 30/08/2006 15:43:33
Event time (UTC): 30/08/2006 12:43:33
Event ID: 8bffe75e7ff344c78fe1af8c1124e217
Event sequence: 894
Event occurrence: 388
Event detail code: 50201

Below you can find a short explanation and the solution how to prevent this behaviour.

In fact the application uses “machinekey” definition to generate the authentication cookie. If “machinekey” properties are not initialized in the web.config file, the application uses different values on the different servers. This way when you have been logged in on server X and then try to login on server Y it may happen to use the cookie from server X which is different from the one that server Y uses. Then you cannot login.

Therefore machinekey properties must be always defined for applications that are moved from server to server. Here is an example of “machinekey” definition:

You can generate it by using this .exe file: http://omar.mvps.org/pics/SecurityKey.exe

Here is how you can run it: SecurityKey.exe 24 64

You can read more about this problem and its solution in the following article: http://msmvps.com/blogs/omar/archive/2006/08/20/108307.aspx

, , ,
Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • Technorati
  • digg
  • Reddit
  • SphereIt
  • DotNetKicks
  • YahooMyWeb

7 Responses to “Forms authentication failed for the request. Reason: The ticket supplied was invalid.”


  1. 1 Alexander Yakovlev Dec 5th, 2006 at 4:35 am

    The problem is in difference in default values for slidingExpiration property in forms tag.

    Important!

    For ASP.NET 1.1. slidingExpiration = true by default

    whereas

    For ASP.NET 2.0 slidingExpiration = false by default

  2. 2 Vesy Dec 10th, 2006 at 3:55 pm

    Thanks for your solution, Alexander. It is undoubtedly the easier one.

    According to the MSDN:

    “slidingExpiration is set to ‘true’ to enforce a sliding session lifetime. This means that the timeout is reset after each request to your application.”
    (http://msdn2.microsoft.com/en-US/library/ms998347.aspx)

    I haven’t checked it across the servers but I think it should work without problems.

  3. 3 Idetrorce Dec 15th, 2007 at 9:44 am

    very interesting, but I don’t agree with you
    Idetrorce

  4. 4 werutzb Oct 7th, 2008 at 4:44 pm

    Hi!

    I would like improve my SQL knowledge.
    I red that many SQL books and want to
    read more about SQL for my position as oracle database manager.

    What would you recommend?

    Thanks,
    Werutz

  5. 5 Vesy Oct 27th, 2008 at 10:39 pm

    Hi Werutz,

    Unfortunately I’m not using Oracle and cannot recommend you any learning resources.

    Cheers

  6. 6 hippy Jan 18th, 2010 at 8:27 am

    Hi,

    So to clarify, is slidingExpiration supposed to be set to true on both ASP1.1 and ASP2.0 configs or is it supposed to be left as the defaults (true in 1.1, false in 2.0)??

    Thanks

  7. 7 gkayton Mar 17th, 2010 at 5:32 am

    What fix the problem for me was the following. I was double authenticating users. Once I removed the commented line below I stopped getting the error. Farm or no Farm.

    If System.Web.Security.Membership.ValidateUser(_txtUsername.Text, _txtPassword.Text) Then
    ‘*** Remove Line FormsAuthentication.Authenticate(_txtUsername.Text, _txtPassword.Text)
    If _chkRemember.Checked Then
    FormsAuthentication.RedirectFromLoginPage(_txtUsername.Text, True)
    Else
    FormsAuthentication.RedirectFromLoginPage(_txtUsername.Text, False)
    End If

    Removed this line:
    FormsAuthentication.Authenticate(_txtUsername.Text, _txtPassword.Text)

Leave a Reply




Google

Blogroll


Blogroll Me!

Enter your email address:

Delivered by FeedBurner







Academics Blogs - Blog Top Sites