Asp.net session layer setting end time setting

Source: Internet
Author: User

What is Session? Simply put, it is the number that the server sends to the client. When a WWW server is running, several users may browse the website running on this server. When a user establishes a connection with the WWW server for the first time, the user establishes a Session with the server, and the server automatically assigns a SessionID to the user to identify the unique identity. This SessionID is a random string consisting of 24 characters on the WWW server. We will see it in the following experiment.

This unique SessionID has great practical significance. When a user submits a form, the browser automatically attaches the user's SessionID to the HTTP header information (this is an automatic function of the browser and the user will not notice it ), after the server processes this form, it returns the result to the user corresponding to SessionID.

If a session ends

<% @ Page Language = "C #" AutoEventWireup = "true" CodeFile = "Default. asp tutorial x. cs" Inherits = "UsingSessionEnd" EnableSessionState = "ReadOnly" %>

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head id = "Head1" runat = "server">
<Title> Using Session State-End </title>
</Head>
<Body>
<Form id = "form1" runat = "server">
<Div id = "container">
<H1> Using Session State-End Session value:
<Asp: Label ID = "labSession" runat = "server"/> <br/>
<Asp: HyperLink ID = "lnkSession" runat = "server" NavigateUrl = "UsingSessionStart. aspx" Text = "Go to session start page"/> <br/>
</Div>
</Form>
</Body>
</Html>

File: Default. aspx. cs

 

Using System;
Using System. Data;
Using System. Configuration;
Using System. Collections;
Using System. Web;
Using System. Web. Security;
Using System. Web. UI;
Using System. Web. UI. WebControls;
Using System. Web. UI. WebControls. WebParts;
Using System. Web. UI. HtmlControls;

Public partial class UsingSessionEnd: System. Web. UI. Page
{
Protected void Page_Load (object sender, EventArgs e)
    {
If (Session ["Name"] = null)
LabSession. Text = "Session has timed out or not been initialized ";
Else
       {
String name = (string) Session ["Name"];
LabSession. Text = name;
       }
    }
}

Use Cookieless session status


The web configuration file enables cookieless sessions by assigning the value AutoDetect to the cookieless attribute.

File: Web. Config

<Configuration>
<System. web>
<SessionState
Cookieless = "AutoDetect"
RegenerateExpiredSessionId = "true"/>
</System. web>
</Configuration>

Session Timeout

File: Web. Config

<Configuration>
<System. web>

<SessionState timeout = "60"/>

</System. web>
</Configuration>


You can modify the Session timeout value programmatically with the Timeout property of the Session object.


Session. Timeout = 60;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.