Like for example when a user vists the index page he sees content that is different from the content that a logged in user sees.
How can i achieve this, does this require some kind of annotation or something else ?
Have you tried _Layout view or partial views?
There is more than one way to handle this...
If you want to handle it in the controller or the view its up to you. Ideally I would hazard a guess the choice depends on what you want to display or not display as the case may be.
If you handle it in the controller....
Function Index()As ActionResult
If Request.IsAuthenticated Then
' Logged in is TRUE
Return View(LoggedInUserContentModel)
Else
' Logged in is FALSE
Return View(SiteGuestUserContentModel)
End If
End Function
If you handle it in the View.... DIRECTLY Showing page content
<% If Request.IsAuthenticated Then %>
<!-- User is Logged In -->
Welcome <b><%: Page.User.Identity.Name %></b>!
[ <%: Html.ActionLink("Log Off", "LogOff", "Account")%> ]
<% Else %>
<!-- User is NOT Logged In -->
Welcome <b>Guest</b> please login!
[ <%: Html.ActionLink("Log On", "LogOn", "Account")%> ]
<% End If %>
You may optionally choose not to directly show content embedded on the page itself but may choose to show content retrieved from within a ChildAction (this would be similar to showing it in a UserControl using the old non MVC style of web design as opposed to directly placing the content on the web page)