Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post May 11, 2012 12:08 AM by Jo em
May 10, 2012 08:24 PM|LINK
in my web.config file i am defining the page access like below
<deny roles="master" />
<allow roles="admin" />
<deny roles="user" />
<deny roles="inactivated" />
<deny users="*" />
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#
May 10, 2012 09:58 PM|LINK
As far as my knowledge you can this only in web.config file.
May 10, 2012 10:28 PM|LINK
Maybe that link help u:
But i dont understood why u wonna do this?
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......
May 10, 2012 10:56 PM|LINK
U must dynamically save ur config sections from code behind maybe another examples:
-i dont see any way.
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");
AuthorizationRule denyRule = new AuthorizationRule(AuthorizationRuleAction.Deny);
the AuthorizationSection part does not work and returns a null
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.