0

hello I'm trying so hard for this, I cant understand most question since this is my first time developing in ASP.NET here is my problem.
Im declaring session variable when the user click the submit in the login page then redirecting them to somepage.aspx

if (dt.Rows.Count > 0)
{
    Session["usersId"] = usersId;
    Session["usersLevel"] = usersLevel;
    Session["usersRegion"] = usersRegion;
    Session["notification"] = "";
    Response.Redirect("pages/Dashboard.aspx");
}

So after that that I put something in my Web.config

 <system.web>
    <compilation debug="true" targetFramework="4.0"/>
    <sessionState timeout = "1" mode = "InProc" />
  </system.web>

So ofcourse the session will expire?/timeout? then in my Global.asax I put this

void Session_End(object sender, EventArgs e) 
{

    Response.Redirect("Login.aspx");

}

However an HttpExeception rises, that says

Response is not available in this context.

Why did the response is not available? when it said that the sessionstate mode must be set to InProc? I just want the user to be redirected in that page when the session expires/timeout(I dont know their difference but looks same to me)

thank you

WTFZane
  • 592
  • 1
  • 4
  • 25
  • Try using `HttpContext.Current.Response.Redirect` instead of `Response.Redirect` in `Session_End` method for redirect to login page. – Tetsuya Yamamoto Feb 08 '17 at 02:47
  • @TetsuyaYamamoto no that wouldnt work. There is no response for that event because it isn't triggered by a request. – mason Feb 08 '17 at 03:22
  • You don't redirect users to a login page when the page expires, at least not from the server. The next time they make a request you can redirect them if you wish, because that will be in the request/response context. Or you can try to keep track on the client side with JavaScript if their session is active or not, but that tends to get messy. – mason Feb 08 '17 at 03:24
  • @mason. the numbers mason, what do they mean?? – WTFZane Feb 08 '17 at 03:38
  • yes @mason I understand what you are trying to say. Can't it be helped with just the `Global.asax`? I don't want to put a condition checker every page. – WTFZane Feb 08 '17 at 03:44
  • You're the 2nd guy in several days to use that quote. Did someone just have a big Black Ops party that I wasn't invited to? – mason Feb 08 '17 at 03:46
  • Take a look at [this question](http://stackoverflow.com/questions/484964/asp-net-push-redirect-on-session-timeout). – mason Feb 08 '17 at 03:47
  • thank you @mason. I've looked up to that topic already. I just thought there is an easy way for this, looks like it's not easy like what I think. – WTFZane Feb 08 '17 at 03:55

1 Answers1

0

You may consider to do the redirect in AuthenticateRequest event. Only inProc sessionstate provider supports session end event and it may happen any time(even after the relevant request is responsed, that's why you saw that exception).

mattfei
  • 498
  • 3
  • 5