Enabling Sessions for ASP.NET Web Parts in Sharepoint Portal 2003
To Enable Session State in Sharepoint Portal 2003 you will need to do couple of amendments in the “Web.Config“ placed at the root of your virtual server. (usually available at C:\Inetpub\wwwroot ).
Edit your web config file using any editor. (I use Ultra Edit).
1) Enabling SessionStateModule:
Find this tage and enable it: (It is disabled/commented by default)
2) Enable SessionState:
Enable session state (Set to true):
Programmatically check if the session has been enabled on Sharepoint Server or not:
Develop a Web Part and place the following code to test if the session has been enabled or not. Place the following code in your protected override void RenderWebPart(HtmlTextWriter output) method:
output.Write("");
output.Write("");
output.Write(" ");
output.Write("
");
output.Write("
");
try
{
if( this.Page.Session != null && this.Page.Session.Count > 0)
{
if( this.Page.Session["UserPass"] == null)
{
output.Write(SPEncode.HtmlEncode("I dont have the passport for you ... "));
this._linkButton.RenderControl(output);
}
else
{
output.Write(SPEncode.HtmlEncode("Thanks GOD "+this.Page.Session["UserPass"].ToString()+"! you are logged in .."));
}
}
else
{
output.Write(SPEncode.HtmlEncode("I dont have the passport for you ... "));
this._linkButton.RenderControl(output);
}
}
catch(System.Exception exp)
{
output.Write(SPEncode.HtmlEncode("ERROR OCCURED "+exp.Message) );
this._linkButton.RenderControl(output);
}
finally
{
output.Write("
");
output.Write("
");
output.Write("
");
output.Write("");
output.Write("");
}
thats it for now.
stay tuned for more!
--------------------------------------------------------------------------------
Hammad Rajjoub,
MVP (Windows Server System - XML Web Services),
User Group Leader - Dot Net Wizards (http://dotnetwizards.blogspot.com),
Chariman UG Relations Committee (http://inetapakistan.org),
Member Speakers Bureau (http://mea.ineta.org)
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment