asp mvc 2 areas [closed]
can i disable compiling of routing and other asax files? to change them, when application running already
No. Anything with a .cs extension (like global.asax.cs) has to be compiled. What are you really trying to do? The compiler is pretty quick. If you're just trying to debug your routes, you can use something like the route debugger (wonderful, wonderful tool).
Update based on comment
Your comment says that you want to store routes outside of the compiled code.
This link describes how to store them in a database, which I feel is the best place. The example is from 2008 so it's probably not compatible with the MVC3, but it should give you an idea of where to start.
If you don't want to go through the trouble of building an editor (or worse, manually entering them in your database), an XML file is acceptable. This link describes loading routes from an XML file.
The techniques are all pretty much the same:
- Create a class which can load route data from a store. The simplest may be:
- Route Name
- route string (ie, "{controller}/{action}/{id}"
but you'll probably want to include defaults for controller name, action name, etc.
- In Application_Start, use that class to load and register the routes:
...
List<Route> routes = MyRouteLoader.Load(routeXmlFileName);
foreach(Route route in routes)
{
routes.add(route);
}
The only semi-complex part is loading the routes from the XML, but you may be able to use the System.Xml.Serialization.XmlSerializer
class to read and write the routes to your XML with little custom code.
精彩评论