Reputation: 1113
I am using asp.net mvc 4.
I have a header with two sections, top and bottom. The top section simply displays static links and images.
The bottom section will show a login button and other information when a user is not logged in.
Once the user logs in the bottom section will show user specific information and overall game play information. I want to reload this information whenever a user makes a request to a page on the site and I determine the data is stale.
Using asp.net web forms I could create a user control to represent the bottom sections functionality.
It appears in asp.net mvc I can use partial views and then call RenderAction which would allow a controller action to be called when rendering the bottom section.
In the controller action I could render one partial view for authenticated users and another partial view for unauthenticated users. I could also reload the data for authenticated users if it is determined to be stale.
Is this the best approach? I don't need ajax for my bottom section.
Thanks
Upvotes: 1
Views: 610
Reputation: 3725
It depends on the complexity of your bottom section. If there's not much logic, you can put authenticated and unauthenticated html code in a single partial view. If they are quite different, use two separated partial views is OK. Also, simply put button section into your master page is also a common practice, there'are no quite differences.
If you leverage .net mvc's authentication framework(which should be best practice), you can simply use User.Identity.IsAuthenticated in your Action. In View page it's Page.User.Identity.IsAuthenticated. It can check whether current user has signed in.
Upvotes: 3
Reputation: 1745
There are several ways and it all depends what kind of Authorization mechanism you're using. The general rule is that you query (pseudo code here) @if(IsAuthenticated(currentUser) { bla bla } else non authenticated content
Take a look at this project with sample and documentation http://nerddinnerbook.s3.amazonaws.com/Intro.htm
It will drive you through what you are trying to accomplish.
Upvotes: 1