我創建了一個自定義屬性稱爲RouteAttribute
:屬性幫助的路由,編譯器錯誤
[AttributeUsage(AttributeTargets.Property)]
public class RouteAttribute : Attribute
{
public string Url { get; set; }
public bool CheckPhysicalUrlAccess { get; set; }
public RouteValueDictionary Defaults { get; set; }
public RouteValueDictionary Constraints { get; set; }
public RouteValueDictionary DataTokens { get; set; }
}
它是用來增加通過包含在我的網站網址的名單上我的網址助手類屬性的路由,所以我有一個簡單的方法來管理我的網站網址。
有一個問題,與添加默認不過,讓編譯器錯誤:
[Route("~/MyPage/Home.aspx", new RouteValueDictionary { { "query", "value" } })]
public string HomePage
{
get { return "Home" }
}
爲了避免混淆,該值設置爲routeurl,物理地址是從屬性, 原因是,我轉換現有的網站,而不是改變聯繫無處不在,一旦我與網頁做,我去我的階級和改變物理鏈接到新的頁面
給了一個錯誤:
An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type
不是最好的解決方案,但它的工作原理..我將在未來研究更好的方式,謝謝 – jaekie 2011-02-25 16:49:34