C# asp.net MVC 4中的SignOut()

C# asp.net MVC 4中的SignOut(),c#,asp.net,asp.net-mvc,razor,C#,Asp.net,Asp.net Mvc,Razor,我有以下代码要注销并重定向到控制器中的另一个页面: ... public ActionResult Logout(){ FormsAuthentication.SignOut(); return Redirect("Index"); } ... 我有以下母版页: ... <body> <header> <div style="background-color:deepskyblue; width:100%; height:2

我有以下代码要注销并重定向到控制器中的另一个页面:

...
public ActionResult Logout(){
    FormsAuthentication.SignOut();
    return Redirect("Index");
}
...
我有以下母版页:

...
<body>
    <header>
        <div style="background-color:deepskyblue; width:100%; height:20px">
            @if(User.Identity.IsAuthenticated){
                <a style="position:relative; float:right; right:15px" href="@Url.Action("Logout", "Home", null)">Logout</a>
            }
            else{
                <a style="position: relative; float: right; right: 15px" href="@Url.Action("Login", "Home", null)">Login</a>
            }
        </div>
    </header>
    @RenderBody()
    <footer>
        <div style="position:relative; background-color:lightslategrey; width:100%; height:20px">
            @if(User.Identity.IsAuthenticated){
                <a style="position: relative; float: left; left: 15px" href="@Url.Action("Index", "Home", null)">Go back</a>
            }
        </div>
    </footer>
</body>
...
问题是:当注销操作被调用时,它会重定向到取消索引页面,但页眉和页脚不会改变,我必须再次单击注销或刷新页面,然后它才能工作

它如何工作而不必点击两次或刷新页面

为什么在这里使用重定向?RedirectToAction是在应用程序上下文中发出302重定向的首选方法。它遵循您的路线。我希望RedirectIndex不会总是像Redirect/Controller/Index那样工作


我修正了这一点:

            @if(User.Identity.IsAuthenticated){
                 <a style="position:relative; float:right; right:15px" href="@Url.Action("Logout", "Home", null)">Logout</a>
            }
            else{
                 <a style="position: relative; float: right; right: 15px" href="@Url.Action("Login", "Home", null)">Login</a>
            }
无论如何,感谢您的回答。

可能的副本
            @if(User.Identity.IsAuthenticated){
                 <a style="position:relative; float:right; right:15px" href="@Url.Action("Logout", "Home", null)">Logout</a>
            }
            else{
                 <a style="position: relative; float: right; right: 15px" href="@Url.Action("Login", "Home", null)">Login</a>
            }
            @if(User.Identity.IsAuthenticated){
                 @Html.ActionLink("Logout", "Logout", "MyAccount", null, new{@style="position:relative; float:right; right:15px"})
            }
            else{
                 @Html.ActionLink("Login", "Login", "MyAccount", null, new{@style="position: relative; float: right; right: 15px"})
            }