How to use global.asax file to transfer user to default page on timeout

I have the following code in the global.asax file.  when the session ends, by timeout it is supposed to send this user to the main login
When it executes in tells me "Response can not be used with in this context".  I'm confused because I have another website that this does work on but not with in the vs2013 project.  Any ideas.  Feels like I'm missing something in web.config?

 

  Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
        Try
            Response.Redirect("~/Account/login.aspx", False)
        Catch ex As Exception
            Dim m As String = ex.Message
            MsgBox(m)
        End Try
    End Sub

Open in new window

mgmhicksAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SStoryCommented:
Does, doing this in web.config work?

<configuration>
<system.web>
<sessionState mode="InProc"  timeout="1" loginurl="~/Account/login.aspx"/>
</system.web>
</configuration>

Open in new window

mgmhicksAuthor Commented:
this is what I have now
   -->
    <sessionState mode="InProc" customProvider="DefaultSessionProvider" cookieless="false" cookieName="ResidentPortal" timeout="10">
      <providers>
        <add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" />
      </providers>
    </sessionState>

Open in new window


<authentication mode="Forms">
      <forms loginUrl="Account/Login" timeout="30" defaultUrl="~/Accounts/Login.aspx" slidingExpiration="true" />
    </authentication>

Open in new window


When I put your code in I get loginurl is not an attribute.
CodeCruiserCommented:
You should not have to manually redirect user. Authentication provider should automatically redirect user if the session has ended.
Learn SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

mgmhicksAuthor Commented:
Even if they haven't clicked anything, as soon as the session is over it is supposed to go to login screen?
SStoryCommented:
Well, how about what is shown by Microsoft in this page:
https://msdn.microsoft.com/en-us/library/vstudio/532aee0e%28v=vs.100%29.aspx

You might be able to get it working by tweaking it and changing the loginurl. I'm not sure you'd need the passport setting or not.

<authentication mode="Windows">
   <forms 
      name=".ASPXAUTH" 
      loginUrl="login.aspx" 
      defaultUrl="default.aspx" 
      protection="All" 
      timeout="30" 
      path="/" 
      requireSSL="false" 
      slidingExpiration="true" 
      cookieless="UseDeviceProfile" domain="" 
      enableCrossAppRedirects="false">
      <credentials passwordFormat="SHA1" />
   </forms>
   <passport redirectUrl="internal" />
</authentication>

Open in new window

CodeCruiserCommented:
No it will only take them to login page when they make their next request.

You can only redirect a request to login page when a user makes a request. You are trying to redirect a request that does not exist.

Here are a couple of tutorials about what I think you are trying to achieve

http://www.codeproject.com/Articles/711196/Session-Time-Out-Warning-Message-Using-jQuery-in-A

http://www.codeproject.com/Articles/227382/Alert-Session-Time-out-in-ASP-Net

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.