webapi权限常见错误
webapi权限常见错误
错误一:
Response for preflight has invalid HTTP status code 405.
解决方案:
屏蔽配置文件中的如下代码
<!--<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>-->
错误二:
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:2062' is therefore not allowed access. The response had HTTP status code 500.
<!--<add name="access-control-allow-headers" value="accept,origin,token,content-type,Authorization" />-->
解决方案:
跨域造成的,解决跨域即可:
<system.webServer>
<httpProtocol>
<customHeaders>
<!-- Enable Cross Domain AJAX calls -->
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Methods" value="GET,POST,PUT,DELETE,OPTIONS" />
<add name="Access-Control-Allow-Headers" value="Content-Type,Authorization" />
</customHeaders>
</httpProtocol>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
错误三:
The 'Access-Control-Allow-Origin' header has a value 'http://localhost:2062/' that is not equal to the supplied origin. Origin 'http://localhost:2062' is therefore not allowed access.
解决方案:
由于手误造成的,域名后面不能有任何字符或符合
正确:'http://localhost:2062
错误:'http://localhost:2062/
错误四:
404 Not Found
解决方案:
增加两个modules任意一个都可以解决404,但如果验证权限会出现405错误;
<modules>
<remove name="UrlRoutingModule-4.0"/>
<add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition=""/>
</modules>
<modules runAllManagedModulesForAllRequests="true">
<remove name="WebDAVModule" />
</modules>
错误五:
Failed to load http://192.168.31.110:8014/api/Login/CheckLogin: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://192.168.31.110:8013' is therefore not allowed access.
解决方案:
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Content-Type,x-xsrf-token,X-Requested-With" />
<add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE, OPTIONS" />
</customHeaders>
</httpProtocol>
错误六:
The requested resource does not support http method 'OPTIONS
解决方案:
错误七:
<!--IIS7/7.5上必须加这个配置,否则访问报错-->
23 <modules runAllManagedModulesForAllRequests="true">
24 <remove name="WebDAVModule" />
25 </modules>
26 <validation validateIntegratedModeConfiguration="false" />
27 <handlers>
28 <remove name="WebDAV" />
29 <remove name="WebAPI_64bit" />
30 <remove name="WebAPI_32bit" />
31 <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
32 <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
33 <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
34 <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" />
35 <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" />
36 <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" />
37 <add name="WebAPI_64bit" path="*" verb="*" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="None" preCondition="classicMode,runtimeVersionv4.0,bitness64" />
38 <add name="WebAPI_32bit" path="*" verb="*" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="None" preCondition="classicMode,runtimeVersionv4.0,bitness32" />
39 </handlers>
-----
错误八:
<remove name="OPTIONSVerbHandler" />
这个是罪魁祸首,移除即可
HTTP Error 403.14 - Forbidden
Web 服务器被配置为不列出此目录的内容。
解决方案:
jQuery.support.cors = true;//设定支持跨域
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
2016-08-02 javascript js自执行函数