开发者

How to future-proof a reference to a page that could change

Simple example..

Response.Redirect("/store/packages.aspx");

I'd like to reference "/store/packages.aspx" directly from the web.sitemap file, if at all possible. This way if some day down the line I rename or move the file packages.aspx, I don't have t开发者_运维百科o find every instance of where I hard-coded the URL in my code.

What is the best method for achieving this?


It may be overkill for what you're doing, but check out T4MVC. The short version is that it generates classes from files in your project. You then reference the generated classes' members instead of hard-coding the URL, and get a compile error if the names change and your reference hasn't been updated. It's built specifically for MVC, but the templates could probably be modified to meet your needs.

As mentioned by RPM1984, a simpler solution is to maintain a set of const fields and reference those wherever you need paths.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜