Monday, December 21, 2015

How set in IIS to allow specific user in to our website ?


The authorization (<authorization>) element allows you to allow the user accounts that can access your site or application.
Authorization is a combination of authentication to secure the access to content on your site. Authentication confirm the user identity of a user , while authorization determines what resources users can or cannot access.
Ø  There are two rules to authenticate the user in IIS:
·       Allow rules let you define the user accounts or user groups that can access a site, an application, or all the sites on a server.
·       Deny rules let you define the user accounts or user groups that cannot access a site, an application, or all the sites on a server
Versions:

Version     Notes
IIS 8.5       The <authorization> element was not modified in IIS 8.5.
IIS 8.0       The <authorization> element was not modified in IIS 8.0.
IIS 7.5       The <authorization> element was not modified in IIS 7.5.
IIS 7.0       The <authorization> element was introduced in IIS 7.0.
IIS 6.0       The <authorization> collection replaces the IIS 6.0 AzEnable, AzStore              Name, AzScopeName, andAzImpersonationLevel metabase properties.
  
Step 1:
Add authentication rule In IIS :
·       In IIS setting -> Authorization rules ->
·       Add new authorization rules.


Configuration :
<configuration>
   <system.webServer>
      <security>
         <authorization>
            <remove users="*" roles="" verbs="" />
            <add accessType="Allow" users="" roles="Administrators" />
         </authorization>
      </security>
   </system.webServer>
</configuration>

Security Authorization <authorization>:

 C#

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("Contoso");
         ConfigurationSection authorizationSection = config.GetSection("system.webServer/security/authorization");
         ConfigurationElementCollection authorizationCollection = authorizationSection.GetCollection();

         ConfigurationElement addElement = authorizationCollection.CreateElement("add");
         addElement["accessType"] = @"Allow";
         addElement["roles"] = @"administrators";
         authorizationCollection.Add(addElement);

         serverManager.CommitChanges();
      }
   }
}





0 comments:

Thanks for commenting..,,

Copyright © 2016 CodeSharing| Design by CodingSharing.