为什么我的应用程序中的所有Razor视图都在缓存?

时间:2011-12-07 15:23:55

标签: asp.net-mvc asp.net-mvc-3

我有一个MVC 3应用程序,我正在使用剃刀视图。我有一个SiteLayout.cshtml页面,这是该站点的主页面。然后,我有一个Login.cshtml页面,它使用SiteLayout.cshtml作为母版页。我还有一个_ViewStart.cshtml页面,将主页面应用到所有cshtml页面。

我最近在登录页面添加了“忘记密码”链接。当我运行应用程序时,它不会显示新链接。我清理了解决方案&重建解决方案,但这没有帮助。它几乎像剃刀视图被缓存。我检查了所有浏览器设置(IE,Firefox,Chrome)以确保它们没有缓存。

我对这一个感到非常难过。任何想法??

以下是母版页的代码:

@using System.Web.UI.WebControls
@{
    Layout = null;
}
<!DOCTYPE html>
<html lang="en">
<head runat="server">
    <title>Application - @ViewBag.Title</title>
    <script src="/Scripts/jquery-1.7.min.js" type="text/javascript"> </script>
    <script src="/Scripts/jquery.tools.min.js" type="text/javascript"> </script>
    <link rel="stylesheet" type="text/css" media="all" href="/Content/Site.css" />
</head>
<body>
    <!-- Total width: 1180px -->
    <div id="maincontainer">
        <div id="header">
            <span style="text-align:left; float:left;">Header</span>
            <span style="text-align:right; float:right; width:200px;">@Html.Partial("LoginStatus")</span>
        </div>
        <div id="maincontent">
            @RenderBody()
        </div>
    </div>
</body>
</Html>

登录视图的代码:

@{
    ViewBag.Title = "Login";
}
<div style="width:500px;">
@using(Html.BeginForm("Authenticate", "Account", FormMethod.Post))
{
    <fieldset>
        <legend>Login</legend>
        <div class="errorMessage">@Html.ValidationMessage("LoginError")</div>
        <label for="Email">Email</label>
        @Html.TextBox("Email", string.Empty, new { @style = "width:250px;" })
        <label for="Password">Password</label>
        @Html.Password("Password", string.Empty, new { @style = "width:100px;" }) <br/><br />
        <div class="buttons">
            <button type="submit" class="positive" name="login">
                <img src="/Content/images/lock_open.png" alt=""/>
                Login
            </button>
        </div>
        <p>@Html.ActionLink("Forgot Password?", "ForgotPassword", "Account")</p>
    </fieldset>
}
</div>

最后,_ViewStart的代码:

@{
    Layout = "~/Views/Shared/SiteLayout.cshtml";
}

3 个答案:

答案 0 :(得分:2)

按[control] + F5强制刷新。

在每个Action方法上方,您可以为该页面设置输出缓存属性。这是一篇关于它的文章output caching

或者,您可以在web.config

中设置站点范围内的缓存首选项

答案 1 :(得分:0)

除了您提到的清理和重建之外,您可能需要检查并确保没有运行.NET Development Server的任何实例。

如果您根本不想进行缓存,可以使用以下属性来确保不缓存任何内容:

[OutputCache(NoStore = true, Duration = 0, VaryByParam = "None")]
//Your Controller Here

答案 2 :(得分:0)

我想我已经弄清楚了。我确信它与我的机器的配置有关,因为它不会发生在其他人身上。因此,我强制选择一个端口,而不是让VS2010分配自己的端口。我现在得到了新观点。