Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Response is not available in this context in asax file

Tags:

c#

I have a login page that works only with Firefox. It does not work with any other browsers.

When I checked the event log, I saw a "response is not available in the current context". It tells me that the error is in the global.asax file, at the response.redirect line:

void Session_End(object sender, EventArgs e) 
{
     Response.Redirect("~/Login.aspx?li=1");
    // Code that runs when a session ends. 
    // Note: The Session_End event is raised only when the sessionstate mode
    // is set to InProc in the Web.config file. If session mode is set to StateServer 
    // or SQLServer, the event is not raised.

}

What could be the problem?

I have tried httpcontext.Current as suggested but then I get a Null Reference Exception, Object Reference not set to an instance of an object

Thank you.

like image 507
Funkyspirit Avatar asked Nov 25 '22 23:11

Funkyspirit


1 Answers

Try using HttpContext.Current.Response it should definitely work.

like image 100
Icarus Avatar answered Dec 10 '22 11:12

Icarus