1个回答
2017-12-02 · 百度知道合伙人官方认证企业
育知同创教育
1【专注:Python+人工智能|Java大数据|HTML5培训】 2【免费提供名师直播课堂、公开课及视频教程】 3【地址:北京市昌平区三旗百汇物美大卖场2层,微信公众号:yuzhitc】
向TA提问
关注
展开全部
修改引用到webapi的Dll文件对应的项目的web.config
选择生成读写方法webapi会生成四个读写的方法(CRUD),两个获取数据的、一个更新、一个删除,默认情况下更新和删除是不对外开外的,原因是安全问题,试想一下,可以删除数据,小A用户一次请求服务器所有的数据被删除了。但是可以通过简单的配置接收更新删除的请求,如下所示:
<system.webServer> <!--以下配置为了让IIS7+支持Put/Delete方法--> <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> <!--IIS7/7.5上必须加这个配置,否则访问报错--> <modules runAllManagedModulesForAllRequests="true"> <remove name="WebDAVModule" /> </modules> <validation validateIntegratedModeConfiguration="false" /> <handlers> <remove name="WebDAV" /> <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" /> <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" /> <remove name="ExtensionlessUrlHandler-Integrated-4.0" /> <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" resourceType="Unspecified" requireAccess="Script" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" /> <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" resourceType="Unspecified" requireAccess="Script" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" /> <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" resourceType="Unspecified" requireAccess="Script" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" /> </handlers>
<!--提高GET URL长度限制上限--> <security> <requestFiltering> <requestLimits maxUrl="409600" maxQueryString="204800" /> </requestFiltering> </security>
</system.webServer>
选择生成读写方法webapi会生成四个读写的方法(CRUD),两个获取数据的、一个更新、一个删除,默认情况下更新和删除是不对外开外的,原因是安全问题,试想一下,可以删除数据,小A用户一次请求服务器所有的数据被删除了。但是可以通过简单的配置接收更新删除的请求,如下所示:
<system.webServer> <!--以下配置为了让IIS7+支持Put/Delete方法--> <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> <!--IIS7/7.5上必须加这个配置,否则访问报错--> <modules runAllManagedModulesForAllRequests="true"> <remove name="WebDAVModule" /> </modules> <validation validateIntegratedModeConfiguration="false" /> <handlers> <remove name="WebDAV" /> <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" /> <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" /> <remove name="ExtensionlessUrlHandler-Integrated-4.0" /> <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" resourceType="Unspecified" requireAccess="Script" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" /> <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" resourceType="Unspecified" requireAccess="Script" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" /> <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" resourceType="Unspecified" requireAccess="Script" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" /> </handlers>
<!--提高GET URL长度限制上限--> <security> <requestFiltering> <requestLimits maxUrl="409600" maxQueryString="204800" /> </requestFiltering> </security>
</system.webServer>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询