我正在创建一个ASP.NET MVC 5应用程序和我在路由方面有一些问题.我们使用属性Route
在web应用程序中映射路由.我有以下行动:
[Route("{type}/{library}/{version}/{file?}/{renew?}")]
public ActionResult Index(EFileType type,
string library,
string version,
string file = null,
ECacheType renew = ECacheType.cache)
{
// code...
}
只有在url
结尾处通过斜杠字符/
,我们才能访问此URL,如下所示:
type/lib/version/file/cache/
它工作得很好,但是没有/
就不能工作,我得到一个404
Not Found(找不到)错误,如下所示
type/lib/version/file/cache
或者这样(不带可选参数):
type/lib/version
我想在url
结尾处加入或不加入/
个字符.最后两个参数是可选的.
我的RouteConfig.cs
是这样的:
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapMvcAttributeRoutes();
}
}
我该怎么解决呢?让斜线/
也成为可选的吗?