IIS7 application authentication

Jan 29, 2013 at 8:54 AM

Hi Mike, is it possible to set the authentication settings at the application level?  For example I'm creating an Application under Default Web Site.  The web site has anonymous authentication enabled, but I'd like the application to use Windows authentication.

I'm using Iis7Website TaskAction="AddApplication".

Feb 12, 2013 at 3:08 PM
I've forked the source and added the following to the end of the foreach loop in IIS7Website.ProcessApplications():
this.LogTaskMessage(string.Format(CultureInfo.CurrentCulture, "Setting additional settings for Application: {0}", app.ItemSpec));
Configuration config = this.iisServerManager.GetApplicationHostConfiguration();

if (!string.IsNullOrEmpty(app.GetMetadata("WindowsAuthentication")))
{
    this.LogTaskMessage(string.Format(CultureInfo.CurrentCulture, "Setting WindowsAuthentication for Application: {0}", app.ItemSpec));
    ConfigurationSection windowsAuthenticationSection = config.GetSection(
        "system.webServer/security/authentication/windowsAuthentication",
        this.Name + app.ItemSpec);
    windowsAuthenticationSection["enabled"] = app.GetMetadata("WindowsAuthentication");
}

if (!string.IsNullOrEmpty(app.GetMetadata("AnonymousAuthentication")))
{
    ConfigurationSection anonyAuthentication = config.GetSection("system.webServer/security/authentication/anonymousAuthentication", this.Name + app.ItemSpec);
    anonyAuthentication["enabled"] = app.GetMetadata("AnonymousAuthentication");
}

if (!string.IsNullOrEmpty(app.GetMetadata("DigestAuthentication")))
{
    ConfigurationSection digestAuthentication = config.GetSection("system.webServer/security/authentication/digestAuthentication", this.Name + app.ItemSpec);
    digestAuthentication["enabled"] = app.GetMetadata("DigestAuthentication");
}

if (!string.IsNullOrEmpty(app.GetMetadata("BasicAuthentication")))
{
    ConfigurationSection basicAuthentication = config.GetSection("system.webServer/security/authentication/basicAuthentication", this.Name + app.ItemSpec);
    basicAuthentication["enabled"] = app.GetMetadata("BasicAuthentication");
}

this.iisServerManager.CommitChanges();
I can now do something like this:
<ItemGroup>
    <IISApplication Include="/$(IISApplicationName)">
        <PhysicalPath>$(TargetDirectory)</PhysicalPath>
        <AppPool>$(IISAppPoolName)</AppPool>
        <WindowsAuthentication>true</WindowsAuthentication>
        <AnonymousAuthentication>false</AnonymousAuthentication>
    </IISApplication>
</ItemGroup>

<MSBuild.ExtensionPack.Web.Iis7Website TaskAction="AddApplication" Name="Default Web Site" Applications="@(IISApplication)" Force="true" />
Coordinator
May 26, 2014 at 1:12 PM
Marked as answer by mikeFourie on 5/26/2014 at 5:12 AM