大佬教程收集整理的这篇文章主要介绍了angularJs – 405方法不允许在WebAPI2(OWIN),大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
webAPI和Angular位于不同的站点上。
在Startup.cs我有:
public void Configuration(IAppBuilder app) { ConfigureOAuth(app); var config = new httpConfiguration(); WebApiConfig.Register(config); app.UseCors(Microsoft.owin.Cors.CorsOptions.AllowAll); app.UseWebApi(config); } private void ConfigureOAuth(IAppBuilder app) { var oAuthServerOptions = new OAuthAuthorizationServerOptions { AllowInsecurehttp = true,TokenEndpointPath = new PathString(Paths.TokenPath),AccessTokenExpireTimeSpan = TimeSpan.Fromminutes(30),Provider = Kernel.Get<IOAuthAuthorizationServerProvider>() }; app.USEOAuthAuthorizationServer(oAuthServerOptions); OAuthBearerOptions = new OAuthBearerAuthenticationOptions(); app.USEOAuthBearerAuthentication(OAuthBearerOptions); }
然后在控制器上,我的方法设置为允许匿名:
[AllowAnonymous] public bool PostRegister(UserSignupForm form) { ... }
我也更新了web.config:
<system.webServer> <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> </system.webServer>
saveRegistration: function (registration) { return $http.post(baseUrl + '/api/signup/register',registration).then(function (responsE) { return response; }); }
当使用Postman进行调用时,我得到了一个成功的响应,但是当从Angular进行相同的调用时,我得到了405错误。
BitOfTech示例站点正在发送相同的请求标头,但能够获取Access-Control-Allow-XXX标头
我已经更新了我的代码以跟随Token Based Authentication using ASP.NET Web API 2,Owin,and Identity
[AllowAnonymous] [Route("Register")] [AcceptVerbs("OPTIONS")] public async Task<IhttpActionResult> Register() { return Ok(); }
以上是大佬教程为你收集整理的angularJs – 405方法不允许在WebAPI2(OWIN)全部内容,希望文章能够帮你解决angularJs – 405方法不允许在WebAPI2(OWIN)所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。