Views MVC | How to make * YOU * process IsAuthenticated authentication scripts?

As a rule, on sites that allow membership, you want to offer your users some data that is visible only when you log in.

For my site, if a registered user is the owner of the data, I want to offer some tools that allow them to manage the data.

My question is that. Do you share this responsibility between two different views? One view is loaded for "regular" users, and the other is loaded for "owner" users. The view that ordinary users see simply shows the data. The owner sees the data and some tools for managing it.

Or do you perform checks in one view and hide / show blocks inside it (similar to what you would do in normal ASP.NET)?

This may be a preference, but are there any technical reasons for sharing responsibilities between the two views and the only species?

+4
source share
4 answers

I would also like to use one view option. Would provide specific properties in your viewpoints to indicate what to do.

<% if (Model.IsOwner) { %> //Html for owner <% } %> 
+5
source

Personally, I would choose one viewing option. This way you do not need to repeat the code that will be displayed in both views.

Technically (or in relation to the MVC pattern), I cannot think of any reason to separate it.

+1
source

I would be inclined to divide the presentation into short ones, since ideally you want to avoid conditional logic in the presentation (read: ideally).

If you find that this will lead to some duplication between your views, perhaps you can move this duplicate content into shared parts.

0
source

Usually I want to do additional content in partial, with conditional logic in partial role checking before rendering:

 <%-- Master Page --%> <% Html.RenderPartial("DataOwnerStuff"); %> <%-- Partial --%> <% if(Roles.IsUserInRole("DataOwner")) { %> <h1>Hi Data Owner!</h1> <% } %> 
0
source

All Articles