开发者

help with NullReference exception in C#

开发者 https://www.devze.com 2023-02-06 04:00 出处:网络
The following is a web method that is called from ajax, I have verified with firebug that the script is indeed passing two string values to my method:

The following is a web method that is called from ajax, I have verified with firebug that the script is indeed passing two string values to my method:

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;
}

I'm passing "w" just for开发者_如何学Python testing purposes. If I delete the if block then I don't get an error back from the server. I'm confused.


Without seeing the stack trace, I would guess that HttpContext.Current or HttpContext.Current.Session is null.


Jeff is correct, but I wanted to add that using session within a web service requires that session be turned "on":

[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;
}
0

精彩评论

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