HELP WITH NULLREFERENCE EXCEPTION IN C#

Goti Bandu

Total Post:119

Points:835
Posted by  Goti Bandu
C# 
C#
 971  View(s)
Ratings:
Rate this:

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;

}

 If I delete the if block then I don't get an error back from the server. 

  1. Sumit Kesarwani

    Post:378

    Points:2694
    Re: Help with NullReference exception in C#

    Hi Goti, 


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

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!