Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 629 Vote(s) - 3.56 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Differences in forms auth timeout and session timeout

#1
The session state timeout is set using this web.config element

<sessionState mode="InProc" cookieless="false" timeout="120" />

The forms auth is configured using this web.config element

<system.web>
<authentication mode="Forms">
<forms loginUrl="Login.aspx"
protection="All"
timeout="30"
name=".ASPXAUTH"
path="/"
requireSSL="false"
slidingExpiration="true"
defaultUrl="default.aspx"
cookieless="UseDeviceProfile"
enableCrossAppRedirects="false" />
</authentication>
</system.web>


What is the difference between the timeouts specified in each of these elements? If both are different, how would it work?
Reply

#2
A session starts every time a new user hits the website, regardless of whether or not they are anonymous. Authentication has very little to do with Session.

Authentication timeout is the amount of time that the authentication cookie is good for on the user's browser. Once the cookie expires, they must re-authenticate to access protected resources on the site.

So, if Session times out before the Authentication cookie - they are still authenticated, but all their session variables disappear, and may cause errors in your website if you are not disciplined in checking for nulls and other conditions brought about by missing session.

If Authentication times out before the session, then all their session variables will still exist, but they won't be able to access protected resources until they log back in again.
Reply

#3
as expected.

e.g. if your session times out after 20 minutes, your session-variables will be lost.
but the user could access the pages which are protected by the authentication.

if the authentication times out, the user could not access the page which it protects, and the state of the session is irrelevant.
Reply

#4
Session Timeout value must be smaller than FormsAuthentication timeout time. Because Session can be removed because of a reason and the scenario won't work.

If Session times out, check FormsAuthentication Ticket. If ticket is valid and not time out, then re-generate session at your Login page (defined in your web.config file as LoginUrl parameter of FormsAuthentication settings).

If FormsAuthentication times out, ASP.NET FormsAuthentication redirects user automatically to Login Page and user has to login again.

Don't forget that FormsAuthentication automatically redirects user to login page when ticket time outs.

Actually I prefer this structure:

1. Create a BasePage.cs for login required pages.
2. at Page_Init in BasePage.cs check Session. If Session Expired; redirect user to Login page.

if (Session["UserId"] == null) Response.Redirect("Login.aspx", true);



3. At Page_Load in Login.aspx check Session and FormsAuthentication Ticket times properly.





//User already have a session; redirect user to homepage.
if (SessionHandler.UserId != 0)
Response.Redirect("HomePage.aspx");
else
{
//Session is killed; check Ticket is Valid or not
if (Context.User.Identity != null && Context.User.Identity.IsAuthenticated)
{
//Use Value of the FormsAuthentication
var customDataToCheck = Context.User.Identity.Name;

//Use value to check user is exist really and check db for user's session
var user = CheckUserData(customDataToCheck);
if (user != null)
{
//Start Session here
SessionHandler.StartSession(user);

//Redirect user to page what you want.
Response.Redirect("HomePage.aspx?ref=regenerated_session");
}
}
}

4. at Login.aspx use FormsAuthentication to create cookies.

if (username == "testuser" && password == "testpassword")
{
//User data will be written to a cookie, store a user data that you can check user is valid or not (for example Username or UserId).
System.Web.Security.FormsAuthentication.SetAuthCookie("testUserData", keepMeSignedInCheckBox.Checked);
Response.Redirect("HomePage.aspx");
}
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through