Add user and role to AuthorizationRule : AuthorizationSection « Configuration « ASP.NET Tutorial






<%@ page language="C#" %>
<%@ import namespace="System.Web.Management" %>

<script runat="server">

void Page_Load(object sender, System.EventArgs e)
{
    string appPath = this.Request.ApplicationPath;    
    Configuration config = Configuration.GetConfigurationForUrl(appPath);
    AuthorizationSection authorization = config.Web.Authorization;

    AuthorizationRule rule = new AuthorizationRule();
    rule.Action = AuthorizationRuleAction.Allow;
    rule.Users.Add("TestUser");
    rule.Roles.Add("TestRole");
    authorization.Rules.Add(rule);

    config.Update();
}
    
</script>

<html>
<head id="Head1" runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="Form1" runat="server">

    </form>
</body>
</html>








16.8.AuthorizationSection
16.8.1.Bind datalist to Authorization Section in your configuration
16.8.2.Add user and role to AuthorizationRule