有人会告诉我,如果在ASP中有Response.AddHeader("Refresh", "10")
的模拟。请问.NET MVC5?我试过[OutputCache(NoStore = true, Location = OutputCacheLocation.Client, Duration = 10)]
但它不起作用。什么是ASP中的Response.AddHeader(“刷新”,“10”)的模拟。 NET MVC5
1
A
回答
1
您可以在控制器
public ActionResult MyAction()
{
Response.AddHeader("Refresh", "10");
return View();
}
直接使用它,或者你可以做一个自定义的行为过滤
public class RefreshAttribute : ActionFilterAttribute, IActionFilter
{
public string Duration { get; set; }
public override void OnActionExecuted(ActionExecutedContext filterContext)
{
var duration = 10;
Int32.TryParse(this.Duration, out duration);
filterContext.HttpContext.Response.AddHeader("Refresh", duration.ToString());
}
}
使用
[Refresh(Duration = "10")]
public ActionResult MyAction()
{
return View();
}
2
[OutputCache]
适用于高速缓存动作的输出。 Duration
param只是告诉它需要多长时间来缓存该输出。无论有什么向做设置HTTP头,并且肯定不会自动进行刷新页面。
Reponse.AddHeader
仍处于MVC5有效;你只需要确保你还没有开始响应。除非你在墙上做点什么,这并不难。如果你正在返回ViewResult
,例如,只需要调用这个第一:
Response.AddHeader("Refresh", "10");
return View();
如果你直接写入到响应,那么就确保你添加页眉你开始做之前。
相关问题
- 1. 什么是.NET中的Date.UTC的模拟
- 2. Python中.Net InvalidOperationException的模拟是什么?
- 3. iOS 10中的CTCallStateIncoming的模拟是什么?
- 4. ASP .NET Apps v2.0 *的WMI类是什么?
- 5. 什么的.NET Buffer.BlockCopy的纯C模拟?
- 6. ASP .NET MVC 4中“Internet应用程序”模板中的ASP .NET使用的OAuth包是什么?
- 7. Haskell中的ConcurrentHashMap的模拟是什么?
- 8. MVC5中的对象是什么?
- 9. 为什么我的asp更新面板只刷新一次
- 10. 在php中struct.pack()的模拟是什么?
- 11. Android中MKLocalSearch的模拟是什么?
- 12. 什么是log4j2中的getCurrentLoggers模拟
- 13. ASP NET MVC会话刷新丢失
- 14. .net中的设计模式是什么?
- 15. .NET中MSMQ的新技术是什么
- 16. sqlite3 datatype varchar(10)中的10是什么?
- 17. 为什么视图不刷新? (.Net MVC)
- 18. ASP .NET MVC5 - CSS样式发出─“@ Html.ValidationMessageFor”
- 19. 什么是Flash/Flex的C#.Net模拟flash.utils.ByteArray?
- 20. ios7:拉,刷新模拟器
- 21. 在HTML中呈现的asp .net验证器是什么?
- 22. 什么是在ASP .NET MVC 5中使用的Startup.Auth.cs和Startup.cs?
- 23. 什么是由Hibernate的Session.flush刷新()
- 24. “刷新令牌”的用途是什么?
- 25. jQuery给$是undefined而刷新页面?(asp .net MVC2)
- 26. 什么是Azure存储模拟器上的新的$ Metrics表?
- 27. 模拟bash的[ctrl] -l,**刷新**
- 28. 什么是.net中的AutoClass?
- 29. 什么是.NET中的“AxSHDocVw”?
- 30. 什么是.NET中的WCF?
你可以用'Response.AddHeader() '在MVC5中。你想达到什么目的?什么“不起作用”? – Jasen
@Jasen我认为应该是一些方法属性标记来做到这一点,对吧? –
将其直接添加到控制器操作中。或者制作自定义操作过滤器以获取属性样式。 – Jasen