asp.net mvc - showing and hiding the _layout view sections based on User custom groups -


i created own user permission tables, each user can belong many groups , many security roles. have following part of _layout view:-

<li class="nav-header hidden-tablet"style="background-color:#3e9bd4 ; color:white">user section</li> <li><a class="ajax-link" href="~/home/contact"><i class="icon-home"></i><span class="hidden-tablet">contact</span></a></li>  <li class="nav-header hidden-tablet"style="background-color:#3e9bd4 ; color:white">administration section</li> <li><a class="ajax-link" href="~/securitygroup/"><i class="icon-home"></i><span class="hidden-tablet">security groups</span></a></li> <li><a class="ajax-link" href="~/securityrole/"><i class="icon-home"></i><span class="hidden-tablet">security roles</span></a></li> <li><a class="ajax-link" href="~/auditinfo"><i class="icon-home"></i><span class="hidden-tablet">audit</span></a></li> <li><a class="ajax-link" href="~/securitygroup/adusers"><i class="icon-home"></i><span class="hidden-tablet">active directory</span></a></li> 

so how can show administration section if current user belongs group associated predefined security role named “admin” or directly linked security role.

i not storing of users info inside application , users exists inside active directory . have following models classes:-

public partial class group      {          public group()          {              this.usergroups = new hashset<usergroup>();              this.securityroles = new hashset<securityrole>();          }            public int groupid { get; set; }          public string name { get; set; }          public string description { get; set; }          public byte[] timestamp { get; set; }            public virtual icollection<usergroup> usergroups { get; set; }          public virtual icollection<securityrole> securityroles { get; set; }      }      public partial class usergroup      {          public int groupid { get; set; }          public string username { get; set; }            public virtual group group { get; set; }      }  }    public partial class securityrole      {          public securityrole()          {              this.securityroletypepermisions = new hashset<securityroletypepermision>();              this.securityroleusers = new hashset<securityroleuser>();              this.groups = new hashset<group>();          }            public int securityroleid { get; set; }          public string name { get; set; }          public string description { get; set; }          public byte[] timestamp { get; set; }            public virtual icollection<securityroletypepermision> securityroletypepermisions { get; set; }          public virtual icollection<securityroleuser> securityroleusers { get; set; }          public virtual icollection<group> groups { get; set; }      }  public partial class securityroleuser      {          public int securityroleid { get; set; }          public string username { get; set; }            public virtual securityrole securityrole { get; set; }      } 

baring in mind _layout view not typed view , not able define helper method on model level such public bool isadmin(string username) .

thanks in advance help.

seeing user information not being dealt in application, don't see way can access user security rights in _layout file, 1 of first things loaded.

why not move have in _layout file partial view, create partial view identical, not including whatever rights want hide. type views , choose render each partial needed. given, need render partial every time loaded page, potentially able use models , helpers (isadmin, etc.) decide partial render.

if interested in going _layout page, try typing entire layout particular model. see "razor view engine" section of http://philjthorne.blogspot.com/2012/05/strongly-typing-aspnet-mvc-masterlayout.html more information.


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -