ASP.NET MVC Output Cache enables you to
cache the action result content by a MVC controller action. By default MVC
Output cache is enabled. So for this you don’t need to do anything, if client
will send same request, browser will not forward request to MVC controller and
it returns previous cached result but in few scenario, you don’t want to cache
controller action result and want to disabled output caching for specific
controller action.
You
can use [OutputCache] attribute to disabled or enabled the
browser caching for specific action or all action in controller.
·
Action
Level:
Disable output caching for specific action only
public class HomeController : Controller
{
[OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]
public ActionResult Index(ParametersData parameters)
{
return View();
}
}
·
Controller
Level:
Disable output caching for all actions in controller
[OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]
public class HomeController : Controller
{
public ActionResult Index(ParametersData parameters)
{
return View();
}
}
·
Global/Application
Level
You can a add a action filer in FilterConfig.cs for disabling
caching for application controllers
public class FilterConfig
{
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new CustomHandleErrorAttribute());
filters.Add(new OutputCacheAttribute
{
VaryByParam
= "*",
Duration
= 0,
NoStore
= true,
});
}
}
Other
ASP.NET MVC related topics:
- ASP.NET MVC how to disable Caching
- Ajax Get method not hitting the
ASP.NET MVC Controllers
- Asp.net MVC view not refreshing after
postback
- OutPutCache Action Filter in
ASP.NET MVC
Thanks for visiting!!
2 comments:
Hire asp.net developers for all your web applications development, CMS customisations and migrating your existing apps to the .NET Platform seamlessly now.
Thanks for sharing this informative article on how to disable Caching in Asp Dot Net development with useful examples. If you have any requirement to Hire ASP.Net Developers for your web development solution. Please contact us.
Post a Comment