i want to do this from code behind rather than writing code in the web.config file for each roles, users and pages. Is there a way to assign page level access from code behind using c#
i am creating a web application in which i will dynamically create ysers and roles. and for each user and role i will create a corresponding directory, to which only he will have access, or can give access to other users or roles. i dont want to hard code
anything and want to make my app flexible and dynamic.......thanks for your reply, but tat is not wat i want......
mohammed.kam...
Member
139 Points
92 Posts
Setting Page Access Dynamically for Users and Roles
May 10, 2012 08:24 PM|LINK
in my web.config file i am defining the page access like below
<location path="admin"> <system.web> <authorization> <deny roles="master" /> <allow roles="admin" /> <deny roles="user" /> <deny roles="inactivated" /> <deny users="*" /> </authorization> </system.web> </location>i want to do this from code behind rather than writing code in the web.config file for each roles, users and pages. Is there a way to assign page level access from code behind using c#
OWDARO
Madhu1234
Participant
1380 Points
287 Posts
Re: Setting Page Access Dynamically for Users and Roles
May 10, 2012 09:58 PM|LINK
As far as my knowledge you can this only in web.config file.
xRidx
Member
573 Points
235 Posts
Re: Setting Page Access Dynamically for Users and Roles
May 10, 2012 10:28 PM|LINK
Maybe that link help u:
http://www.dotnetcurry.com/ShowArticle.aspx?ID=102
But i dont understood why u wonna do this?
mohammed.kam...
Member
139 Points
92 Posts
Re: Setting Page Access Dynamically for Users and Roles
May 10, 2012 10:45 PM|LINK
i am creating a web application in which i will dynamically create ysers and roles. and for each user and role i will create a corresponding directory, to which only he will have access, or can give access to other users or roles. i dont want to hard code anything and want to make my app flexible and dynamic.......thanks for your reply, but tat is not wat i want......
OWDARO
xRidx
Member
573 Points
235 Posts
Re: Setting Page Access Dynamically for Users and Roles
May 10, 2012 10:56 PM|LINK
U must dynamically save ur config sections from code behind maybe another examples:
http://stackoverflow.com/questions/1755296/change-web-config-settings-in-code-behind -i dont see any way.
mohammed.kam...
Member
139 Points
92 Posts
Re: Setting Page Access Dynamically for Users and Roles
May 10, 2012 11:44 PM|LINK
not able to achieve it
is there no way to do it properly.......
i am writing this code
Configuration conf = WebConfigurationManager.OpenWebConfiguration("~"); ConfigurationLocationCollection confLocSection = conf.Locations; foreach (ConfigurationLocation location in confLocSection) { if (location.Path == "admin") { AuthorizationSection authSection = (AuthorizationSection)location.OpenConfiguration().GetSection("system.web/authorization"); authSection.Rules.Clear(); AuthorizationRule denyRule = new AuthorizationRule(AuthorizationRuleAction.Deny); denyRule.Roles.Add("admin"); authSection.Rules.Add(denyRule); } } conf.Save();the AuthorizationSection part does not work and returns a null
OWDARO
Jo em
Member
30 Points
17 Posts
Re: Setting Page Access Dynamically for Users and Roles
May 11, 2012 12:08 AM|LINK
if you already familiar in Orchard CMS, kindly check that.
Orchard Roles Authentication is very dynamic and very good example.