ASP.NET MVC OutputCache doesn't work for root URI

和自甴很熟 提交于 2019-12-03 16:59:23

问题


I'm learning ASP.NET MVC and bugged by one issue.

In the HomeController, the Index action has OutputCache attribute, but it seems doesn't work.

[HandleError]
public class HomeController : Controller
{
    [OutputCache(Duration=5, VaryByParam="none")]
    public ActionResult Index()
    {
        ViewData["Title"] = "Home Page" + DateTime.Now;
        ViewData["Message"] = "Welcome to ASP.NET MVC! " + DateTime.Now;

        return View();
    }
}

After quite a few minutes trying, I found that it is due to the way I access the action. If I access it through "http://localhost:3573/", the outputcache doesn't work. However, if I access it with "http://localhost:3575/Home/Index", the outputcache works.

Anybody know any workaround to make the default controller-action outputcacheable?

Thanks.


回答1:


I think this is a bug in ASP.NET MVC. We have logged the issue in our database and will investigate a fix for this issue.

Thanks, Eilon




回答2:


using VarByParam="" seems to make it work




回答3:


According to my contacts at Microsoft, the issue disappears entirely if you remove the Default.aspx file from the root of your site, or, if you absolutely need to have it, make sure you use the one that's provided with the latest version of ASP.NET MVC.



来源:https://stackoverflow.com/questions/323458/asp-net-mvc-outputcache-doesnt-work-for-root-uri

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!