---
title: "Clearing Cache in Asp.net"  
description: "In computer engineering, a cache is a component that transparently stores data so that future requests for that data can be served faster. If requeste"  
author: "Chris Anderson"  
published: 2011-08-09  
updated: 2014-09-18  
canonical: https://www.mindstick.com/blog/222/clearing-cache-in-asp-dot-net  
category: "asp.net"  
tags: ["asp.net"]  
reading_time: 2 minutes  

---

# Clearing Cache in Asp.net

In computer [engineering](https://www.mindstick.com/blog/12520/earning-a-internal-engineering-graduate-rank-online), a cache is a [component](https://www.mindstick.com/articles/12262/learn-how-to-make-a-component-in-magento-2) that transparently stores data so that future requests for that data can be served faster. If requested data is contained in the cache, this [request](https://www.mindstick.com/blog/255/post-get-and-request-function-in-php) can be served by simply [reading](https://www.mindstick.com/articles/126273/books-commonly-found-on-college-reading-lists) the cache, which is comparatively faster. But there are times when we need to [clear cache](https://www.mindstick.com/forum/157336/how-to-clear-cache-in-asp-dot-net-mvc) to [enhance security](https://answers.mindstick.com/qa/102085/how-do-password-manager-programs-enhance-security).

##### HOW TO CLEAR CACHE ON LOGOUT?

Suppose we have two page login.aspx and home.aspx. In login.aspx we have login panel and on the click of login button valid user can access their details in home.aspx and in home.aspx we also have a logout button and after logout we have to expires the [session](https://www.mindstick.com/articles/12042/session-in-c-sharp) of user and remove the cache from [browser](https://www.mindstick.com/blog/155254/which-is-the-best-internet-browser) so that [previous](https://yourviews.mindstick.com/view/81421/unlock-2-0-is-just-like-previous-corona-lockdowns) pages cannot be visited by clicking browser back button.

```
// index.aspx - startprotected void btnLogin_Click(object sender, EventArgs e){            Session["emailid"] = txtUSerID.Text;            Response.Redirect("Home.aspx");}// index.aspx - end // home.aspx - startprotected void Page_Load(object sender, EventArgs e){        Response.Buffer = true;        Response.ExpiresAbsolute = DateTime.Now.AddDays(-1d);        Response.Expires = 0;        Response.CacheControl = "no-Cache";        if (Session["emailid"] == null)            Response.Redirect("index.aspx");}protected void btnLogout_Click(object sender, EventArgs e){        Session["emailid"] = null;        string nextpage = "index.aspx";        Response.Redirect(nextpage);}// home.aspx - end
```

The code above removes the cache from the browser and prevents [unauthorized access](https://www.mindstick.com/forum/158562/how-can-wireless-networks-be-secured-against-unauthorized-access-and-attacks) to the previous page after log out and cannot able to access the previous page by clicking on the browser back button.

---

Original Source: https://www.mindstick.com/blog/222/clearing-cache-in-asp-dot-net

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
