ASP.NET MVC刷新头问题

时间:2011-03-07 02:00:18

标签: asp.net-mvc http-headers refresh

我想在重定向到另一个页面后调用一个动作方法(DownloadPictures),所以我使用刷新标题

UrlHelper url = new UrlHelper(Request.RequestContext);
Response.AddHeader("REFRESH" , "1;URL=" + url.Action("DownloadPictures" , "Cart" , new { isFree = true }));
return Redirect(returnUrl != null ? returnUrl : url.Action("Index", "Home"));

我的下载图片方法在第一行设置了断点,但这个方法永远不会被调用

public ActionResult DownloadPictures ( bool? isFree ) {
    Cart cart = (Cart)HttpContext.Session["_cart"];
    ....
    //The Download Picture Method returns a File (a zip file)
}

任何帮助将不胜感激。感谢

1 个答案:

答案 0 :(得分:2)

大多数浏览器会忽略刷新标头

使用其他方法,例如javascript等

e.g。

<html>
<head>
<script type="text/javascript">
  function delayRedirect()
  {
    window.location = "/DownloadPictures";
  }
</script>
</head>
<body onLoad="setTimeout('delayRedirect()', 1000)">
...
</body>
</html>