0

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.

4

1 回答 1

1

我想问题是查询字符串不包含“capath”键/值,并且您得到对象空异常,因为您调用.ToString()了空对象

于 2013-05-28T08:52:38.157 回答