大佬教程收集整理的这篇文章主要介绍了asp.net-web-api – WebAPI:403在发布网站后被禁止,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
错误代码:403禁止.服务器拒绝指定的统一资源定位符(URL).联系服务器管理员. (12202)
[RoutePrefix("api/v1/project")] public class ProjectController : BaseApiController { [httpGet] public httpResponsemessage GetProjects() { httpResponsemessage resp = new httpResponsemessage(httpStatusCode.oK); if(User.Identity.IsAuthenticated) { var model = new ModelFactory().CreateProjects(); resp = request.CreateResponse(httpStatusCode.oK,model); } return resp; } }
public static class WebApiConfig { public static void Register(httpConfiguration config) { // all actions under /project routes require authentication config.Routes.MaphttpRoute( name: "ProjectApi",routeTemplate: "api/v1/{Controller}/{action}/{apikey}",defaults: new { apikey = RouteParameter.optional },consTraints: new { controller = "project" },handler: new BasicAuthHandler(config)); // all routes requires an api key config.messageHandlers.Add(new ApiKeyHandler()); config.MaphttpAttributeRoutes(); } }
我已经从网上尝试了几个“解决方案”,但似乎没有一个解决这个问题.我添加了:
// Stop IIS/Asp.Net breaking our routes RouteTable.Routes.RouteExisTingFiles = true;
来自:http://www.grumpydev.com/2013/09/17/403-14-error-when-trying-to-access-a-webapi-route/
并确保:
<modules runAllManagedModulesForAllrequests="true">
拥有上面的代码,使用以下链接提供了一个成功的连接,它检查(按正确的顺序)APIkey(ApiKeyHandler),检查用户是否需要登录(BasicAuthHandler)然后转到控制器中的方法({Controller }/{行动}).
// THIS WORKS! http://localhost:51077/api/v1/project/getprojects?apikey=123456
然后我们做一个发布并尝试相同的事情
// This is haunted with number 403 http://website.com/api/v1/project/getprojects?apikey=123456
给出错误代码:403 Forbidden.
我很无能为力.我甚至尝试将“NETWORK serviCE”的整个发布文件夹的安全设置更改为完全访问权限..没有变化.
如果您需要更多英特尔,请告诉我.
以上是大佬教程为你收集整理的asp.net-web-api – WebAPI:403在发布网站后被禁止全部内容,希望文章能够帮你解决asp.net-web-api – WebAPI:403在发布网站后被禁止所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。