Click here to Skip to main content
15,885,032 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
In one new project, I can't create Session variables. for
C#
Session["fileName"] = null;

I got HttpException:
C#
Session state can only be used when enableSessionState is set to true, either in a configuration file or in the Page directive. Please also make sure that System.Web.SessionStateModule or a custom session state module is included in the <configuration>\<system.web>\<httpModules> section in the application configuration.

Then I added
XML
<system.web>
<sessionState mode="InProc" timeout="60" cookieless="false" />
<pages enableSessionState="true" />
<httpModules>
  <remove name="Session" />
  <add name="Session" type="System.Web.SessionState.SessionStateModule" />
</httpModules>
</system.web>

But still got the same error. I used Session Variables in my other projects well. I wonder why I got error in this asp project. Thanks if you can share your experience.
Posted
Comments
Richard Deeming 12-Jan-16 10:26am    
What does your @Page directive[^] look like?
s yu 12-Jan-16 10:31am    
No @Page Directive is defined. In my other projects, in which Session variables work fine, there are also no @Page Directive.
Richard Deeming 12-Jan-16 10:32am    
So where are you trying to create the session variable? Is this an ASP.NET MVC application?
s yu 12-Jan-16 10:34am    
Asp.net.
Richard Deeming 12-Jan-16 10:37am    
OK, but WHERE are you trying to create the session variable?

If it's not in a page, and you're not using MVC, then are using a generic handler? (.ashx)

If you are, then did you remember to implement the IRequireSessionState interface?

1 solution

Answered only to remove from unanswered queue -solved by OP:
guess the problem is caused by the page itself. This page exists some crashing issues. I work on another age, and there is no such a problem. This thread can be closed. Thanks.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900