Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I accept CORS AJAX requests on AppHarbor?
    primarykey
    data
    text
    <p>I'm using the Thinktecture.IdentityModel nuget package to enable CORS for WebAPI controllers in an MVC Web Application. At the moment, I'm only worried about POSTs but let me know about any problems with other verbs. This works when running through the IIS Express server. </p> <p>When dealing with the AppHarbor deployment, it doesn't work. nginx doesn't seem to pass through the OPTIONS request to my code. What else is needed to get it running on AppHarbor?</p> <h3>Request</h3> <blockquote> <p>OPTIONS $path HTTP/1.1<br> Host: $servername Connection: keep-alive<br> Access-Control-Request-Method: POST<br> Origin: <a href="http://www.local" rel="nofollow">http://www.local</a><br> User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.56 Safari/537.17<br> Access-Control-Request-Headers: accept, origin, content-type<br> Accept: <em>/</em><br> Referer: <a href="http://www.local/wordpress/2013/01/request-url-test/" rel="nofollow">http://www.local/wordpress/2013/01/request-url-test/</a><br> Accept-Encoding: gzip,deflate,sdch<br> Accept-Language: en-GB,en;q=0.8,en-US;q=0.6<br> Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3 </p> </blockquote> <h3>Response</h3> <blockquote> <p>HTTP/1.1 200 OK<br> Server: nginx<br> Date: Wed, 30 Jan 2013 02:34:14 GMT<br> Content-Length: 0<br> Connection: keep-alive<br> Allow: OPTIONS, TRACE, GET, HEAD, POST<br> Public: OPTIONS, TRACE, GET, HEAD, POST </p> </blockquote> <p>My web.config is set up with the following default handlers:</p> <pre><code>&lt;handlers&gt; &lt;remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" /&gt; &lt;remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" /&gt; &lt;remove name="ExtensionlessUrlHandler-Integrated-4.0" /&gt; &lt;add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" /&gt; &lt;add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" /&gt; &lt;add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" /&gt; &lt;/handlers&gt; </code></pre> <h2>Is WebDAV to blame?</h2> <p>After the suggestion of Jeffery To, I disabled WebDAV by <a href="http://brockallen.com/2012/10/18/cors-iis-and-webdav/" rel="nofollow">following these instructions</a>. Didn't even know WebDAV was installed on AH, but doing this did change my results.</p> <h3>Relevant Web.config sections</h3> <pre><code>&lt;handlers&gt; &lt;remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" /&gt; &lt;remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" /&gt; &lt;remove name="ExtensionlessUrlHandler-Integrated-4.0" /&gt; &lt;remove name="WebDAV" /&gt; &lt;add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" /&gt; &lt;add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" /&gt; &lt;add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" /&gt; &lt;/handlers&gt; &lt;modules runAllManagedModulesForAllRequests="true"&gt; &lt;remove name="WebDAVModule"/&gt; &lt;remove name="AspNetAppHarborIntegration" /&gt; &lt;add name="AspNetAppHarborIntegration" type="Premotion.AspNet.AppHarbor.Integration.AppHarborModule, Premotion.AspNet.AppHarbor.Integration" /&gt; &lt;/modules&gt; </code></pre> <h3>Request</h3> <blockquote> <p>OPTIONS $path HTTP/1.1<br> Host: $servername<br> Connection: keep-alive<br> Access-Control-Request-Method: POST<br> Origin: <a href="http://www.local" rel="nofollow">http://www.local</a><br> User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.57 Safari/537.17<br> Access-Control-Request-Headers: accept, origin, content-type<br> Accept: <em>/</em><br> Referer: <a href="http://www.local/wordpress/2013/01/request-url-test/" rel="nofollow">http://www.local/wordpress/2013/01/request-url-test/</a><br> Accept-Encoding: gzip,deflate,sdch<br> Accept-Language: en-GB,en;q=0.8,en-US;q=0.6<br> Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3 </p> </blockquote> <h3>Response</h3> <blockquote> <p>HTTP/1.1 405 Method Not Allowed<br> Server: nginx<br> Date: Mon, 04 Feb 2013 17:09:19 GMT<br> Content-Type: application/json; charset=utf-8<br> Content-Length: 76<br> Connection: keep-alive<br> Cache-Control: no-cache<br> Pragma: no-cache<br> Expires: -1 </p> </blockquote>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload