我有一个大的Webforms应用程序。在整个应用程序的许多地方,我们在后面的代码中设置超链接的导航URL。硬编码字符串文字似乎是一个坏主意。在WebForms中管理网址
hlVideos.NavigateUrl = "/path/to/some/page.aspx";
这似乎不是一个好主意,或者,因为它可能需要我有每个需要它的页面上的字符串常量:
private const string PathToSomePage = "/path/to/some/page.aspx";
hlVideos.NavigateUrl = PathToSomePage;
我想过一个类有一堆可以访问的const字符串。这似乎是一个开放/封闭的原则违反,每次我添加一个新的页面时,要求我添加另一个常量。
public class UrlManager
{
public const string PathToSomePage = "/path/to/some/page.aspx";
public const string PathToSomeOtherPage = "/path/to/some/other/page.aspx";
public const string PathToYetAnotherPage = "/path/to/yet/another/page.aspx";
}
其他人如何处理这个问题?也许我过于复杂了,尽管我正在处理一百个URL,并且有很多页面引用每个URL。