WinHost Forums                

Go Back   WinHost Forums > Programming/troubleshooting forums > General troubleshooting

Reply
 
Thread Tools Search this Thread
Old 07-26-2011, 01:48 PM   #1
0000403
 
Join Date: Oct 2009
Posts: 6
Unhappy form authentication timeout not working

Hi, I have a mvc3 application, uses form authentication to validate users.
in web.config, I set timeout for 2880 (minutes) as default. And I also checked session state menu in IIS7 which connects to my site, and disabled the session and selected "Uses cookies".

Despite all my settings, my application redirects user to login page after being inactive for 30seconds(I timed it).

Here is authentication attribute in web.config

<authentication mode="Forms">
<forms loginUrl="~/Account/LogOn" timeout="2880" defaultUrl="/SGIC/Home" />
</authentication>

Thanks
0000403 is offline   Reply With Quote
Old 07-27-2011, 10:50 AM   #2
iqdesign
 
Join Date: Dec 2010
Posts: 4
My Solution

I had the same problem and have spent 2 days trying to fix this. There are some red herring posts about the app pool recycling if you go over 100MB in memory in your app. However this is not completely relevant. I went through the effort of writing my own Custom Session State Provider Store to eliminate this possibility. (as an fyi, it was pretty easy and probably not a bad idea)

I contacted Winhost support and they told me that my app pool had recycled a few times, but not enough to provide an explanation as to why the session was dissapearing after 30 seconds.

After writing my own code to read the HTTP headers and process the cookies as opposed to using the Request.Cookies collection, I discovered that the problem was with the encryption and decryption of the authentication cookie. .NET was nice enough not to throw an error to the user and just ignore any bad cookies. So while you may see the cookie in the HTTP header, it doesn't get processed.

In the end, it appears that you need to configure your machine key. It defaults to autogenerate, but does not default to the isolated app option. I haven't tested this in depth, but it appears to be what is happening. Being on a shared server, this would be an issue.

I provided a machinekey in my web.config and that solved the problem. As this took me 2 days to figure out, I wanted to spare everyone the pain. The upside is I now have a custom session provider that uses a MySQL database so I guess the 2 days wasn't a complete loss.

here is a link to generate a machinekey:

http://aspnetresources.com/tools/machineKey
iqdesign is offline   Reply With Quote
Old 08-04-2011, 04:33 PM   #3
Rich Miles
 
Join Date: Aug 2011
Posts: 1
THANK YOU! I have been looking everywhere for this solution.
Rich Miles is offline   Reply With Quote
Old 08-31-2011, 07:32 PM   #4
ars427x
 
Join Date: Aug 2011
Posts: 1
Iqdesign, thanks for posting your solution! I had been fighting with random logoffs for days, but adding a machinekey section to the web.config fixed everything.
ars427x is offline   Reply With Quote
Old 09-06-2011, 03:22 PM   #5
cdiscla
 
Join Date: Sep 2011
Posts: 3
Thumbs up

Great !!
This solved my great problem in immediate session expiration !!
cdiscla is offline   Reply With Quote
Old 09-08-2011, 07:20 PM   #6
Charles
 
Join Date: Sep 2011
Posts: 1
shall I know how to configure the web.config?
I've added the machine key inside web.config.but still found random logoff..
Charles is offline   Reply With Quote
Old 11-03-2011, 08:15 PM   #7
fuli1001
 
Join Date: Nov 2011
Posts: 2
Thank you Iqdesign, it solved the problem!
fuli1001 is offline   Reply With Quote
Old 11-09-2011, 07:46 PM   #8
trickturner
 
Join Date: Nov 2011
Posts: 2
I still have hair!

Thank you! I was going crazy trying to figure this out. No more pulling my hair out.
trickturner is offline   Reply With Quote
Old 12-16-2011, 12:10 AM   #9
noratalal
 
Join Date: Oct 2011
Posts: 3
thank you , i have the same problem logout after 30 minutes although i set session time out 30 minutes in web config. After i put machine key as you mention , the logout problem solved but i get another problem ,the problem is the after 5 minutes the content of session is empty.i don't know how to sole this problem,,,,help plz??
noratalal is offline   Reply With Quote
Old 12-16-2011, 09:15 AM   #10
Ray
WinHost Staff
 
Ray's Avatar
 
Join Date: Aug 2009
Posts: 2,995
Try looking at SQL sessions.

http://support.winhost.com/KB/a626/h...-your-web.aspx
Ray is offline   Reply With Quote
Old 02-04-2012, 08:55 AM   #11
scotty
 
Join Date: Feb 2012
Posts: 3
Thumbs up SQL session state works! (steps included)

thank you iqdesign! I used the generated machine key from that site you provided, inserted into my web.config, and turned on SQL session state via IIS7 and session is being maintained, as expected.

There are 5 steps necessary to implement SQL Session...

1. Used the generated machine key from http://aspnetresources.com/tools/machineKey

2. In web.config, under <configuration>, <system.web>, I added...

<sessionState mode="SQLServer" allowCustomSqlDatabase="true" sqlConnectionString="data Source=<winhost server>;database=<your database>;user id=<your db user>;password=<your db password>" cookieless="false" timeout="<pick a number>" />
<machineKey validationKey="<generated validation key>" decryptionKey="<generated decryption key>" validation="SHA1" decryption="AES" />

NOTE: winhost automatically recycles the app pool under 3 conditions - over 75% spiked usage within 5 minutes, over 100MB memory or over 20 minutes timeout.

3. Run IIS7 and setup the machine key, both methods and keys, to the exact same values you placed in your web.config.

4. In IIS7, also setup your SQL session state with the same connection string you have in the web.config. I also checked "Enable custom database". Note you are setting timeout in seconds for session, in minutes for cookies.

5. You need to submit a ticket to support to add "sql session schema" to your database.

Hope this adds clarification to the topic.
scotty is offline   Reply With Quote
Old 03-15-2012, 02:27 AM   #12
Marko
 
Join Date: Mar 2012
Posts: 2
cannot log in

Hello, I was trying to reproduce these steps which scotty mention here in post before mine, but with no luck. Let me first describe my situation>
I'm using mvc3 with nhibernate and c#. Everything goes as expected (communication with the db) but I cannot log in to my app. So after I was found these post I submit ticked to support to have sql session schema on my db, that was really fast done by support. After that I followed steps from scotty post (even twice to be sure) but same thing appear, cannot login.

I asked for winhost support for help, no luck. Worth to mention is that in my dev. environment everything runs smoothly.

Here is my machine code screenshot and sql session state screenshot.
image1.png:


please help
Marko is offline   Reply With Quote
Old 04-19-2012, 06:19 PM   #13
Mo the Hawk
 
Join Date: Apr 2012
Posts: 1
iqdesign: THANK YOU SO MUCH. You just helped me solve a problem with my new website that has been nagging at me for nearly 2 weeks. If I could give you a hug, I would.
Mo the Hawk is offline   Reply With Quote
Old 08-29-2012, 07:10 PM   #14
topquote
 
Join Date: Jul 2012
Posts: 4
Question I am still having problems with this

<machineKey validationKey="B #other key letters D" decryptionKey="E #other key letters D0" validation="SHA1" decryption="AES" />

<sessionState mode="SQLServer" allowCustomSqlDatabase="true" sqlConnectionString="data Source=s01.winhost.com;database=DB#####z;user id=DB######r;password=######" cookieless="false" timeout="300" />

is there anything missing?

I set up the sql session tables using aspnet_resql.exe locally does that matter?

thanks
glen
topquote is offline   Reply With Quote
Old 10-11-2012, 08:35 AM   #15
BassemMohsen
 
Join Date: Oct 2012
Posts: 1
Thank you thank you thank you iqdesign!
BassemMohsen is offline   Reply With Quote
Reply

Bookmarks

Tags
timeout

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Timeout expired. Silverlight, Entity Framework, WCF JimS Site Programming, Development and Design 3 02-25-2011 12:22 PM
Wordpress Email Setup not working using Google Apps andysinclair Email 1 02-21-2011 11:18 AM
form authentication timeout in 5 minutes likeuclinux General troubleshooting 6 11-17-2010 01:56 PM
WCF and ASP.Net membership authentication error stevharr General troubleshooting 6 04-10-2010 06:11 PM
error on form authentication xpslib General troubleshooting 4 11-07-2009 06:14 PM


All times are GMT -7. The time now is 04:20 AM.


vBulletin® ©Jelsoft Enterprises Ltd.