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)
            Response.Redirect("~/Account/login.aspx", False)
        Catch ex As Exception
            Dim m As String = ex.Message
        End Try
    End Sub

Open in new window

Who is Participating?

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

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.

Does, doing this in web.config work?

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

Open in new window

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

Open in new window

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

Open in new window

When I put your code in I get loginurl is not an attribute.
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?
Well, how about what is shown by Microsoft in this page:

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">
      cookieless="UseDeviceProfile" domain="" 
      <credentials passwordFormat="SHA1" />
   <passport redirectUrl="internal" />

Open in new window

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

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.