假设我的路线定义如下:
routes.MapPageRoute(""
, "{language}/customerservice.aspx"
, "~/customerservice.aspx"
, false
, new RouteValueDictionary { {"language", "en"} });
在/comersomerservice.aspx中我填充了一个文字:
lit_test.Text = RouteData.Values["language"].ToString();
当我导航到/comersomerservice.aspx时,我希望文字文本为“en”,而我得到一个空引用异常。在/en/customerservice.aspx,它的行为与我期望的一样。
有没有办法为磁盘上存在的aspx文件运行路由?
编辑:
如此配置的路线:
routes.RouteExistingFiles = true;
routes.MapPageRoute(""
, "customerservice.aspx"
, "~/customerservice.aspx"
, false
, new RouteValueDictionary { { "language", "en" } });
将导致文字填充“en”,但是带有可选语言参数的第一个场景仍然失败,并且RouteExistingFiles标志设置为true。
谢谢!
答案 0 :(得分:0)
使用RouteExistingFiles属性强制所有请求(即使是磁盘上存在的文件)都要通过路由。
routes.RouteExistingFiles = true;
搜索RouteExistingFiles以查找更多信息,例如Considerations when turning on RouteExistingFiles。