webapi权限常见错误
Posted 逻辑思维-质变
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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" />-->
解决方案:
跨域造成的,解决跨域即可:
<httpProtocol>
<customHeaders>
<!-- Enable Cross Domain AJAX calls -->
<add name="Access-Control-Allow-Origin" value="http://localhost:2062" />
<add name="Access-Control-Allow-Methods" value="GET,POST,PUT,DELETE,OPTIONS"/>
<add name="Access-Control-Allow-Headers" value="Content-Type,Authorization"/>
</customHeaders>
</httpProtocol>
错误三:
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/
以上是关于webapi权限常见错误的主要内容,如果未能解决你的问题,请参考以下文章