I define OutputCache attributes on top of my controller actions, so that the server can give the same response quickly to different users. Bu it caches the whole page. I mean the master page is also cached if I have cached an action that returns a View()
. So the user account information on top of the master page gets shared by every user. I want to cache only the content page, not the master page, _Layout.cshtml. How can I exclude that?
Edit: The part where I'm having trouble is this:
@if(Request.IsAuthenticated) {
<text>Hello <strong>@User.Identity.Name</strong>!</text>
@: |
@Html.ActionLink("Index", "Index", "Account")
@: |
@Html.ActionLink("Logout", "Logout", "Account")
}
else
{
@:|
@Html.ActionLink("Login", "Login", "Account")
}
When I cache a controller action, the returned view also carries this userlogin part from the cache, so it gives wrong salutes to almost every user. How can I dynamically generate this part even if the page is cached?