自定义路由是在RouteConfig类的RegisterRoutes方法中使用routes.add定义的。
routes.Add("Default", new ABCRoute("{*url}",
new
{
languageCulture = "en",
pos = "uk",
area = defArea,
我想为我的asp.net mvc应用程序定制URL。目前我正在开发asp.net MVC4.5
案例:1
Current URL : localhost/Country/Index/param1
Expected URL : localhost/param1
案例:2
Current URL : (1) localhost/Country/Index/param1 (Param1 is name of country)
(2) localhost/State/Index/param11 (param11 is name of state)
Expected
我在使用带有get参数的Zend url helper时遇到了一些问题。在一个视图中,我有分页,它在get中发送额外的参数(所以在url中),所以这是可以的。但这并不好,因为参数总是留在url中,即使我改变了页面。事实上,zend url helper -我用来生成链接或表单的操作的url -自动添加参数到url的末尾,所以无论我点击哪个链接,我都有这个参数……
//In my controller
$this->_view->url(array("action"=>"action-name");
// generate for example
给定此URL的
http://localhost:51095/Person // This is equivalent to this one Person/Index
http://localhost:51095/Person/Allan
我为它设置了一个路由配置,如下所示:
routes.MapRoute(
"Person",
"Person/{personName}",
new { controller = "Person", action = "Person", personName = Url
我已经将我的ASP.NET MVC5应用程序配置为为WebApi使用AttributeRouting:
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
config.MapHttpAttributeRoutes();
}
}
我有ApiController,如下所示:
[RoutePrefix("api/v1/subjects")]
public class SubjectsController : Api
我目前正在为应用程序编写一个新闻文章方面,并将新的路由(针对新文章)添加到我的RouteTable中,这看起来很好,但是这些路由是不可到达的?
我使用的代码如下:
var routes = RouteTable.Routes;
using (routes.GetWriteLock())
{
var url = contentHelper.GetPageUrl(page);
routes.MapRoute(page.Id.ToString(), url, new { controller = "Cms", action = "Index", id