Lucky Luke2
Lucky Luke2

Reputation: 2116

Setting session variable in class that implements IHttpModule error

I am trying to set a session variable in a class that implements IHttpModule. I receive a "Object reference not set to an instance of an object."

Here is my code:

    public void Init(HttpApplication context)
    {
        context.PreRequestHandlerExecute += context_PreRequestHandlerExecute;

    }

    private void context_PreRequestHandlerExecute(object sender, EventArgs e)
    {
        HttpApplication app = (HttpApplication) sender;
        HttpRequest request = app.Context.Request;
        app.Session.Add("capath", request.QueryString["capath"].ToString());


    }

Please help.

Upvotes: 0

Views: 134

Answers (1)

Massimiliano Peluso
Massimiliano Peluso

Reputation: 26737

I guess the issue is that the query string does not contain "capath" key / value and you get the object null exception because you call .ToString() on a null object

Upvotes: 1

Related Questions