OWIN middleware implementation for Windows Authentication.
- Disable Anonymous Authentication
- Enable Windows Authenticaion
- Remove the authentication section
- Remove FormsAuthentication
<system.web>
<!--<authentication mode="Windows" />-->
<compilation debug="true" targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.2" />
</system.web>
<system.webServer>
<modules>
<remove name="FormsAuthentication" />
</modules>
</system.webServer>
<runtime>
Use this code in your Startup
using WindowsAuthentication.Middleware;
public partial class Startup
{
public void Configuration(IAppBuilder app)
{
app.SetDefaultSignInAsAuthenticationType(WindowsAuthenticationDefaults.AuthenticationType);
app.UseWindowsAuthentication(new WindowsAuthenticationOptions()
{
AuthenticationMode = Microsoft.Owin.Security.AuthenticationMode.Active,
SignInAsAuthenticationType = WindowsAuthenticationDefaults.AuthenticationType,
AuthenticationType = WindowsAuthenticationDefaults.AuthenticationType,
Provider = new WindowsAuthenticationProvider
{
OnAuthenticated = context =>
{
// context.Identity is of type ClaimsIdentity and can be extended;
context.Identity.AddClaim(new Claim("app:name", "MvcWindowsAuthentication"));
return Task.FromResult(true);
}
}
});
}
}