Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/267.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# C中NullReference异常的帮助#_C#_Asp.net - Fatal编程技术网

C# C中NullReference异常的帮助#

C# C中NullReference异常的帮助#,c#,asp.net,C#,Asp.net,以下是从ajax调用的web方法,我已经用firebug验证了脚本确实在向我的方法传递两个字符串值: public string DealerLogin_Click(string name, string pass) { string g="adf"; if (name == "w" && pass == "w") { HttpContext.Current.Session["public"] = "pub"; g= "wi

以下是从ajax调用的web方法,我已经用firebug验证了脚本确实在向我的方法传递两个字符串值:

public string DealerLogin_Click(string name, string pass)
{
    string g="adf";
    if (name == "w" && pass == "w")
    {
        HttpContext.Current.Session["public"] = "pub";
        g= "window.location = '/secure/Default.aspx'";
    }

    return g;
}

我通过“w”只是为了测试。如果删除If块,则不会从服务器返回错误。我很困惑。

如果没有看到堆栈跟踪,我会猜测
HttpContext.Current
HttpContext.Current.Session
null
如果没有看到堆栈跟踪,我会猜测
HttpContext.Current
HttpContext.Current.Session
null
杰夫是正确的,但我想补充一点,在web服务中使用会话需要“打开”会话:


Jeff是正确的,但我想补充一点,在web服务中使用会话需要“打开”会话:


您能否发布异常的堆栈跟踪?当前
。当前
。会话
是唯一的候选项。您能否验证调用此web方法时ASP.Net是否已分配其会话id?问题是.Current或.Session。以前没有会话,因此我编写了错误的语法来创建一个会话。您可以发布异常的堆栈跟踪吗?当前
。当前
。会话
是唯一的候选对象。您可以验证在调用此web方法时ASP.Net是否分配了其会话id吗?问题是.Current或.Session。以前没有会话,所以我编写了错误的语法来创建一个。@SLaks(和Andras):Doh!我在CMMI训练了一整天,我的脑子都快炸了。谢谢。@Jeff-s'好的,你是其中之一friends@Jeff耶茨,你说得对。我不知道我为什么这么写。应该是Session[“public”]=“pub”@尼克:很高兴我能帮忙。@SLaks(和Andras):啊!我在CMMI训练了一整天,我的脑子都快炸了。谢谢。@Jeff-s'好的,你是其中之一friends@Jeff耶茨,你说得对。我不知道我为什么这么写。应该是Session[“public”]=“pub”@尼克:很高兴我能帮忙。
[WebMethod(EnableSession=true)]
public string DealerLogin_Click(string name, string pass)
{
    string g="";
    if (name == "w" && pass == "w")
    {
        Session["Public"]="pub";

        g= "window.location = '/secure/Default.aspx'";
    }

    return g;
}