ASP.NET MVC – Prevent Browser Back Button Openning Page After Logout

If you have ASP.NET MVC application with login / logout functionality (for example using Forms Authentication), you may have noticed that after logout, if you hit back button in your browser, last page you were on will open. In secure application this could present a problem, as it could expose information that only authorized users should view.

Culprit in this scenario is our browser, as it will quite happily show cached version of the page after you’ve logged out.

There isn’t much you can do, except tell your browser to not cache your application’s pages. You can do this for individual pages in your applications, or if you want all pages not to be cached, you can add an event in Global.asax file.

Add Application_BeginRequest() method to your application’s Global.asax file, and add code below which will disable browser caching for each request.

        protected void Application_BeginRequest()
        {
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.Cache.SetExpires(DateTime.UtcNow.AddHours(-1));
            Response.Cache.SetNoStore();
        }
Advertisements

Visual Studio – Enable Debug for new Build Configuration

When you are setting up new build configuration which you want to be able to debug, you need to set Debug info to Full.

Right click the project in Solution Explorer and select Properties. Select build tab and then select desired configuration from Configuration drop down list at the top of the page.

Click on Advanced at the bottom of output section and select Full from Debug Info drop down list.

Save changes to project settings and rebuild your solution.

VSBuildConfigDebug

Visual Studio 2015 – Disable file preview on single click

Visual Studio 2015 opens files for preview by default when you click on a file in solution explorer.

If you wish to disable this, go to Tools -> Options, and under Environment select “Tabs and Windows” settings. Under “Preview Tab” section, deselect “Allow new files to be opened in the preview tab” option and click on OK. Now when you click on a file in solution explorer it won’t open in preview tab.

This also applies to Visual Studio 2012 and 2013.

VS2015TabsAndWindowsSetting