I am using HttpContext.Current.Session to retrieve session variables within a HTTP Handler in my application. This is working fine, however I also want to set a session variable, how do I do this as HttpContext.Current.Session appears to only be able to
"Get".
Here is the peice of code I am talking about:
if (HttpContext.Current.Session["pdfDocument"] != null)
{
test = (Boolean)HttpContext.Current.Session["pdfDocument"];
if (test == true)
{
//delete the variable
//next line not working!!
HttpContext.Current.Session["pdfDocument"] = false;
String filepath = "/Documents/";
String document = System.Web.HttpContext.Current.Session["docName"].ToString();
objResponse.TransmitFile(filepath + document);
objResponse.End();
}
}
As you can see I am simply attempting to set Session["pdfDocument"] to false in order to prevent the statements from running again, however it seems to be completely ignoring this statement. It is being run as it hits a breakpoint.
I think even you put the above line in ur code, it should work.
Where are you setting the value in HttpContext.Current.Session["pdfDocument"] . R u missing to set the value inHttpContext.Current.Session["pdfDocument"].
Please mark it as answer if it resolves the issue.
Are you implementating IRequiresSessionState on your handler? It's required in order have full access to session state. I believe read access works without but updates require this interface.
Ahh nailed it on the head in one! :-) I was using IReadOnlySessionState :-S I didn't even think to look up to the top of my code....assumption is a wonderful thing.
Member
135 Points
317 Posts
HttpContext.Current.Session in Custom HTTP Handler
Mar 30, 2009 10:05 AM|eddy556|LINK
I am using HttpContext.Current.Session to retrieve session variables within a HTTP Handler in my application. This is working fine, however I also want to set a session variable, how do I do this as HttpContext.Current.Session appears to only be able to "Get".
Here is the peice of code I am talking about:
As you can see I am simply attempting to set Session["pdfDocument"] to false in order to prevent the statements from running again, however it seems to be completely ignoring this statement. It is being run as it hits a breakpoint.Star
8012 Points
2124 Posts
Re: HttpContext.Current.Session in Custom HTTP Handler
Mar 30, 2009 11:59 AM|sumitd|LINK
The code which you have posted is working perfectly fine .
I have commented the below line and it works fine.
objResponse.TransmitFile(filepath + document);
objResponse.End();
I think even you put the above line in ur code, it should work.
Where are you setting the value in HttpContext.Current.Session["pdfDocument"] . R u missing to set the value inHttpContext.Current.Session["pdfDocument"].
Visit: www.msblogdirectory.com
www.dotnetspeaks.com
Member
135 Points
317 Posts
Re: HttpContext.Current.Session in Custom HTTP Handler
Mar 30, 2009 12:51 PM|eddy556|LINK
Hi, many thanks for your reply! :-)
I'm very sorry but I don't understand your answer :-S which line did you comment out?
Participant
1471 Points
442 Posts
ASPInsiders
MVP
Re: HttpContext.Current.Session in Custom HTTP Handler
Mar 31, 2009 04:17 AM|rstrahl|LINK
Are you implementating IRequiresSessionState on your handler? It's required in order have full access to session state. I believe read access works without but updates require this interface.
http://msdn.microsoft.com/en-us/library/system.web.sessionstate.irequiressessionstate.aspx
+++ Rick ---
West Wind Technologies
Making waves on the Web
weblog.west-wind.com
Check out: Markdown Monster
Member
135 Points
317 Posts
Re: HttpContext.Current.Session in Custom HTTP Handler
Mar 31, 2009 04:31 AM|eddy556|LINK