How do I add custom locations at runtime without modifying web.config
I have an xml file with custom routes that I'm开发者_运维知识库 creating routes from on Application_Start in Global.asax. Some of those routes require authentication, some don't. Currently I have "location" entries for all those routes in web.config to control authorization.
I wonder whether there is a way to configure locations on application start at the same time I configure routes, so that I don't need to have entries in web.config.
I'm using ASP.NET WebForms .NET 4.0
Try creating your own (or looking at the many open source) sitemap providers. Your sitemap provider can allow you to dynamically change the sitemap nodes based on whatever logic you want and can also allow you to specify roles/users allowed to access each node...
An SO question showing the basic concept is here and a slightly more involved answer is here
That way, you can read your XML to calculate the URLs of the routes, merge it with any existing sitemap definition as appropriate and still get all the ASP.Net security benefits (Security trimming on sitemap, Authorization for URLs, etc.)
This doesn't answer your question directly but I hope this is of some help.
精彩评论