开发者

session null on production server

I got an strange exception on my production server:

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.] selectie.Functie..ctor() in ..\Page\Specificaties\Functie\Functie.cs:35 System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35 System.Web.UI.Control.OnLoad(EventArgs e) +91 System.Web.UI.Control.LoadRecursive() +74 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207

line 35:

Kast kast = (Kast)HttpContext.Current.Session["kast"];


The session is used in multiple webmethods like:

[WebMethod(EnableSession = true)]
public static String button_click(String information) {

}

and

[WebMethod(EnableSession=true)]
public static void ChangeKast(String id, String value)
{

}

in my search for a solution i found this:

As you might expect, if you enable s开发者_JS百科ession support for one Web method, that does not imply that it is enabled for another Web method. In fact, the Context.Session property will be null if EnableSession is not explicitly set to True for a particular Web method.

localy it runs perfectly, and has worked since today... How could i solve this?


Look in Web.Config on the live machine under the <system.web> Element there should an element called <sessionstate> make sure it's not set to Mode="Off"

<configuration>
...
<system.web>
....
<sessionState mode="InProc" cookieless="false" timeout="20" />
....
</system.web>
....
</configuration>


My wisdom with these kind of session null scenarios says that - there are hidden errors occurring in your applications but not unearthed. any exception inside the code would kill the session and might continue with a new session so the values are null...

best approach, run your dev environment code in vs ide with debug --> exceptions menu, on all exception handlers and run through the application for several scenarios, eventually you would realize there are hidden errors starting from simple errors like convertToInt or similar reference errors, which cause session becomes null... But as I guessed things did not break at error in "error" page but found through above "DEBUG" with all exceptions ON option.

Hope it helps! HydTechie

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜