使用正则表达式匹配ASP.NET MVC的url并进行处理

2019/4/14 下午11:35:01 阅读(276)

ASP.NET MVC url匹配及路由参考

routes.MapRoute(
	"NotFound",
	"{shortid:regex(^\\w{{8}}$)}",
	new { controller = "Home", action = "Detail" });
//匹配类似/xxxxxxxx这样的路径,返回/home/detail的内容

public async Task<IActionResult> Detail(string id)
{
	var shrotid = this.RouteData.Values["shortid"]?.ToString();
	...
	return View();
}
返回