如何将上传到服务器的文件(不带.json扩展名)设置为内容类型“ application / json”;使用.NET框架 [英] How to set file uploaded to server without .json extension to content type "application/json" using .NET framework
问题描述
我一直在尝试在iOS9上为我们的iOS应用设置深度链接。
第一步涉及创建一个我已经做过的JSON文件,然后将其上传到服务器。
我的问题是我已将json文件上传到以下位置的服务器: https://www.example.com/apple-app-site-association ,但是当我在浏览器中检查此URL时,它返回404 File not found错误响应。我应该能够像在Google上一样看到它: https://www.google.com / apple-app-site-association
I've been trying to set up deeplinking for our iOS app on iOS9. The first step involves creating a JSON file which I have already done so and then upload it to server. The problem I have is I've uploaded the json file to server at location: https://www.example.com/apple-app-site-association but when I check this URL on browser it is returning 404 File not found error response. I should be able to see it just like on Google's: https://www.google.com/apple-app-site-association
在Apple Developer文档中,它说我必须确保不要保存扩展名为.json的文件所以这就是为什么不包括.json扩展名的原因。
On the Apple Developer docs it says I have to make sure I don't save the file with extension .json so that's why .json extension is not included.
在文档上说必须将文件设置为MIME类型application / json。
而且我认为这一定是问题所在,因为我还没有这样做。
On the docs it says you have to set the file to MIME type application/json. And I believe this must be the issue as I have not done so.
我的问题是如何设置文件的MIME类型?
我知道必须在服务器端某个地方进行设置,如果有帮助,我们将.NET框架用于我们的Web应用程序和服务器端代码。
将此文件设置为MIME类型 application / json的编程代码是什么,应将此代码放置在哪个文件上?
My question is how do I set the MIME type of the file? I know this has to be set up somewhere server side and if it helps we are using the .NET framework for our web-app and server side code. What is the programming code for setting this file to MIME type "application/json" and on which file should this code be placed inside?
将感谢任何人
推荐答案
您将需要将apple-app-site-association端点映射到根目录下的json文件。网站。我是通过在.webconfig中使用url重写来实现的。
You will need to map the apple-app-site-association endpoint to the json file in the root of the website. I achieved this by using a url rewrite in my .webconfig
如果IIS中没有url重写模块,则可以在此处下载:
< a href = http://www.iis.net/downloads/microsoft/url-rewrite rel = nofollow> http://www.iis.net/downloads/microsoft/url-rewrite
If you don't have the url rewrite module in IIS you can download it here: http://www.iis.net/downloads/microsoft/url-rewrite
这是我当前的网络配置:
This is my current webconfig:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="apple_json_file">
<match url="^apple-app-site-association" />
<action type="Rewrite" url="apple-app-site-association.json" />
</rule>
</rules>
</rewrite>
<staticContent>
<mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>
</system.webServer>
</configuration>
根据服务器是否已识别.json扩展名,关于服务哑剧类型的最后一部分可能是不必要的
The final part which regards serving mime types maybe unnecessary depending on whether your server already recognizes the .json extension.
这篇关于如何将上传到服务器的文件(不带.json扩展名)设置为内容类型“ application / json”;使用.NET框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!