简体   繁体   English

会话在asp.net中的处理程序中为空?

[英]Session is coming null in handler in asp.net?

I want to access session in handler for that i am inheriting "IRequireSessionState" Class. 我想在处理程序中访问会话,因为我正在继承“ IRequireSessionState”类。 but while evaluating the session it is coming null, but on the web page it has value. 但是在评估会话时,它为空,但是在网页上它具有价值。 i dont know why this is happening my code of handler is: 我不知道为什么会这样,我的处理程序代码是:

 public void ProcessRequest(HttpContext context)
{
String Name = Common.GetSessionValue("UserId").ToString() ;
// my code.........

Here is my common method to Get Session's value 这是获取会话价值的常用方法

 public static Guid GetSessionValue(string SessionName)
    {
        Guid returnvalue = Guid.Empty;
        if (HttpContext.Current.Session[SessionName] != null)
        {
            returnvalue = new Guid(HttpContext.Current.Session[SessionName].ToString());
        }
        else
        {
            HttpContext.Current.Response.Redirect("Login.aspx");
        }
        return returnvalue;
    }

Please help me. 请帮我。 Thanks in advance 提前致谢

You can try this by Exposing the value to the outside world http://forums.asp.net/t/1506625.aspx/1 and then trying to fetch the value in handler using 您可以通过将值暴露给外部环境http://forums.asp.net/t/1506625.aspx/1进行尝试,然后尝试使用以下方法在处理程序中获取值

context.Request.Form["returnvalue"]; 

You can see the exposed value in firebug AddOn in Mozilla 您可以在Mozilla的firebug AddOn中看到暴露的值

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM