I have a AuthorizationProvider that needs to use both Anonymous and Windows and I can't seem to get then windows challenge to work using:
if (principal == null || principal.Identity == null || string.IsNullOrWhiteSpace(principal.Identity.Name))
{
context.OwinContext.Authentication.Challenge();
return Task.FromResult(0);
}
Are there any other configuration values I need to set in order for this line to work? : context.OwinContext.Authentication.Challenge();
Any thoughts why this will not work? I need to be able to get the windows principal which works fine with just windows enabled but also need to enable anonymous in order to be able to hit other endpoints in the provider.
On the taskbar, click Start, and then click Control Panel. In Control Panel, click Programs and Features, and then click Turn Windows Features on or off. Expand Internet Information Services, then World Wide Web Services, then Security. Select Windows Authentication, and then click OK.
To uninstall Windows authentication agent using control panel, perform the following steps: Click Start menu > Control Panel > Programs and Features. Right click NetIQ Windows Authentication Agent and select Uninstall. Click OK to confirm.
In short, you should enable Windows authentication in your Web host. There are different settings, depending on the Web host you are using.
After configuring the Web host, your controller code starts working.
OWIN self-host
Configure HttpListener
to accept both authentication modes in OWIN Startup
class:
class Startup
{
public void Configuration(IAppBuilder app)
{
var listener = (HttpListener)app.Properties["System.Net.HttpListener"];
listener.AuthenticationSchemes =
AuthenticationSchemes.IntegratedWindowsAuthentication |
AuthenticationSchemes.Anonymous;
// Other initialization
}
}
IIS
If you are hosting your application on IIS, you should enable Windows authentication mode in IIS Web site settings for your application:
If you don't see Authentication icon or Windows authentication mode, install following Windows features:
Visual Studio Web debugging (IIS Express)
Finally, for convenience of Web debugging from Visual Studio, you can enable Windows authentication in your project properties. Open Solution explorer and select your project:
Then open Properties tab and set both anonymous and Windows authentication:
For more details, you can check out this article.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With