我如何站点范围内的无缓存标头添加到一个MVC 3应用程序 [英] How do I add site-wide no-cache headers to an MVC 3 app
问题描述
我建了一个MVC3应用程序,应用程序了有大量的页面,现在因为安全问题,我需要添加无缓存设置在HTTP头,是任何简单的方法来做到这一点?如果我们可以修改一个地方那么它将为整个应用程序的工作,这将是完美的。
I built a MVC3 app, the applicaiton have lot of pages, now because security issues I need to add the no-cache setup in http headers, Is any easier way to do it? if we can modify one place then it will working for entire application, it will be perfect.
你们能帮助我吗?
推荐答案
如何设置 Application_ preSendRequestHeaders
事件里面的标题在的Global.asax
How about setting the Headers inside the Application_PreSendRequestHeaders
event in Global.asax?
修改
您可以使用 Response.Cache.SetCacheability
,而不是直接设置标头。*
EDIT
You can use Response.Cache.SetCacheability
rather than setting the Headers directly.*
void Application_PreSendRequestHeaders(Object sender, EventArgs e)
{
Response.Cache.SetCacheability(HttpCacheability.NoCache);
}
经测试,在提琴手。
的通过手动设置页眉替代方法。的
void Application_PreSendRequestHeaders(Object sender, EventArgs e) {
Response.Headers.Set("Cache-Control", "no-cache");
}
这篇关于我如何站点范围内的无缓存标头添加到一个MVC 3应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!