Answered by:
Add User To Virtual Directory Permissions

Question
-
User482326764 posted
1 - I added a User To Windows
2 - i created a Virtual Directory With C#
3 - How can Add a User To Virtual Directory Permissions With C# .
tanksSaturday, December 31, 2011 11:05 PM
Answers
-
User-1672167363 posted
Hello,
Then http://www.iis.net/ConfigReference Expand to virtualDirectory
http://www.iis.net/ConfigReference/system.applicationHost/sites/site/application/virtualDirectory
http://www.iis.net/ConfigReference/system.applicationHost/applicationPools/add/processModel has users
there is C# Code.
The Reference for IIS 7.0 IIS 7.5 Server :
Configuration reference guides are available as compiled Help files from here [IIS 7.0] and here [IIS 7.5].
The Editor for IIS 7.0 IIS 7.5 Server http://learn.iis.net/page.aspx/418/editing-collections-with-configuration-editor/
makes doing C# code easier.
HTH
Martin
- Marked as answer by Anonymous Tuesday, September 28, 2021 12:00 AM
Monday, January 2, 2012 5:39 PM -
User1558068163 posted
Hi,As Martin said Configuration editor makes doing C# code easier.
Here is the C# code of adding a user permission to a virtual directory generated by configuration editor:
using System;
using System.Text;
using Microsoft.Web.Administration;internal static class Sample
{private static void Main()
{
using(ServerManager serverManager = new ServerManager())
{
Configuration config = serverManager.GetWebConfiguration("your site name here" , "virtual directory name here");
ConfigurationSection authorizationSection = config.GetSection("system.webServer/security/authorization");
ConfigurationElementCollection authorizationCollection = authorizationSection.GetCollection();
ConfigurationElement addElement = authorizationCollection.CreateElement("add");
addElement["accessType"] = @"Allow";
addElement["users"] = @"username here";
authorizationCollection.Add(addElement);
serverManager.CommitChanges();
}
}
}- Marked as answer by Anonymous Tuesday, September 28, 2021 12:00 AM
Tuesday, January 3, 2012 5:40 AM
All replies
-
User-1672167363 posted
Hello,
Have you tried using the Configuration Editor to generate
the C# code http://learn.iis.net/page.aspx/417/using-configuration-editor-generate-scripts/ ?
Martin
Sunday, January 1, 2012 1:07 AM -
User482326764 posted
I Want To Add Permission To a Virtual Directory With C# .
Monday, January 2, 2012 3:42 PM -
User-1672167363 posted
Hello,
Then http://www.iis.net/ConfigReference Expand to virtualDirectory
http://www.iis.net/ConfigReference/system.applicationHost/sites/site/application/virtualDirectory
http://www.iis.net/ConfigReference/system.applicationHost/applicationPools/add/processModel has users
there is C# Code.
The Reference for IIS 7.0 IIS 7.5 Server :
Configuration reference guides are available as compiled Help files from here [IIS 7.0] and here [IIS 7.5].
The Editor for IIS 7.0 IIS 7.5 Server http://learn.iis.net/page.aspx/418/editing-collections-with-configuration-editor/
makes doing C# code easier.
HTH
Martin
- Marked as answer by Anonymous Tuesday, September 28, 2021 12:00 AM
Monday, January 2, 2012 5:39 PM -
User1558068163 posted
Hi,As Martin said Configuration editor makes doing C# code easier.
Here is the C# code of adding a user permission to a virtual directory generated by configuration editor:
using System;
using System.Text;
using Microsoft.Web.Administration;internal static class Sample
{private static void Main()
{
using(ServerManager serverManager = new ServerManager())
{
Configuration config = serverManager.GetWebConfiguration("your site name here" , "virtual directory name here");
ConfigurationSection authorizationSection = config.GetSection("system.webServer/security/authorization");
ConfigurationElementCollection authorizationCollection = authorizationSection.GetCollection();
ConfigurationElement addElement = authorizationCollection.CreateElement("add");
addElement["accessType"] = @"Allow";
addElement["users"] = @"username here";
authorizationCollection.Add(addElement);
serverManager.CommitChanges();
}
}
}- Marked as answer by Anonymous Tuesday, September 28, 2021 12:00 AM
Tuesday, January 3, 2012 5:40 AM -
User-1672167363 posted
Hi,
Dalong Zang did the C# code.
I was to "Lazy" to even use the Editor :(
I want the "Permission" that you mark his answer as the best so far :).
Martin
Tuesday, January 3, 2012 5:57 AM