最近在做一个Asp.net的项目,因为原来一直是用java来开发应用程序,改到Asp.net后,按照Java下的web开发思路,使用到json文件,发现以往很顺利的开发,在Asp.net中是相当的不顺利,原因是微软的.net平台默认的安全性,不允许直接访问本地的json文件,需要在web.config中进行配置之后方可以访问。
<?xml version="1.0" encoding="utf-8"?>
<!--
有关如何配置 ASP.NET 应用程序的详细信息,请访问
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
<globalization requestEncoding="utf-8" responseEncoding="utf-8" culture="zh-CN" uiCulture="zh-CN" fileEncoding="utf-8"/>
</system.web>
<!--配置 ASP.NET 可访问本地JSON详细配置-->
<system.webServer>
<security>
<requestFiltering>
<fileExtensions>
<add fileExtension=".json" allowed="true"/>
</fileExtensions>
</requestFiltering>
</security>
<staticContent>
<mimeMap fileExtension=".json" mimeType="text/json"/>
</staticContent>
</system.webServer>
<system.web.extensions>
<!--配置 JSON 序列化-->
<scripting>
<webServices>
<jsonSerialization maxJsonLength="5000"/>
</webServices>
</scripting>
</system.web.extensions>
</configuration>
在项目开发的时候,发现本地JSON文件只能通过GET的方式进行访问,所以在访问时候,需要配置GET方式。
- Ajax中配置TYPE=“GET”
- 表单中配置METHOD="GET"
因为项目中使用的是JQuery EasyUI,发现默认JQuery Datagrid默认使用的是POST方式,通过配置属性method="get"来解决此方案。