Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

401 response for CORS request in IIS with Windows Auth enabled

I'm trying to enable CORS support in my WebAPI project, and if I enable Anonymous Authentication then everything works fine, but with Windows Auth + disabled anonymous authentication, the OPTIONS request sent always returns a 401 unauthorized response. The site requesting it is on the DOMAIN so should be able to make the call, is there any way to get around the issue without disabling Windows Authentication?

like image 257
dariusriggins Avatar asked May 23 '12 15:05

dariusriggins


People also ask

What is 401. 1?

The HTTP status and sub status are 401.1, which maps to Access Denied due to Invalid credentials.


Video Answer


1 Answers

You can allow only OPTIONS verb for anonymous users.

<system.web>   <authentication mode="Windows" />     <authorization>       <allow verbs="OPTIONS" users="*"/>       <deny users="?" />   </authorization> </system.web> 

According W3C specifications, browser excludes user credentials from CORS preflight: https://dvcs.w3.org/hg/cors/raw-file/tip/Overview.html#preflight-request

like image 61
Jan Remunda Avatar answered Sep 26 '22 23:09

Jan Remunda