Note that there are some explanatory texts on larger screens.

plurals
  1. POServiceStack Cors
    text
    copied!<p>I am building a project and wish to implement CORS. It is installed on a shared IIS server (shared hosting).</p> <p>In my apphost.cs I enable and configure CORS according to several of the articles I find on the web.</p> <pre><code>Plugins.Add(new CorsFeature( allowedMethods: "GET, POST, PUT, DELETE, OPTIONS", allowedOrigins: "*", allowCredentials: true, allowedHeaders: "content-type, Authorization, Accept")); </code></pre> <p>I also read that when implementing the newer SS API (IService) I had to provide a hook for the 'Options' call so I added...</p> <pre><code>this.RequestFilters.Add((httpReq, httpRes, requestDto) =&gt; { //Handles Request and closes Responses after emitting global HTTP Headers if (httpReq.HttpMethod == "OPTIONS") httpRes.EndRequest(); //add a 'using ServiceStack;' }); </code></pre> <p>I am able to call my api via REST Console (chrome addin) but when I call with a ajax request I get a 405 error.</p> <pre><code>Request URL:http://empire.thecodingpit.com/api/engine Request Method:OPTIONS Status Code:200 OK Request Headers view source Accept:*/* Accept-Encoding:gzip,deflate,sdch Accept-Language:en-US,en;q=0.8 Access-Control-Request-Headers:accept, origin, content-type Access-Control-Request-Method:POST Connection:keep-alive Host:empire.thecodingpit.com Origin:http://json.commublogs.com Referer:http://json.commublogs.com/ User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.66 Safari/537.36 Response Headers view source Cache-Control:private Content-Length:0 Date:Thu, 26 Sep 2013 17:00:59 GMT Server:Microsoft-IIS/8.0 X-AspNet-Version:4.0.30319 X-MiniProfiler-Ids: ["f8c3ddb8434149feb689dd44d93bf862","6d0e7e0f8ac1456d98872a82af4d6602","67bdf08a19c641a7b26db0b43fd10888","1819b1ce3e314c0594ef9ecb1ac68fcf","7af8595373e345f3a9f8ade60c8a7817"] X-Powered-By:ASP.NET </code></pre> <p>I do not have any [Authentication] on my methods - yet.</p> <p>I have looked at <a href="https://stackoverflow.com/questions/8211930/servicestack-rest-api-and-cors">this question</a> and have implemented it as shown above. This related question is NOT a duplicate. <a href="https://stackoverflow.com/questions/8211930/servicestack-rest-api-and-cors">servicestack REST API and CORS</a></p> <p>The service call (POST) that I am making is...</p> <pre><code>public object Post(SelectedTroops request) { return new SelectedTroopsResponse { ArrayOfSelectedTroops = request.ArrayOfSelectedTroops }; } </code></pre> <p>If I am missing anything that may be helpful please let me know. I guess an side note question may be - how do you effectively trace thru and debug something like this? Any helpful hints would be more than appreciated.</p>
 

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