请求的资源不支持http方法'OPTIONS' [英] The requested resource does not support http method 'OPTIONS'
问题描述
大家好,
当我通过POSTMAN发送请求时,它工作正常,但当我发送请求时,我的Web应用程序(用于POST,DELETE和PUT,PATCH)动词),系统给我错误 请求的资源不支持
< g class =" gr_ gr_189 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace"数据-GR-ID =" 189" id =" 189"> http < / g> 方法'选项'
我花费数小时根据我删除的一些网站并添加属性到web配置,但我没有得到任何正确的答案。在此我添加了配置文件。我做错了吗?< g class =" gr_ gr_611 gr-alert gr_gramm gr_inline_cards gr_run_anim
Punctuation multiReplace"数据-GR-ID =" 611" id =" 611"> thing。< / g>
我正在使用WEB API 2
< ?xml version =" 1.0"编码= QUOT; UTF-8英寸;?>
<结构>
&NBSP; <&的System.Web GT;
&NBSP; &NBSP; < compilation debug =" true" targetFramework = QUOT; 4.6.2" />
&NBSP; &NBSP; < httpRuntime targetFramework =" 4.6.2" />
&NBSP; &NBSP; <&的HttpModules GT;
&NBSP; &NBSP; &NBSP; < add name =" ApplicationInsightsWebTracking" type =" Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule,Microsoft.AI.Web" />
&NBSP; &NBSP; < /&的HttpModules GT;
&NBSP; < /system.web>
&NBSP; < system.webServer>
&NBSP; &NBSP; < directoryBrowse enabled =" false" />
&NBSP;
< httpProtocol>
&NBSP; &NBSP; < customHeaders>
&NBSP; &NBSP; &NBSP; &NBSP; < add name =" Access-Control-Allow-Origin"值= QUOT * QUOT; />
&NBSP; &NBSP; &NBSP; &NBSP; < add name =" Access-Control-Allow-Methods"值= QUOT; GET,POST,PUT,PATCH,DELETE,方式]; />
&NBSP; &NBSP; &NBSP; &NBSP; < add name =" Access-Control-Allow-Headers"值= QUOT;产地,X-请求-随着,X-原型的版本,内容类型,同意] />
&NBSP; &NBSP; &NBSP; < / customHeaders>
&NBSP; &NBSP; < / httpProtocol>
&NBSP; <处理>
&NBSP; &NBSP; &NBSP; < remove name =" WebDAV" />
&NBSP; &NBSP; &NBSP; < remove name =" ExtensionlessUrlHandler-Integrated-4.0" />
&NBSP; &NBSP; &NBSP; < remove name =" TRACEVerbHandler" />
&NBSP; &NBSP; &NBSP; < remove name =" OPTIONSVerbHandler" />
&NBSP; &NBSP; &NBSP; < add name =" OPTIONSVerbHandler"路径= QUOT * QUOT;动词= QUOT;方式];模块= QUOT; IsapiModule" scriptProcessor = QUOT; C:\Windows\System32\inetsrv\asp.dll" resourceType为= QUOT;未指定" requireAccess = QUOT;无" />
&NBSP; &NBSP; &NBSP; < add name =" ExtensionlessUrlHandler-Integrated-4.0"路径= QUOT * QUOT。动词= QUOT * QUOT;类型= QUOT; System.Web.Handlers.TransferRequestHandler"前提= QUOT; integratedMode,runtimeVersionv4.0" />
&NBSP; &NBSP; < / handlers>
&NBSP; < validation validateIntegratedModeConfiguration =" false" />
&NBSP; < modules runAllManagedModulesForAllRequests =" true">
&NBSP; &NBSP; < remove name =" WebDAVModule" />
&NBSP; &NBSP; &NBSP; < remove name =" ApplicationInsightsWebTracking" />
&NBSP; &NBSP; &NBSP; < add name =" ApplicationInsightsWebTracking" type =" Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule,Microsoft.AI.Web"前提= QUOT; managedHandler" />
&NBSP; &NBSP; < / modules>
< /system.webServer>
< / configuration>
< G> Gehan Fernando Snr。工程技术。 AKLO信息技术(私营)有限公司位于斯里兰卡科伦坡06,Wellawatta,5楼,第42巷。电话:+94 117 520000 |手机:+94 772 269625
我认为你已经有了解决方案,如果没有,你可以在控制器文件中包含下一个代码:
public HttpResponseMessage Options()
{
return new HttpResponseMessage {StatusCode = HttpStatusCode.OK};
}
问候。
Hi All,
When I send the request via POSTMAN it works fine, but When I send the request my web application ( for the POST, DELETE and PUT, PATCH verbs ), system gives me error The requested resource does not support <g class="gr_ gr_189 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" data-gr-id="189" id="189">http</g> method 'OPTIONS'
I spend hours and hours, according to some websites I removed and added attributes to web config, but I didn't get any proper answer. Herewith I added my config file. Am I doing any wrong <g class="gr_ gr_611 gr-alert gr_gramm gr_inline_cards gr_run_anim Punctuation multiReplace" data-gr-id="611" id="611">thing.</g>
I am using WEB API 2
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.6.2" />
<httpRuntime targetFramework="4.6.2" />
<httpModules>
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" />
</httpModules>
</system.web>
<system.webServer>
<directoryBrowse enabled="false" />
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Methods" value="GET,POST,PUT,PATCH,DELETE,OPTIONS" />
<add name="Access-Control-Allow-Headers" value="Origin,X-Requested-With,X-Prototype-Version,Content-Type,Accept" />
</customHeaders>
</httpProtocol>
<handlers>
<remove name="WebDAV" />
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="TRACEVerbHandler" />
<remove name="OPTIONSVerbHandler" />
<add name="OPTIONSVerbHandler" path="*" verb="OPTIONS" modules="IsapiModule" scriptProcessor="C:\Windows\System32\inetsrv\asp.dll" resourceType="Unspecified" requireAccess="None" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true">
<remove name="WebDAVModule" />
<remove name="ApplicationInsightsWebTracking" />
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler" />
</modules>
</system.webServer>
</configuration>
Gehan Fernando Snr. Engineer Technology. AKLO Information Technologies (Pvt) Ltd. #58, 42nd Lane, 5th Floor, Wellawatta, Colombo 06, Sri Lanka. Phone: +94 117 520000 | Mobile: +94 772 269625
解决方案Hi,
I think you have got already the solution, if not you could include next code in controller file:
public HttpResponseMessage Options() { return new HttpResponseMessage { StatusCode = HttpStatusCode.OK }; }
Regards.
这篇关于请求的资源不支持http方法'OPTIONS'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文