简体   繁体   English

允许在Visual Studio Express 2013 for Web中加载JSON文件

[英]Allow loading of JSON files in Visual Studio Express 2013 for Web

I have the problem, that the IIS from Visual Studio Express 2013 for Web doesn't allow the loading of *.json files. 我有一个问题,即Visual Studio Express 2013 for Web中的IIS不允许加载* .json文件。 When trying to load a *.json file I get a 403 Forbidden and a help page how to configure the IIS allow the loading of JSON files, but don't know what to do with this information / where the IIS is even located. 当我尝试加载* .json文件时,我得到403 Forbidden和帮助页面如何配置IIS允许加载JSON文件,但不知道如何处理这些信息/ IIS所在的位置。

This is the error page: 这是错误页面:

HTTP Error 404.3 - Not Found The page you are requesting cannot be served because of the extension configuration. HTTP错误404.3 - 未找到由于扩展配置,无法提供您请求的页面。 If the page is a script, add a handler. 如果页面是脚本,请添加处理程序。 If the file should be downloaded, add a MIME map. 如果要下载文件,请添加MIME映射。

Most likely causes: It is possible that a handler mapping is missing. 最有可能的原因:可能缺少处理程序映射。 By default, the static file handler processes all content. 默认情况下,静态文件处理程序处理所有内容。 The feature you are trying to use may not be installed. 您尝试使用的功能可能未安装。 The appropriate MIME map is not enabled for the Web site or application. 未为网站或应用程序启用适当的MIME映射。 (Warning: Do not create a MIME map for content that users should not download, such as .ASPX pages or .config files.) If ASP.NET is not installed. (警告:不要为用户不应下载的内容创建MIME映射,例如.ASPX页面或.config文件。)如果未安装ASP.NET。

Things you can try: In system.webServer/handlers: Ensure that the expected handler for the current page is mapped. 您可以尝试的事情:在system.webServer / handlers中:确保映射当前页面的预期处理程序。 Pay extra attention to preconditions (for example, runtimeVersion, pipelineMode, bitness) and compare them to the settings for your application pool. 特别注意前提条件(例如,runtimeVersion,pipelineMode,bitness)并将它们与应用程序池的设置进行比较。 Pay extra attention to typographical errors in the expected handler line. 在预期的处理程序行中要特别注意打字错误。 Please verify that the feature you are trying to use is installed. 请确认已安装您尝试使用的功能。 Verify that the MIME map is enabled or add the MIME map for the Web site using the command-line tool appcmd.exe. 验证是否已启用MIME映射,或使用命令行工具appcmd.exe添加网站的MIME映射。 To set a MIME type, run the following command in the IIS Express install directory: appcmd set config /section:staticContent /+[fileExtension='string',mimeType='string'] The variable fileExtension string is the file name extension and the variable mimeType string is the file type description. 要设置MIME类型,请在IIS Express安装目录中运行以下命令:appcmd set config / section:staticContent / + [fileExtension ='string',mimeType ='string']变量fileExtension string是文件扩展名和变量mimeType字符串是文件类型描述。 For example, to add a MIME map for a file which has the extension ".xyz": appcmd set config /section:staticContent /+[fileExtension='.xyz',mimeType='text/plain'] Warning: Ensure that this MIME mapping is needed for your Web server before adding it to the list. 例如,要为扩展名为“.xyz”的文件添加MIME映射:appcmd set config / section:staticContent /+[fileExtension='.xyz',mimeType='text/plain']警告:确保这一点在将Web服务器添加到列表之前,需要进行MIME映射。 Configuration files such as .CONFIG or dynamic scripting pages such as .ASP or .ASPX, should not be downloaded directly and should always be processed through a handler. 配置文件(如.CONFIG)或动态脚本页(如.ASP或.ASPX)不应直接下载,而应始终通过处理程序进行处理。 Other files such as database files or those used to store configuration, like .XML or .MDF, are sometimes used to store configuration information. 其他文件(如数据库文件或用于存储配置的文件,如.XML或.MDF)有时用于存储配置信息。 Determine if clients can download these file types before enabling them. 确定客户端是否可以在启用它们之前下载这些文件类型。 Install ASP.NET. 安装ASP.NET。 Check the failed request tracing logs for additional information about this error. 检查失败的请求跟踪日志,以获取有关此错误的其他信息。 For more information, click here. 欲了解更多信息,请点击此处。

Detailed Error Information: Module StaticFileModule Notification 详细错误信息:模块StaticFileModule通知
ExecuteRequestHandler Handler StaticFile Error Code 0x80070032 Requested URL http: //localhost:64107/Settings/Settings.json Physical Path D:\\GIT\\RepoP_Paneon\\Settings\\Settings.json Logon Method Anonymous Logon User Anonymous Request Tracing Directory ExecuteRequestHandler处理程序StaticFile错误代码0x80070032请求的URL http://localhost:64107/Settings/Settings.json物理路径D:\\ GIT \\ RepoP_Paneon \\ Settings \\ Settings.json登录方法匿名登录用户匿名请求跟踪目录
C:\\Users\\stefank\\Documents\\IISExpress\\TraceLogFiles\\REPOP_PANEON C:\\ Users \\用户stefank \\文档\\ IISExpress \\ TraceLogFiles \\ REPOP_PANEON

More Information: This error occurs when the file extension of the requested URL is for a MIME type that is not configured on the server. 更多信息:当请求的URL的文件扩展名是针对未在服务器上配置的MIME类型时,会发生此错误。 You can add a MIME type for the file extension for files that are not dynamic scripting pages, database, or configuration files. 您可以为不是动态脚本页面,数据库或配置文件的文件添加文件扩展名的MIME类型。 Process those file types using a handler. 使用处理程序处理这些文件类型。 You should not allows direct downloads of dynamic scripting pages, database or configuration files. 您不应该允许直接下载动态脚本页面,数据库或配置文件。 View more information » 查看更多信息»

After some more googling, and experimenting I found out, that you have to define IIS settings in the Web.config . 经过一些谷歌搜索和实验后我发现,你必须在Web.config定义IIS设置。

After adding the following configuration: 添加以下配置后:

  <system.webServer>
    <staticContent>
      <mimeMap fileExtension=".json" mimeType="application/json" />
    </staticContent>
  </system.webServer>

it works like a charm. 它就像一个魅力。

Full setup file example: 完整安装文件示例:

<?xml version="1.0"?>
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0"/>
  </system.web>
  <system.webServer>
    <staticContent>
      <mimeMap fileExtension=".json" mimeType="application/json" />
    </staticContent>
  </system.webServer>
</configuration>

Better add remove tag in case future IIS has build in json support. 最好添加删除标记,以防将来IIS在json支持中构建。 This is my web.config section of mimeMap. 这是mimeMap的web.config部分。

<system.webServer>
  <staticContent>
      <remove fileExtension=".woff" />
      <remove fileExtension=".woff2" />
      <remove fileExtension=".json" />
      <mimeMap fileExtension=".woff" mimeType="application/x-font-woff" />
      <mimeMap fileExtension=".woff2" mimeType="application/font-woff2" />
      <mimeMap fileExtension=".json" mimeType="application/json" />
  </staticContent>
<system.webServer>

We may need to distinguish the Visual Studio development environment (with IIS Express) from local IIS and a remote server (like Azure WebSites). 我们可能需要将Visual Studio开发环境(使用IIS Express)与本地IIS和远程服务器(如Azure WebSites)区分开来。 To specifically target IIS Express, for example, we edit %USERPROFILE%\\Documents\\IISExpress\\config\\applicationhost.config under system.webServer/staticContent : 例如,要专门针对IIS Express,我们在system.webServer/staticContent下编辑%USERPROFILE%\\Documents\\IISExpress\\config\\applicationhost.config

<mimeMap fileExtension=".json" mimeType="application/javascript" />

I need to make this distinction because my local (intranet) IIS already has the JSON mime type defined. 我需要进行区分,因为我的本地(Intranet)IIS已经定义了JSON mime类型。 So when I deploy to Azure websites I use this transformation in Web.Release.config : 因此,当我部署到Azure网站时,我在Web.Release.config使用此转换:

<system.webServer>
    <staticContent>
        <mimeMap fileExtension=".json" mimeType="application/javascript" xdt:Transform="Insert" />
    </staticContent>
</system.webServer>
  • Open CMD with administrator privilages. 使用管理员权限打开CMD。
  • Go to: 去:

    cd C:\\Program Files\\IIS Express or cd C:\\Program Files\\IIS Express
    cd C:\\Program Files (x86)\\IIS Express

  • Run command: 运行命令:

    appcmd set config /section:staticContent /+[fileExtension='JSON',mimeType='application/x-javascript']

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM