views:

50

answers:

5

Please help me I'm getting desperate here trying to find the problem, and I don't know where to start looking for it.

Here are the symptoms:

I've noticed, that when a user logs on in the morning, he is then immediately logged off, then when he logs on again, everything is fine and he can work on the site.

Every once in a while, when the user clicks a link, the page takes a lot of time to load, but it never actually loads, and the user is thrown to the login page.

Also, after an Exception has occurred in the website, the user is then thrown to the login page. It's as if the exception clears somehow the session.

Do any of you know of a situation where this might happen ?

The code I use in every page in my application is as follows :

If (Not User.Identity.IsAuthenticated) Then  
    Response.Redirect("../login2.aspx")
End If  

' If session timeout then return to login screen '
If ((Session("LocationId") Is DBNull.Value) Or (Session("LocationId") Is Nothing)) 
Then  
   Response.Redirect("../login2.aspx")   
End If

The code in the web.config:

<sessionState cookieless="false" timeout="600" />
<authentication mode="Forms">
<forms timeout="600" />
<system.web>
    <authorization>
        <allow users="*"/>
    </authorization>
</system.web>
+1  A: 

Why are you using that code in every page?

.NET authorization and authentication normally takes care of all those things if you have it set up correctly.

leppie
+1  A: 

Related to this scenario *`

".... after an Exception has occurred in the website, the user is then thrown to the login page. It's as if the exception clears somehow the session

I know of one possible situation where it may occur. It is far fetched especially in a production scenaio for multiple reasons but i have seen it happen :-)

If the session is In Memory and logging is done by writing to a log file that is in the Bin directory of the application, then this may occur as modifying the bin folder of the web application results in the application restarting i.e the in memory session getting lost.

Just one possible scenario. If your session is not in Memory OR your logging mechanism isnt like this, then this doesnt apply to you.

InSane
A: 

Hi, I am turning to all the dot net experts out there because I am really desperate,

let me give another symptom of the problem because it still persists,

the server is a very strong server - intel xeon with a 3 gb ram, so it is probably not a problem of resources.

When the user uses the system continuously there is no problem and she can work freely, the problem arises when the user leaves the computer (or the application for that matter) for as long as 5 minutes, then when she wants to continue working and clicks a link in the application she is thrown to the login page. when she tries to login again, she succeeds, but after she clicks another link, she is thrown out again, then when she logins she can work freely and everything is fine.

Somehow the session is being cleared when the site is idle. let me emphasize that this doesn't happen when I run the app in visual studio, only in iis.

The app was converted from asp.net 2.0 to 3.5,

that's it, thanks

olst
A: 

If you are just using the normal session functionality in asp.net I believe that the session times out after 15-30 minutes of inactivity (I typically don't use session so I remember it is somewhere in this range). Every postback to the server resets this timer so if a user is active doing things then they won't hit this time out.

For the page taking a long time to load it is most likely due to the worker process recycling and that user is the first user to access the site after a recycle which triggers IIS to do all of it's compilation stuff and then serve the page which causes the delay. This only happens for the first visitor after a worker process recycle. You can change this behavior in IIS to happen on a schedule rather than after a certain amount of time has passed without activity. This will cause your worker process to take up more memory though so depending on your environment this might not be a good change to make.

EDIT: I should add that the code you posted explains exactly why the user is kicked back to the login page. It is checking to make sure that there is something in the session and if there isn't anything there it kicks the user back to the login page. So if they are inactive for too long your session times out, so it is cleared, and the user is kicked back to the login page by your code. Also you should use FormsAuthentication.RedirectToLoginPage(); for your redirect instead of Response.Redirect. This way after logging in they go back to the page they requested originally.

antonlavey
30 by default. P.S. Jesus loves you :))
abatishchev
Hi, the weird thing is, that I set the session timeout to 8 hours, so the session shouldn't end, my bet is that somekind of exception causes the session to be cleared, and thus the logout
olst
A: 

First of all, you need to deny access for non-authenticated (anonymous) users:

<authorization>
    <deny users="?" />
</authorization>

Have you configured default and login pages?

<authentication mode="Forms">
    <forms name=".ASPXFORMSAUTH" loginUrl="Login.aspx" defaultUrl="Default.aspx" slidingExpiration="true" timeout="30" />
</authentication>

name sets the name of a cookie, useful if you will use .NET 2.0 built-in security infrastructure (roles, membership, etc)

slidingExpiration enabled normal timeout behavior - any user action resets timeout

abatishchev