Rupesh Kahane

Rupesh Kahane

  • 102
  • 19.1k
  • 4.2m

Set Authenticated Users permission to IIS site using C# code

Jun 15 2016 5:51 AM
I have hosted one web application into my ISS. Now I don't to want to open iis and  i would like to give Authenticated Users permission to my site using c# code. (I have created application using MVC 5 )
 
 
Currently it have Creator Owner permission. Please see bellow image for more info
 
 
 
I would like to set Authenticated Users permission to this as bellow
 
 
 
I have tried bellow code but it is not working fine
 
string publishPath = System.IO.Path.GetFullPath("publish");
string folder = Context.Parameters[publishPath]; 
SecurityIdentifier sid = new SecurityIdentifier(WellKnownSidType.AuthenticatedUserSid, null);
FileSystemAccessRule writerule = new FileSystemAccessRule(sid, FileSystemRights.Write, AccessControlType.Allow); 
DirectorySecurity fsecurity = Directory.GetAccessControl(folder);
fsecurity.AddAccessRule(writerule);
Directory.SetAccessControl(folder, fsecurity);
 
 
 

Answers (1)