SORU
17 EYLÜL 2012, PAZARTESİ


etkinleştirme kökenli çapraz IIS7 kaynak paylaşımı

Geçenlerde başka bir etki alanı için bir Javascript istekleri gönderme ile karşılaştım. Varsayılan olarak XHR diğer etki alanlarına nakil izin verilmez.

http://enable-cors.org/ gelen talimatlara diğer etki alanında bu etkinleştirdim.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
 <system.webServer>
  <httpProtocol>
    <customHeaders>
      <add name="Access-Control-Allow-Origin" value="*" />
      <add name="Access-Control-Allow-Methods" value="GET,PUT,POST,DELETE,OPTIONS" />
      <add name="Access-Control-Allow-Headers" value="Content-Type" />
    </customHeaders>
  </httpProtocol>
 </system.webServer>
</configuration>

enter image description here

Şimdi her şey iyi çalışıyor, ancak hala çalışan 200 yanıt geri göndermeden önce 405 yanıt verir.

Request URL:http://testapi.nottherealsite.com/api/Reporting/RunReport
Request Method:OPTIONS
Status Code:405 Method Not Allowed
Request Headersview source
Accept:*/*
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-GB,en-US;q=0.8,en;q=0.6
Access-Control-Request-Headers:origin, content-type, accept
Access-Control-Request-Method:POST
Connection:keep-alive
Host:testapi.nottherealsite.com
Origin:http://test.nottherealsite.com
Referer:http://test.nottherealsite.com/Reporting
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.89 Safari/537.1
Response Headersview source
Access-Control-Allow-Headers:Content-Type
Access-Control-Allow-Methods:GET,PUT,POST,DELETE,OPTIONS
Access-Control-Allow-Origin:*
Allow:POST
Cache-Control:private
Content-Length:1565
Content-Type:text/html; charset=utf-8
Date:Tue, 18 Sep 2012 14:26:06 GMT
Server:Microsoft-IIS/7.5
X-AspNet-Version:4.0.30319
X-Powered-By:ASP.NET

Güncelleme: 3/02/2014

MSDN magazine son güncellenen bir makale var. Ayrıntılı bir İSTASYONDAN ASP.NET API 2 Web Destek.

http://msdn.microsoft.com/en-us/magazine/dn532203.aspx

CEVAP
31 Ocak 2013, PERŞEMBE


Büyük olasılıkla IIS 7 vakası 'işleme' başvurunuzu yerine HTTP SEÇENEKLERİ tepki belirtme. Bu, IIS7, . belirlemek için

  1. Sitenizin İşleyici Eşlemeleri.

  2. Kaydırma''. OPTİONSVerbHandler aşağı

  3. Değişim '''' . İsapiHandler ProtocolSupportModule

  4. Çalıştırılabilir: %windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll

Şimdi, config girişlerinizi yukarıdaki HTTP SEÇENEKLERİ bir fiil gönderildiği zaman devreye girer.

Alternatif olarak BeginRequest yöntemi HTTP SEÇENEKLER fiil cevap verebilir.

    protected void Application_BeginRequest(object sender,EventArgs e)
    {
        HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*");

        if(HttpContext.Current.Request.HttpMethod == "OPTIONS")
        {
            //These headers are handling the "pre-flight" OPTIONS call sent by the browser
            HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE");
            HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept");
            HttpContext.Current.Response.AddHeader("Access-Control-Max-Age", "1728000" );
            HttpContext.Current.Response.End();
        }

    }

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Jimmie Jones

    Jimmie Jones

    16 Kasım 2007
  • Lamborghini

    Lamborghini

    13 Aralık 2005
  • Pocketnow

    Pocketnow

    14 EKİM 2007