ASP.NET MVC路由配置详解

ASP.NET Core MVC中区域路由的配置与调试 在ASP.NET Core MVC应用程序中,区域(Areas)是一个非常有用的特性,可以帮助我们将大型应用分割成更小的模块化单元。ASP.NET Core的区域路由配置虽然看似简单,但需要注意细节和项目结构的准确性。通过这些实践经验,我们可以更有效地管理和调试我们的MVC应用,确保每个模块都能按预期工作。通过这些步骤和调整,我们可以确保我们的ASP.NET Core MVC应用程序中的区域能够正确地配置和使用,避免不必要的路由错误和调试时间。首先,我们需要调整路由配置,使其能够正确处理区域的URL格式。 阅读详情

      先说一下基本的路由规则原则。基本的路由规则是从特殊到一般排列,也就是最特殊(非主流)的规则在最前面,最一般(万金油)的规则排在最后。这是因为匹配路由规则也是照着这个顺序的。如果写反了,那么即便你路由规则写对了那照样坐等404.

XD 首先说URL的构造。 其实这个也谈不上构造,只是语法特性吧。

URL构造

命名参数规范+匿名对象

1
routes.MapRoute(name: "Default" ,url: "{controller}/{action}/{id}" , defaults: new { controller = "Home" , action = "Index" , id = UrlParameter.Optional } );

构造路由然后添加

1
2
Route myRoute = new Route( "{controller}/{action}" , new MvcRouteHandler());
routes.Add( "MyRoute" , myRoute);

直接方法重载+匿名对象

1
routes.MapRoute( "ShopSchema" , "Shop/{action}" , new { controller = "Home" });

  个人觉得第一种比较易懂,第二种方便调试,第三种写起来比较效率吧。各取所需吧。本文行文偏向于第三种。

路由规则

 1.默认路由(MVC自带)

1
2
3
4
routes.MapRoute(
"Default" , // 路由名称
"{controller}/{action}/{id}" , // 带有参数的 URL
new { controller = "Home" , action = "Index" , id = UrlParameter.Optional } // 参数默认值 (UrlParameter.Optional-可选的意思) );

2.静态URL段

1
2
3
4
5
routes.MapRoute( "ShopSchema2" , "Shop/OldAction" , new { controller = "Home" , action = "Index" });
  
routes.MapRoute( "ShopSchema" , "Shop/{action}" , new { controller = "Home" });
routes.MapRoute( "ShopSchema2" , "Shop/OldAction.js" ,
  new { controller = "Home" , action = "Index" });

 没有占位符路由就是现成的写死的。

      比如这样写然后去访问http://localhost:XXX/Shop/OldAction.js,response也是完全没问题的。 controller , action , area这三个保留字就别设静态变量里面了。

3.自定义常规变量URL段(好吧这翻译暴露智商了)

1
routes.MapRoute( "MyRoute2" , "{controller}/{action}/{id}" , new { controller = "Home" , action = "Index" , id = "DefaultId" });

这种情况如果访问 /Home/Index 的话,因为第三段(id)没有值,根据路由规则这个参数会被设为DefaultId

这个用viewbag给title赋值就能很明显看出

1
ViewBag.Title = RouteData.Values[ "id" ];

图不贴了,结果是标题显示为DefaultId。 注意要在控制器里面赋值,在视图赋值没法编译的。

4.再述默认路由

     然后再回到默认路由。 UrlParameter.Optional这个叫可选URL段.路由里没有这个参数的话id为null。 照原文大致说法,这个可选URL段能用来实现一个关注点的分离。刚才在路由里直接设定参数默认值其实不是很好。照我的理解,实际参数是用户发来的,我们做的只是定义形式参数名。但是,如果硬要给参数赋默认值的话,建议用语法糖写到action参数里面。比如:

1
public ActionResult Index( string id = "abcd" ){ViewBag.Title = RouteData.Values[ "id" ]; return View();}

5.可变长度路由。

1
routes.MapRoute( "MyRoute" , "{controller}/{action}/{id}/{*catchall}" , new { controller = "Home" , action = "Index" , id = UrlParameter.Optional });

    在这里id和最后一段都是可变的,所以 /Home/Index/dabdafdaf 等效于 /Home/Index//abcdefdjldfiaeahfoeiho 等效于 /Home/Index/All/Delete/Perm/.....

6.跨命名空间路由

 这个提醒一下记得引用命名空间,开启IIS网站不然就是404。这个非常非主流,不建议瞎搞。

1
routes.MapRoute( "MyRoute" , "{controller}/{action}/{id}/{*catchall}" , new { controller = "Home" , action = "Index" , id = UrlParameter.Optional }, new [] { "URLsAndRoutes.AdditionalControllers" , "UrlsAndRoutes.Controllers" });

但是这样写的话数组排名不分先后的,如果有多个匹配的路由会报错。 然后作者提出了一种改进写法。

1
2
3
routes.MapRoute( "AddContollerRoute" , "Home/{action}/{id}/{*catchall}" , new { controller = "Home" , action = "Index" , id = UrlParameter.Optional }, new [] { "URLsAndRoutes.AdditionalControllers" });
  
routes.MapRoute( "MyRoute" , "{controller}/{action}/{id}/{*catchall}" , new { controller = "Home" , action = "Index" , id = UrlParameter.Optional }, new [] { "URLsAndRoutes.Controllers" });

 这样第一个URL段不是Home的都交给第二个处理 最后还可以设定这个路由找不到的话就不给后面的路由留后路啦,也就不再往下找啦。

1
2
3
4
Route myRoute = routes.MapRoute( "AddContollerRoute" ,
"Home/{action}/{id}/{*catchall}" ,
new { controller = "Home" , action = "Index" , id = UrlParameter.Optional },
new [] { "URLsAndRoutes.AdditionalControllers" });  myRoute.DataTokens[ "UseNamespaceFallback" ] = false ;

7.正则表达式匹配路由

1
2
3
4
routes.MapRoute( "MyRoute" , "{controller}/{action}/{id}/{*catchall}" ,
  new { controller = "Home" , action = "Index" , id = UrlParameter.Optional },
  new { controller = "^H.*" },
new [] { "URLsAndRoutes.Controllers" });

 约束多个URL

1
2
3
4
routes.MapRoute( "MyRoute" , "{controller}/{action}/{id}/{*catchall}" ,
new { controller = "Home" , action = "Index" , id = UrlParameter.Optional },
new { controller = "^H.*" , action = "^Index$|^About$" },
new [] { "URLsAndRoutes.Controllers" });

8.指定请求方法

1
2
3
4
5
6
7
routes.MapRoute( "MyRoute" , "{controller}/{action}/{id}/{*catchall}" ,
  
new { controller = "Home" , action = "Index" , id = UrlParameter.Optional },
  
new { controller = "^H.*" , action = "Index|About" , httpMethod = new HttpMethodConstraint( "GET" ) },
  
new [] { "URLsAndRoutes.Controllers" });

9. WebForm支持

1
2
3
4
5
6
7
routes.MapPageRoute( "" , "" , "~/Default.aspx" );
  
  routes.MapPageRoute( "list" , "Items/{action}" , "~/Items/list.aspx" , false , new RouteValueDictionary { { "action" , "all" } });
  
  routes.MapPageRoute( "show" , "Show/{action}" , "~/show.aspx" , false , new RouteValueDictionary { { "action" , "all" } });
  
  routes.MapPageRoute( "edit" , "Edit/{id}" , "~/edit.aspx" , false , new RouteValueDictionary { { "id" , "1" } }, new RouteValueDictionary { { "id" , @"\d+" } });

 具体的可以看

使用Asp.Net4新特性路由创建WebForm应用

或者官方msdn

10.MVC5的RouteAttribute

首先要在路由注册方法那里

1
2
//启用路由特性映射
routes.MapMvcAttributeRoutes();

 这样

1
[Route( "Login" )]

 route特性才有效.该特性有好几个重载.还有路由约束啊,顺序啊,路由名之类的.

其他的还有路由前缀,路由默认值
1
[RoutePrefix( "reviews" )]<br>[Route( "{action=index}" )]<br> public class ReviewsController : Controller<br>{<br>}
 路由构造
1
2
3
4
5
6
7
// eg: /users/5
[Route( "users/{id:int}" ]
public ActionResult GetUserById( int id) { ... }
  
// eg: users/ken
[Route( "users/{name}" ]
public ActionResult GetUserByName( string name) { ... }
 参数限制
1
2
3
4
5
// eg: /users/5
// but not /users/10000000000 because it is larger than int.MaxValue,
// and not /users/0 because of the min(1) constraint.
[Route( "users/{id:int:min(1)}" )]
public ActionResult GetUserById( int id) { ... }
Constraint Description Example
alpha Matches uppercase or lowercase Latin alphabet characters (a-z, A-Z) {x:alpha}
bool Matches a Boolean value. {x:bool}
datetime Matches a DateTime value. {x:datetime}
decimal Matches a decimal value. {x:decimal}
double Matches a 64-bit floating-point value. {x:double}
float Matches a 32-bit floating-point value. {x:float}
guid Matches a GUID value. {x:guid}
int Matches a 32-bit integer value. {x:int}
length Matches a string with the specified length or within a specified range of lengths. {x:length(6)}  {x:length(1,20)}
long Matches a 64-bit integer value. {x:long}
max Matches an integer with a maximum value. {x:max(10)}
maxlength Matches a string with a maximum length. {x:maxlength(10)}
min Matches an integer with a minimum value. {x:min(10)}
minlength Matches a string with a minimum length. {x:minlength(10)}
range Matches an integer within a range of values. {x:range(10,50)}
regex Matches a regular expression. {x:regex(^\d{3}-\d{3}-\d{4}$)}

具体的可以参考

Attribute Routing in ASP.NET MVC 5

 对我来说,这样的好处是分散了路由规则的定义.有人喜欢集中,我个人比较喜欢这种灵活的处理.因为这个action定义好后,我不需要跑到配置那里定义对应的路由规则

11.最后还是不爽的话自己写个类实现 IRouteConstraint的匹配方法。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Routing;
/// <summary>
/// If the standard constraints are not sufficient for your needs, you can define your own custom constraints by implementing the IRouteConstraint interface.
/// </summary>
public class UserAgentConstraint : IRouteConstraint
{
  
     private string requiredUserAgent;
     public UserAgentConstraint( string agentParam)
     {
         requiredUserAgent = agentParam;
     }
     public bool Match(HttpContextBase httpContext, Route route, string parameterName,
     RouteValueDictionary values, RouteDirection routeDirection)
     {
         return httpContext.Request.UserAgent != null &&
         httpContext.Request.UserAgent.Contains(requiredUserAgent);
     }
}
1
2
3
4
5
6
7
routes.MapRoute( "ChromeRoute" , "{*catchall}" ,
  
new { controller = "Home" , action = "Index" },
  
new { customConstraint = new UserAgentConstraint( "Chrome" ) },
  
new [] { "UrlsAndRoutes.AdditionalControllers" });

 比如这个就用来匹配是否是用谷歌浏览器访问网页的。

12.访问本地文档

1
2
3
routes.RouteExistingFiles = true ;
  
routes.MapRoute( "DiskFile" , "Content/StaticContent.html" , new { controller = "Customer" , action = "List" , });

浏览网站,以开启 IIS Express,然后点显示所有应用程序-点击网站名称-配置(applicationhost.config)-搜索UrlRoutingModule节点

1
<add name= "UrlRoutingModule-4.0" type= "System.Web.Routing.UrlRoutingModule" preCondition= "managedHandler,runtimeVersionv4.0" />

把这个节点里的preCondition删除,变成

1
<add name= "UrlRoutingModule-4.0" type= "System.Web.Routing.UrlRoutingModule" preCondition= "" />

 13.直接访问本地资源,绕过了路由系统

1
routes.IgnoreRoute( "Content/{filename}.html" );

文件名还可以用 {filename}占位符。

IgnoreRoute方法是RouteCollection里面StopRoutingHandler类的一个实例。路由系统通过硬-编码识别这个Handler。如果这个规则匹配的话,后面的规则都无效了。 这也就是默认的路由里面routes.IgnoreRoute("{resource}.axd/{*pathInfo}");写最前面的原因。

路由测试(在测试项目的基础上,要装moq)

1
PM> Install-Package Moq
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Web;
using Moq;
using System.Web.Routing;
using System.Reflection;
[TestClass]
public class RoutesTest
{
     private HttpContextBase CreateHttpContext( string targetUrl = null , string HttpMethod = "GET" )
     {
         // create the mock request
         Mock<HttpRequestBase> mockRequest = new Mock<HttpRequestBase>();
         mockRequest.Setup(m => m.AppRelativeCurrentExecutionFilePath)
         .Returns(targetUrl);
         mockRequest.Setup(m => m.HttpMethod).Returns(HttpMethod);
         // create the mock response
         Mock<HttpResponseBase> mockResponse = new Mock<HttpResponseBase>();
         mockResponse.Setup(m => m.ApplyAppPathModifier(
         It.IsAny< string >())).Returns< string >(s => s);
         // create the mock context, using the request and response
         Mock<HttpContextBase> mockContext = new Mock<HttpContextBase>();
         mockContext.Setup(m => m.Request).Returns(mockRequest.Object);
         mockContext.Setup(m => m.Response).Returns(mockResponse.Object);
         // return the mocked context
         return mockContext.Object;
     }
  
     private void TestRouteMatch( string url, string controller, string action, object routeProperties = null , string httpMethod = "GET" )
     {
         // Arrange
         RouteCollection routes = new RouteCollection();
         RouteConfig.RegisterRoutes(routes);
         // Act - process the route
         RouteData result = routes.GetRouteData(CreateHttpContext(url, httpMethod));
         // Assert
         Assert.IsNotNull(result);
         Assert.IsTrue(TestIncomingRouteResult(result, controller, action, routeProperties));
     }
  
     private bool TestIncomingRouteResult(RouteData routeResult, string controller, string action, object propertySet = null )
     {
         Func< object , object , bool > valCompare = (v1, v2) =>
         {
             return StringComparer.InvariantCultureIgnoreCase
             .Compare(v1, v2) == 0;
         };
         bool result = valCompare(routeResult.Values[ "controller" ], controller)
         && valCompare(routeResult.Values[ "action" ], action);
         if (propertySet != null )
         {
             PropertyInfo[] propInfo = propertySet.GetType().GetProperties();
             foreach (PropertyInfo pi in propInfo)
             {
                 if (!(routeResult.Values.ContainsKey(pi.Name)
                 && valCompare(routeResult.Values[pi.Name],
                 pi.GetValue(propertySet, null ))))
                 {
                     result = false ;
                     break ;
                 }
             }
         }
         return result;
     }
  
     private void TestRouteFail( string url)
     {
         // Arrange
         RouteCollection routes = new RouteCollection();
         RouteConfig.RegisterRoutes(routes);
         // Act - process the route
         RouteData result = routes.GetRouteData(CreateHttpContext(url));
         // Assert
         Assert.IsTrue(result == null || result.Route == null );
     }
  
     [TestMethod]
     public void TestIncomingRoutes()
     {
         // check for the URL that we hope to receive
         TestRouteMatch( "~/Admin/Index" , "Admin" , "Index" );
         // check that the values are being obtained from the segments
         TestRouteMatch( "~/One/Two" , "One" , "Two" );
         // ensure that too many or too few segments fails to match
         TestRouteFail( "~/Admin/Index/Segment" ); //失败
         TestRouteFail( "~/Admin" ); //失败
         TestRouteMatch( "~/" , "Home" , "Index" );
         TestRouteMatch( "~/Customer" , "Customer" , "Index" );
         TestRouteMatch( "~/Customer/List" , "Customer" , "List" );
         TestRouteFail( "~/Customer/List/All" ); //失败
         TestRouteMatch( "~/Customer/List/All" , "Customer" , "List" , new { id = "All" });
         TestRouteMatch( "~/Customer/List/All/Delete" , "Customer" , "List" , new { id = "All" , catchall = "Delete" });
         TestRouteMatch( "~/Customer/List/All/Delete/Perm" , "Customer" , "List" , new { id = "All" , catchall = "Delete/Perm" });
     }
   
}

  最后还是再推荐一下Adam Freeman写的apress.pro.asp.net.mvc.4这本书。稍微熟悉MVC的从第二部分开始读好了。前面都是入门(对我来说是扯淡)。但总比国内某些写书的人好吧——把个开源项目的源代码下载下来帖到书上面来,然后标题起个深入解析XXXX,然后净瞎扯淡。最后一千多页的巨著又诞生了。Adam Freeman的风格我就很喜欢,都是实例写作,然后还在那边书里面专门写了大量的测试。

  哎没办法啊,技术差距就是这样了。



告别爆显存!手把手教你为ComfyUI+华为Atlas 300I Duo配置wan2.1视频生成工作流(含CPU-VAE参数) 本文详细介绍了华为Atlas 300I Duo与ComfyUI的深度适配实战,重点优化wan2.1视频生成工作流。从硬件散热改造到软件栈配置,再到ComfyUI专项优化,提供完整的解决方案,显著提升视频生成效率与稳定性,特别适合需要高效文生视频的应用场景。 阅读详情

相关推荐

工业视觉开发者的福音:用C#玩转VisionMaster算子(非方案版完整教程)

本文为工业视觉开发者提供了一份完整的C#与VisionMaster算子二次开发教程,详细介绍了环境配置、算子调用原理、性能优化技巧及实战案例。通过模板匹配和二维码识别等实例,展示了如何高效集成VisionMaster算子到现有框架中,提升工业自动化视觉检测系统的灵活性和性能。

weixin_29280657的博客 270

猿学~史上最全的ASP.NET MVC路由配置

先说一下基本的路由规则原则。基本的路由规则是从特殊到一般排列,也就是最特殊(非主流)的规则在最前面,最一般(万金油)的规则排在最后。这是因为匹配路由规则也是照着这个顺序的。如果写反了,那么即便你路由规则写对了那照样坐等404. XD 首先说URL的构造。 其实这个也谈不上构造,只是语法特性吧。 URL构造 命名参数规范+匿名对象 1 routes.MapR...

全栈开发者 2万+

Pixhawk变砖自救指南:从DFU模式到固件重刷全流程(附2.4.8实测)

本文详细介绍了Pixhawk飞控变砖后的自救方法,从DFU模式进入、固件重刷到高级恢复技巧全流程。特别针对国产版本boot0引脚未引出的特殊情况提供了解决方案,帮助用户通过QGC或Mission Planner地面站工具恢复飞控功能,适用于2.4.8等常见固件版本。

weixin_29168813的博客 336

Controller 使用自定义路由机制,以及RouteConfig的配置

RouteConfig配置如下:public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( name: "D...

大表哥 4473

波克 上海 Unity开发笔试题 2024

主要分为四部分,如果没有准备好,不要点击笔试链接,进入就会自动开始。

z2014z的博客 3392

基于ROS2的实时视频流转换:image2rtsp在多路相机采集中的应用

本文详细介绍了如何在ROS2机器人系统中使用image2rtsp工具,将ROS2内部的相机图像话题实时转换为标准的RTSP视频流。重点阐述了其安装配置、核心参数调优,并提供了多路相机采集的实战方案,解决了机器人视觉数据跨平台、跨网络分发的难题,极大提升了视频流集成的部署效率。

weixin_29214559的博客 395

asp.net _路由配置

路由配置一般是有两个RouteConfig、WebApiConfig。 RouteConfig RouteConfig一般是影响页面Controller,如下: public class RouteConfig { public static void RegisterRoutes(RouteCollection routes) { ...

楠之枫雪的博客 4386

【硬件相关】IB网与以太网核心技术解析及高性能网络部署指南

本文深入解析了IB网与以太网的核心技术差异,包括协议栈、流量控制机制及硬件架构,并提供了高性能网络部署的实战指南。通过对比测试和调优案例,展示了IB网在低延迟和高负载下的优势,以及混合组网中的创新应用,助力超算集群和高效网络部署。

weixin_29311017的博客 98

史上最全的ASP.NET MVC路由配置,以后RouteConfig再弄不懂神仙都难救你啦~

原文http://www.cnblogs.com/zeusro/p/RouteConfig.html装载注明出处,爬虫请自重。 继续延续坑爹标题系列。其实只是把apress.pro.asp.net.mvc.4.framework里的CHAPTER 13翻译过来罢了,当做自己总结吧。内容看看就好,排版就不要吐槽了,反正我知道你也不会反对的。 先说一下基本的路由规则原则。基本的路由规则是从特殊到...

weixin_30374009的博客 631

英飞凌 AURIX TC3XX 系列单片机的 NVM-Flash 介绍

简单介绍英飞凌 AURIX TC3XX 系列多核单片机的 Flash,便于快速上手使用

大橙子的博客 6637

pi-coding-agent 完整详解

pi-coding-agent是一个由Mario Zechner开发的专业AI编程助手,基于Node.js和TypeScript构建。核心功能包括:1)多级思考模式(ThinkingLevel),从none到ultra控制推理深度;2)对话压缩(compaction)管理长对话记忆;3)WebSocket实时通信支持流式交互。该智能体支持代码生成、调试、重构等专业编程任务,采用AI Agent架构,具备工具调用和多轮记忆能力。项目结构通常包含server、agent、config等模块,可通过二次开发扩展功

大坡3D软件开发 2406

route和ipconfig

Route在本地 IP 路由表中显示和修改条目。使用不带参数的 route 可以显示帮助。语法route [-f] [-p] [Command [Destination] [mask Netmask] [Gateway] [metric Metric]] [if Interface]]参数-f 清除所有不是主路由(网掩码为 255.255.255.255 的路由)、环回网络路由(目标为

搜搜问问 2137

利用baostock获取上市公司财务指标

利用baostock获取上市公司的财务指标 1、导入模块,登录baostock import baostock as bs import pandas as pd import time # 登陆系统 lg = bs.login() # 显示登陆返回信息 print('login respond error_code:'+lg.error_code) print('login respond error_msg:'+lg.error_msg) 2、查询股票代码、行业板块 # 查询股票代码 rs=.

firefox_yau的博客 2098

Asp.Net MVC 路由配置

1、概述  在以前的Web Form开发中,我们请求的URL都对应一个具体的文件,如/System/News.aspx?id=1 ,则在对应的网站目录下面存在一个News.aspx的文件,而ASP.NET路由使您能够使用不必映射到网站中的特定文件的URL。因为URL不必映射到文件,您可以使用描述用户操作的URL,因此用户更容易理解。ASP.NET MVC框架和ASP.NET动态数据扩展路由以提供仅在

高级项目经理、专注于技术架构、分享项目管理及职场心得 1697

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

ASP.NET Core MVC之route简单路由配置

ASP.NET Core MVC的路由配置一般分为两种,约定路由和特性路由。下面分别介绍两种路由的配置方法。 一:约定路由 约定路由顾名思义,是我们约定好的路由规则,程序根据约定,访问对应的controller,首先建立一个ASP.NET Core Web项目,选择空模板,在Startup类中的ConfigureServices方法中注册MVC服务。 public void ConfigureSe...

weixin_39714231的博客 7454

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

asp.net mvc路由配置

https://www.cnblogs.com/zeusro/p/RouteConfig.html

zhao277949522的博客 1315

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

ASP.NET Core MVC 中两种路由的简单配置

1.全局约定路由 这种方式配置优先级比较低,如果控制器或者方法上标记了特性路由那么优先走特性路由。 当建立好一个mvc项目里,路由都是默认配置好的。 如果建立的是空项目那么需要手动配置: 1.需要在ConfigureServices方法中添加mvc服务 services.AddMvc(); 2.在Configure添加mvc中间件: app.UseMvcWithDefaultRoute()...

weixin_30596343的博客 578

史上最全的ASP.NET MVC路由配置

先说一下基本的路由规则原则。基本的路由规则是从特殊到一般排列,也就是最特殊(非主流)的规则在最前面,最一般(万金油)的规则排在最后。这是因为匹配路由规则也是照着这个顺序的。如果写反了,那么即便你路由规则写对了那照样坐等404. XD 首先说URL的构造。 其实这个也谈不上构造,只是语法特性吧。 URL构造 命名参数规范+匿名对象 1

chanzhu的博客 1万+

asp.net mvc 路由配置与规则

命名参数规范+匿名对象 routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } ); 构造路由然后添加 Route myRoute = new Route("{controller}/{action}", new MvcRouteHandler());

Superstatus的博客 765

ASP.NET Core MVC路由配置:从基础路由到高级路由模式的终极指南

想要构建高效、可维护的Web应用程序?ASP.NET Core MVC路由配置就是您必须掌握的核心技能!🚀 路由系统是MVC框架的"交通警察",负责将用户请求精准导航到正确的控制器和操作方法。无论您是初学者还是经验丰富的开发者,本指南将带您从基础路由配置到高级路由模式,全面提升您的ASP.NET Core开发能力。 ## 什么是ASP.NET Core MVC路由? ASP.NET Core

gitblog_00594的博客 996

ASP.NET MVC路由配置

XD 首先说URL的构造。 其实这个也谈不上构造,只是语法特性吧。 一、命名参数规范+匿名对象 routes.MapRoute(name: "Default",url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional

518

ASP.NET MVC路由配置RouteConfig

史上最全的ASP.NET MVC路由配置,以后RouteConfig再弄不懂神仙都难救你啦~原文http://www.cnblogs.com/zeusro/p/RouteConfig.html 装载注明出处,爬虫请自重。继续延续坑爹标题系列。其实只是把apress.pro.asp.net.mvc.4.framework里的CHAPTER 13翻译过来罢了,当做自己总结吧。内容看看就好,排版就不要吐...

ZeroRm的博客 4356

ASP.NET MVC架构与实战系列之二:理解MVC路由配置

ASP.NET MVC架构与实战系列之二:理解MVC路由配置       在上一篇文章中,我简短的谈了一下MVC的底层运行机制,如果对MVC还不是很了解的朋友,可以作为入门的参照。接下来,我开始介绍关于URL路由的相关知识。URL路由不是MVC独有的,相反它是独立于MVC而单独存在的(在System.Web.Routing下)。因此,URL路由也能为传统的ASP.NET应用程序服务。

autumn20080101的专栏 392

ASP.NET MVC网站路由配置

using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.Mvc;using System.Web.Routing;namespace DemoMvc{    // 注意: 有关启用 IIS6 或 IIS7 经典模式的说明,    // 请访问 http://g

最后一个BUG留给我 424
上一篇: SpringMVC(干货)
下一篇: 最美程序媛!
Footloose_
博客等级 码龄10年 254粉丝 11原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值