<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-4788181017626318198</id><updated>2011-04-22T07:00:54.765+05:30</updated><category term='Session State Maintanance'/><title type='text'>Spartan</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://karthikexp.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4788181017626318198/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://karthikexp.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Karthikeyan Rajathinakaran</name><uri>http://www.blogger.com/profile/11845846764558921258</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>1</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4788181017626318198.post-2984294850907252313</id><published>2009-05-11T12:07:00.003+05:30</published><updated>2009-05-11T12:26:16.617+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='Session State Maintanance'/><title type='text'>ASP.Net session expired Handling</title><content type='html'>Step 1: Create the SessionExpired.cs file into APP_CODE folder and write the code below:&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;using System;&lt;/div&gt;&lt;div&gt;using System.Data;&lt;/div&gt;&lt;div&gt;using System.Configuration;&lt;/div&gt;&lt;div&gt;using System.Linq;&lt;/div&gt;&lt;div&gt;using System.Web;&lt;/div&gt;&lt;div&gt;using System.Web.Security;&lt;/div&gt;&lt;div&gt;using System.Web.UI;&lt;/div&gt;&lt;div&gt;using System.Web.UI.HtmlControls;&lt;/div&gt;&lt;div&gt;using System.Web.UI.WebControls;&lt;/div&gt;&lt;div&gt;using System.Web.UI.WebControls.WebParts;&lt;/div&gt;&lt;div&gt;using System.Xml.Linq;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;/// &lt;summary&gt;&lt;/div&gt;&lt;div&gt;/// Summary description for SessionExpired&lt;/div&gt;&lt;div&gt;/// &lt;/summary&gt;&lt;/div&gt;&lt;div&gt;public class PageBase : System.Web.UI.MasterPage&lt;/div&gt;&lt;div&gt;{&lt;/div&gt;&lt;div&gt;    public PageBase()&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;{&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;//&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;// TODO: Add constructor logic here&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;  &lt;/span&gt;//&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;}&lt;/div&gt;&lt;div&gt;    protected override void OnPreRender(System.EventArgs e)&lt;/div&gt;&lt;div&gt;{&lt;/div&gt;&lt;div&gt;    base.OnPreRender(e);&lt;/div&gt;&lt;div&gt;   &lt;/div&gt;&lt;div&gt;    if (Context.Session.IsNewSession == true) {&lt;/div&gt;&lt;div&gt;        string strCookieHEader = Page.Request.Headers["Cookie"];&lt;/div&gt;&lt;div&gt;        if ((strCookieHEader != null)) strCookieHEader = strCookieHEader.ToLower();&lt;/div&gt;&lt;div&gt;        if ((strCookieHEader != null) &amp;amp;&amp;amp; strCookieHEader.IndexOf("asp.net_sessionid") &gt;= 0) {&lt;/div&gt;&lt;div&gt;            if (Page.Request.IsAuthenticated == true) {&lt;/div&gt;&lt;div&gt;                System.Web.Security.FormsAuthentication.SignOut();&lt;/div&gt;&lt;div&gt;            }&lt;/div&gt;&lt;div&gt;            Page.Response.Redirect("~/login.aspx?Id=1");&lt;/div&gt;&lt;div&gt;        }&lt;/div&gt;&lt;div&gt;    }&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Step 2: Refer this .cs file into your master page code behind(aspx.cs). write "PageBase" instead of "System.Web.UI.MasterPage" like this&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;using System;&lt;/div&gt;&lt;div&gt;using System.Collections;&lt;/div&gt;&lt;div&gt;using System.Configuration;&lt;/div&gt;&lt;div&gt;using System.Data;&lt;/div&gt;&lt;div&gt;using System.Linq;&lt;/div&gt;&lt;div&gt;using System.Web;&lt;/div&gt;&lt;div&gt;using System.Web.Security;&lt;/div&gt;&lt;div&gt;using System.Web.UI;&lt;/div&gt;&lt;div&gt;using System.Web.UI.WebControls;&lt;/div&gt;&lt;div&gt;using System.Web.UI.WebControls.WebParts;&lt;/div&gt;&lt;div&gt;using System.Web.UI.HtmlControls;&lt;/div&gt;&lt;div&gt;using System.Xml.Linq;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;public partial class MasterPage1: PageBase&lt;/div&gt;&lt;div&gt;{&lt;/div&gt;&lt;div&gt;   &lt;/div&gt;&lt;div&gt;    protected void Page_Load(object sender, EventArgs e)&lt;/div&gt;&lt;div&gt;    {&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;        if (!IsPostBack)&lt;/div&gt;&lt;div&gt;        {&lt;/div&gt;&lt;div&gt;            &lt;/div&gt;&lt;div&gt;           &lt;/div&gt;&lt;div&gt;        }&lt;/div&gt;&lt;div&gt;       &lt;/div&gt;&lt;div&gt;    }&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;    &lt;/div&gt;&lt;div&gt;    &lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;Conclusion:&lt;/div&gt;&lt;div&gt;Session state maintanance is the tidious task for developer.Because of this code programmer can handle the session state and redirect to login Page with the message of "Session has expired.." by the view state management.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Feel free to write mail...&lt;/div&gt;&lt;div&gt;My Mail Address: karthikexp@gmail.com&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4788181017626318198-2984294850907252313?l=karthikexp.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://karthikexp.blogspot.com/feeds/2984294850907252313/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4788181017626318198&amp;postID=2984294850907252313' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4788181017626318198/posts/default/2984294850907252313'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4788181017626318198/posts/default/2984294850907252313'/><link rel='alternate' type='text/html' href='http://karthikexp.blogspot.com/2009/05/aspnet-session-expired-handling.html' title='ASP.Net session expired Handling'/><author><name>Karthikeyan Rajathinakaran</name><uri>http://www.blogger.com/profile/11845846764558921258</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry></feed>
