0

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 testing purposes. If I delete the if block then I don't get an error back from the server. I'm confused.

3
  • 1
    can you post the stack trace of the exception please - at present .Current or .Session are the only candidates Commented Jan 19, 2011 at 22:59
  • Can you verify if ASP.Net has assigned its session id at the time this web method is called? Commented Jan 19, 2011 at 23:07
  • The problem was either .Current or .Session. There was not previous sessions so I wrote the syntax wrong to create one. Commented Jan 19, 2011 at 23:14

2 Answers 2

5

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

Sign up to request clarification or add additional context in comments.

4 Comments

@SLaks (and Andras): Doh! I've been in CMMI training all day, my brain is fried. Thanks.
@Jeff - s'okay, you're among friends
@Jeff Yates, You are correct. I don't know why I wrote that the way I did. Should be Session["public"]="pub";
@nick: Glad I was able to help.
1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.