Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are a couple of things you need to do:</p> <p>Set up your WebApi to support CORS (Cross Origin Resource Sharing). You can do this easily by installing the Cors Nuget package from Microsoft:</p> <pre><code>Install-Package Microsoft.AspNet.WebApi.Cors </code></pre> <p>Then you need to enable cors early in the application lifetime, for example in the Application_Start section of global.asax:</p> <pre><code>GlobalConfiguration.Configuration.EnableCors(); </code></pre> <p>See this link for more details: <a href="http://www.asp.net/web-api/overview/security/enabling-cross-origin-requests-in-web-api" rel="nofollow">http://www.asp.net/web-api/overview/security/enabling-cross-origin-requests-in-web-api</a></p> <p>I see that you are concerned about security. Good. Then you may need to do two more thing to get your CORS to play nicely. </p> <p>First, you should really look into creating a custom Cors policy provider (see the link above). Since you are hosting your WebApi in Azure, make it easy to configure the allowed origins. This should be a whitelist of only the websites you want to allow on your webapi.</p> <p>Second, I assume that your user is authenticated on the website. I also assume that the way you call the WebApi is via jQuery or some other provider that uses jQuery as a transport (such as BreezeJS). To pass on the authentication details to your WebApi, jQuery needs to know that it should do that. The easiest way to do this is to set a global setting on your website:</p> <pre><code>$.ajaxSetup({ crossDomain: true, xhrFields: { withCredentials: true } }); </code></pre> <p>A good tip for knowing exactly what goes wrong (because from experience, something will), is to use Chrome to test. Then you can open this link and see all the details of what is happening on the wire: chrome://net-internals/#events</p> <p>Happy coding! :)</p>
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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