2016-10-05 31 views
3

我試圖使文件:Azure的網站。嗯,已知路由而無法訪問

.well-known/apple-developer-merchantid-domain-association 

通過我的天青網站訪問。我已將此添加到路由配置中:

routes.MapRoute(
    name: "ApplePay-MacOS", 
    url: ".well-known/apple-developer-merchantid-domain-association", 
    defaults: new { controller = "Home", action = "WellKnownApplePay" }); 

指向控制器操作的控制器操作,該操作將該文件導出。

現在當我在本地IIS和IIS Express上測試它時,一切正常,但當我將它上傳到azure時,它只是不接受點「。」。字符在URL中。如果我將其刪除,那麼它就會起作用,並在文件發佈到Azure後下載文件。我需要它與點一起工作,因爲這是蘋果支付我的網站所要求的。

回答

5

我能夠用不同的方法解決這個問題。我不再試圖寫路由證書,並在這裏添加一個web.config到該目錄每彼得·漢道夫的回答是:IIS: How to serve a file without extension?

<?xml version="1.0" encoding="UTF-8"?> 
<configuration> 
    <system.webServer> 
     <staticContent> 
      <mimeMap fileExtension="." mimeType="text/xml" /> 
     </staticContent> 
    </system.webServer> 
</configuration> 
+1

嘿湯姆,問題是不會提供該文件。如果我刪除了這段時間,並使URL「知名/」而不是「.well-known /」,那麼該文件就是服務器。所以問題在於,爲知名路徑增加一段時間會導致Azure不能提供該文件。並不是它缺少一個擴展。 –

+0

很高興我的回答能夠幫助!我完全繞過了路由,只是將它作爲文件保存在文件系統中。所以我想我遇到了一系列不同於你的問題。我偶然發現你的問題,同時尋找我自己的答案,併發布我承認不是你問的問題的答案;) –

+0

這適用於ASP.NET Mvc網站? –

2

我找到了答案!感謝湯姆的回答。

確實可以將mimemap添加到web配置中以解決問題。但不是把mimeType =「text/xml」,你需要使用mimeType =「application/octet-stream」來提供原始的apple-developer-merchantid-domain-association文件,而不是將其作爲文本(服務器不會想做)。

所以答案是,這個在webconfig添加到system.webserver節點:

<staticContent> 
    <mimeMap fileExtension="." mimeType="application/octet-stream" /> 
</staticContent> 
2

正如在其他的答案中提到,這個問題是IIS處理與路徑的方式。在他們中。

我寫這是註冊像這樣的IHttpHandler的解決了ASP.NET MVC這個問題:

<system.webServer> 
    <handlers> 
    <add name="ApplePayMerchantIdDomainAssociation" path=".well-known/apple-developer-merchantid-domain-association" verb="GET" type="MyNamespace.ApplePayMerchantIdDomainAssociationHandler, MyAssembly" resourceType="Unspecified" preCondition="integratedMode" /> 
    </handlers> 
</system.webServer> 

,然後將其處理類似這樣:

使用System.Globalization; using System.Web; using System.Web.Mvc;

namespace MyNamespace 
{ 
    public class ApplePayMerchantIdDomainAssociation : IHttpHandler 
    { 
     public bool IsReusable => true; 

     public void ProcessRequest(HttpContext context) 
     { 
      var wrapper = new HttpContextWrapper(context); 
      ProcessRequest(wrapper); 
     } 

     public void ProcessRequest(HttpContextBase context) 
     { 
      var type = GetType(); 
      var assembly = type.Assembly; 

      string resourceName = string.Format(
       CultureInfo.InvariantCulture, 
       "{0}.apple-developer-merchantid-domain-association", 
       type.Namespace); 

      using (var stream = assembly.GetManifestResourceStream(resourceName)) 
      { 
       if (stream == null) 
       { 
        context.Response.StatusCode = 404; 
       } 
       else 
       { 
        stream.CopyTo(context.Response.OutputStream); 

        context.Response.ContentType = "text/plain"; 
        context.Response.StatusCode = 200; 
       } 
      } 
     } 
    } 
} 

在ASP.NET核心的東西很多earier你可以只是其用作靜態內容直接從wwwroot的。