问题标签 [attributerouting]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
asp.net-web-api - ASP.Net Web API 控制器中不允许使用 405 方法
我环顾四周,试图找到一些关于此的帖子,有很多但没有一个可以解决我的具体问题(我可以找到)。
在我的 Api 控制器中,还有许多其他带有“ GET ”的方法都可以正常工作,但是当我添加一个新方法时,它返回405 method not allowed消息
但是当我[System.Web.Http.HttpGet]
使用我的方法时,它就开始起作用了。
谁能解释一下我做错了什么,或者这是正确的方法。我发现几乎相同的问题MVC AttributeRouting With.. and 405 when using..但仍然感到困惑。
asp.net-mvc - 属性路由 - 在 IRouteConstraint 使用的参数中包含正斜杠?
我正在试验基于属性的路由——它看起来很棒,但我有一个问题。
我已经搜索了文档(attributerouting.net)和 SO,但我无法弄清楚如何使用自定义路由约束并传入包含正斜杠的参数。例如一个网址。
控制器上的属性:
IRoute 约束:
这很好用......除了 URL 包含正斜杠时,它会给我一个 404。
所以我在路由参数中添加了星号,如下所示:
但现在我无法访问 IRouteConstraint 类中的值。
在 CustomURLConstraint 的 Match 方法中, 的值values[parameterName]
来自于全能星 - as *url
。
路由值按预期通过action
and传递,但键为 null。没有钥匙。controller
url
*url
c# - 根据控制器命名空间名称创建自定义 MVC 路由
我有几个区域的系统。然后,我为我的控制器创建了一个文件夹结构(按照菜单结构),如下所示:
好的,到目前为止一切顺利......使用默认路由我得到了:
我想要实现的是这样的:
或(蛞蝓):
如果这种想法有效(控制器 1 命名空间),我可以使用命名空间控制器名称来创建该 slug:
我怎样才能做到这一点?也许使用类似 AttributeRouting 的东西?
谢谢
c# - Unit Testing MVC 4 routes using AttributeRouting and MvcRouteTester
So I have been researching a lot about this but I cannot find a workaround for my problem
I have a MVC4/Web API application and I'm using AttributeRouting 3.5.6
My app works fine.
I was able to unit test the Web API routes using the following response
AttributeRouting not working with HttpConfiguration object for writing Integration tests
What I want to do now is unit test my MVC4 routes but I have not found a way to do it
I found the following issue and I'm wondering if there's a workaround out there
https://github.com/mccalltd/AttributeRouting/issues/64
Basically the problem seems to be loading the routes from the attributes in memory for my unit tests
This is what I have tried so far:
When I useany of the Assembly methods the routes collection is empty
When I use any of the Controller methods I receive the following exception:
System.Security.VerificationException: Method AttributeRouting.Web.Mvc.Configuration.AddRoutesFromControllersOfType: type argument 'MyNamespace.Controllers.HomeController' violates the constraint of type parameter 'T'.
It has to be a way because when I run the application it works just fine, all my routes are registered in the RoutesCollection
c# - Mvc 5 Attribute Routing
I am trying to use the build-in attribute routing that comes with Mvc 5, previously I was using the AttributeRouting
package on Nuget.
But how do i set up routes by specifying whether it is for a Get or Post request?
In AttributeRouting
there was GET()
and POST()
attributes, but in Mvc 5 there is only a Route()
Attribute?
c# - 在 ASP.Net Web API 中解析属性路由 URL
我正在尝试获取 ActionFilterAttribute 上特定属性路由 URL 的参数。例如,我有如下操作:
在动作过滤器属性中,绝对网址类似于“ http://test.example.com/v1/test/1/123-asda-231-asd ”。但是我想在集合中将这些参数解析为 userId=1 和 udid=... 。
可能吗?
asp.net-mvc-5 - 将属性路由限制为特定的 HTTP 动词
使用 AttributeRouting 库,我可以将路由限制为特定动词:
在 MVC 5 中内置了 AttributeRouting,但没有采用 HttpVerbs 的重载。在这种情况下,如何将路由限制为 POST?
asp.net-mvc-5 - 具有属性路由的路由优先级
在较旧的 MVC 版本中,使用 AttributeRouting 库,我可以有多个路由并指定优先级,因此在生成 URL 时选择最合适的路由:
在 MVC 5 中,ActionPrecedence
属性上没有属性。在这种情况下如何指定路由优先级?
c# - Creating BaseController for ASP.NET MVC
I have a ASP.NET MVC 4 project, which have main page, where visitor should choose subtopic. So structure is:
I'm using AttributeRouting.net nuget package to deal with routing to subdomains. So each controller located in separate area and have following data annotation (SEOController in this case):
I'm implemented repository to decrease amount of duplicated code, but still need to have controller with CRUD actions for each subdomain. All of them using single table wich have separate field called subdomain and I'm passing subdomain name statically in each controller.
I'm looking how to create base controller class with CRUD functionality anв possibility to extend it in derived classes, as each subdomain will have each own actions/views as well. AFAIK I can specify location of View or SharedView to have single view which used by multiple controllers (single Index/Details/Edit View) and pass page title and other tags in ViewBag to avoid maintaining same code for different subdomains, but I'll be much appreciated if someone will suggest better approach.
asp.net-web-api - 在 Web API 2 中使用属性路由时限制自动帮助页面内容
我目前正在使用 Web API 2 的属性路由(http://www.asp.net/web-api/overview/web-api-routing-and-actions/attribute-routing-in-web-api实现一个 Web API -2 )。我还使用帮助页面模块从 XML 注释自动生成文档(http://www.asp.net/web-api/overview/creating-web-apis/creating-api-help-pages)。
对于这个 API,我提供了对可选返回格式扩展的支持,因此每个 API 方法都定义了一对路由,如下所示:
这允许用户点击其中任何一个并获得结果:
我的问题是,当帮助页面使用 MapHttpAttributeRoutes() 生成文档时,它会为每种方法选择两条路线。所以现在我看到了以下帮助:
但我只想看到:
我更愿意在每个方法上隐藏非扩展路由,以便每个方法只显示一个帮助页面条目。
有没有其他人尝试过类似的东西?有没有我想念的解决方法?