Getting virtual path of an arbitrary page
Consider this scenario: You want to redirect (REDIRECT) a user to a certain handler (aspx or ashx) without hardcoded path. You have the name of the ha开发者_如何学运维ndler's class, you can even get it's type (ASP.whateverpageclass). Now, how do you get the virtual path?
If I understood correctly, you want a virtual path for a handler if you have the name/type of implementing class. AFAIK, this is not possible because there need not be one to one correlation between two - from ASP.NET run-time perspective, it has to map a virtual path to some handler class (and not a vice-verse). For example, you can have all paths to certain extension be mapped with the same handler type.
As far as your main problem of avoiding hard-coding is concerned, you can handled that having configurable url (to redirect) or have persistent store (database, xml file or config file) that can map some key (for example, handler class name) to virtual path to redirect.
精彩评论