- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我刚刚一直在研究一种新的 Controller 操作方法,我有点困惑为什么会看到 405。
我已经在我的 API 上定义了几个 GET 属性方法,它们都按预期运行。例如,这很好用:
[GET("entries/{page}"), JsonExceptionFilter]
public HttpResponseMessage GetEntries(int page)
然而我的新方法是这样定义的:
[GET("search/{searchTerm}/{page}"), JsonExceptionFilter]
public HttpResponseMessage Search(string searchTerm, int page)
正在返回 405
如果我访问 API 上的 routes.axd url,我可以在表中看到这样的条目:
GET, HEAD, OPTIONS users/search/{searchTerm}/{page}
这一切看起来都是正确的。在客户端,我使用 HttpClient 对两个请求使用相同的方法:
var response = httpClient.GetAsync(ApiRootUrl + "users/search/" + searchTerm + "/" + page).Result;
从 Fiddler 运行 get 也会返回 405。
即使查看响应中的 RequestMessage 看起来也是正确的:
"{Method: GET, RequestUri: 'http://localhost:51258/users/search/jam/0'"
完全被这个难住了。
我还能尝试什么来阐明问题所在?
最佳答案
您需要使用一个名为 System.Web.Http.HttpGetAttribute
的属性来修饰 Search 操作。对于这背后的原因,您可以在下面的帖子中查看我的回答:
405 when using AttributeRouting.PUTAttribute unless I also include HttpPutAttribute
关于asp.net-mvc - 使用 GET 的 MVC AttributeRouting - 返回 405 - 方法不允许,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17235826/
我想使用 AttributeRouting使用 Orchard CMS。为此,我需要实现 IRouteProvider使用返回 Orchard 列表的方法 RouteDescriptor s。 我需要
我正在尝试做全属性路由,没有常规路由,并试图根据当前域告诉我的路由它们属于哪个区域。 在约定路由中,我可以以此为例指定我的对象约束: context.MapRoute( "MyRouteNam
所以我有一个项目使用默认的Route routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}",
我正在处理我的第一个 MVC 项目并在我的 Controller 中使用属性路由。我的一项操作有一个小问题,它有两个可能的路线路径。路线本身正在工作,但正在生成的 actionLinks 不符合我的喜
我有两个 Controller ,ItemsController 和 SingleItemController,它们都继承自 ApiController。两者都在 Controller 上定义了 Ro
我刚刚在我的 WebAPI 项目上更新了(从 v3.x)到最新版本的 AttributeRouting,它刚刚开始产生我以前从未见过的错误。 现在,每当调用 API 时,我都会收到如下错误: Syst
我们正在使用 Areas 对用 ASP.NET MVC3 编写的 API 进行版本控制,并使用 AttributeRouting 来定义我们的路由。 现在我们有一个“v1”区域,这是我们的第一个 AP
我正在按照此处概述的想法创建一些集成测试: http://www.strathweb.com/2012/06/asp-net-web-api-integration-testing-with-in-m
我正在尝试在 asp.net webapi 上使用 CustomHttpControlSelector 和 AttributeRouting 来实现 api 版本控制。 我想要做的是通过它的命名空间来
我在获取我的 WebAPI 接受的日期范围查询时遇到了一些问题。据我所知,从我读过的所有内容来看,这应该是可行的,但我仍然收到 400 Bad Request 响应。 我的 API 路由如下所示:
我刚刚开始使用 AttributeRouting使用我的 ASP.NET MVC3 应用程序。我一开始根本没有 Controller 。 (新的空 MVC3 应用程序) 然后我做了一个区域。 (称为:
当使用 AttributeRouting 而不是 WebAPI 使用的默认 RouteConfiguration 时,如何设置要使用的默认 Controller 。即摆脱注释代码部分,因为在使用 At
我最近开始为我的操作方法使用属性路由,并且正在努力从 RouteData 获取操作名称(和/或 ID)。下面是我如何使用 attrubues 的示例: [Route( "Edit/{id:int}"
所以我一直在研究这个问题,但我找不到解决我的问题的方法 我有一个 MVC4/Web API 应用程序,我正在使用 AttributeRouting 3.5.6 我的应用运行良好。 我能够使用以下响应对
长话短说 我需要一种方法来在我的 MVC 应用程序中根据用户的属性生成 URL 时以编程方式选择选择哪个 RoutePrefix 不是 TL;DR 我有一个 MVC 4 应用程序(带有 Attribu
我们有一个 MVC 项目,我正在尝试更新该项目以包含 WebApi。为了获得所需的路由,我们使用了 AttributeRouting。除了返回 405 的 [PUT] 之外,所有调用似乎都正确路由。我
我刚刚一直在研究一种新的 Controller 操作方法,我有点困惑为什么会看到 405。 我已经在我的 API 上定义了几个 GET 属性方法,它们都按预期运行。例如,这很好用: [GET(
我有以下代码 [HttpGet] [Route("publish/{id}")] public IHttpActionResult B(string id, string publishid=null
我想根据 Accept header 中请求的媒体类型选择我的 Controller 的操作。 例如,我有一个名为主题的资源。其指定路线为: GET /subjects/{subjectId:int}
我已经通读了建议here和 here但一直无法让它发挥作用。我是 WebApi 的新手,它可以为 GET 工作,但无法执行 PUT。 我应该首先注意,我还没有在 IIS 中托管 thw api,只是直
我是一名优秀的程序员,十分优秀!