IIS - Disable CORS

Disable CORS for IIS 10 website by allowing all origins in two simple steps.

commit 94bf87f · authored · 1 min read

IIS - Disable CORS

For any reason you wish to disable CORS for any website hosted on IIS, one way you can do this by allowing all origins. To do that,

  1. Make sure you installed IIS CORS Module on the server.
  2. Update the Web.Config of the website to have the cors section as given below,

Note: code tested on IIS 10

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<cors enabled="true" failUnlistedOrigins="true">
<add origin="*">
<allowHeaders allowAllRequestedHeaders="true" />
</add>
</cors>
</system.webServer>
</configuration>

As you can see, we are allowing all origin’s by specifying * as the origin.

After just allowing all origins alone, if you encounter error like,

Request header field content-type is not allowed by Access-Control-Allow-Headers in preflight response.

To solve that, we are setting allowAllRequestedHeaders="true" in the allowHeaders for all the origins.

Remember: CORS is a security feature. Disable only if the resource is totally public.

Additional Resources

local graph · open full graph

"IIS - Disable CORS" is connected to the topics Internet Information Services, Web.config and related to 6 other entries. Redirect HTTPS requests to HTTP using IIS Rewrite rule in Web.Config Redirect HTTPS requests to … Redirect HTTP to HTTPS using Web.Config in IIS Redirect HTTP to HTTPS usin… Redirect WWW to Non-WWW using Web.Config in IIS Redirect WWW to Non-WWW usi… Redirect non-www urls to www urls Redirect non-www urls to ww… Azure - Configuring End-to-End SSL for IIS Website by using Application Gateway Azure - Configuring End-to-… C# - Get Web.Config Connection String in a Class Library C# - Get Web.Config Connect… Internet Information Services #iis Web.config #web-config IIS - Disable CORS

webmentions · 2 mentions

  • Someone · Feb 21, 2022 · mention

  • Someone · Dec 13, 2021 · mention

    How do I enable CORS on my Web API? You can enable CORS per action, per controller, or globally for all Web API controllers in your application. To enable CORS for a single action, set the [EnableCors] attribute on the action method. The following example enables CORS for the GetItem method only. via How do I use CORS in API? To support CORS, therefore, a REST API resource needs to implement an OP

comments

loading discussion…