我正在尝试 .NET 4.0 的新功能 - url 路由,但无法获取 url 中传递的信息。以下是代码:
全球.ASPX.CS
protected void Application_Start(object sender, EventArgs e)
{
SetRouting(RouteTable.Routes);
}
private void SetRouting(RouteCollection routeCollection)
{
routeCollection.MapPageRoute("Company",
"Company/{CompanyName}",
"~/Asset/RequestForm.aspx", true, new RouteValueDictionary { { "CompanyName", "?CompanyName" } });
routeCollection.MapPageRoute("Deal",
"Company/{CompanyName}/{DealName}",
"~/Asset/RequestForm.aspx", true, new RouteValueDictionary { { "DealName", "?DealName" } });
routeCollection.MapPageRoute("ClientRoute",
"Client/{ClientCompanyName}",
"~/User/Login.aspx", true, new RouteValueDictionary { { "ClientCompanyName", "?ClientCompanyName" } });
}
登录.aspx:
private string CompanyName {
get
{
if (Page.RouteData.Values["ClientCompanyName"] == null)
{
return null;
}
return Page.RouteData.Values["ClientCompanyName"].ToString();
}
}
现在,即使我在 url 中使用 Client/Google,上面提到的属性也会返回 null。当我重置 IIS(IIS 6)并第一次这样做时,它会返回值。否则它给出null。
任何线索?