Learning
Learning

Reputation: 20001

How to Recompile Global.asax file programmatically

I am custom CMS where i add dynamic routes from database sample code is below

 foreach(DataTable table in ds.Tables) {

  foreach(DataRow dr in table.Rows) {
   ctr = ctr + 1;

   routes.MapPageRoute("Route" + ctr, routeURL, routeHandler, false,
    new RouteValueDictionary {
     {
      "path",
      "page-not-found"
     }, {
      "pagename",
      "page-not-found"
     }
    });
  }
 }

Problem i am facing is that when ever i add new page to website using custom CMS i have to upload Gloabal.asax file again so that it compiles again and new routes take effect.

If i dont compile then new page added dont show.

How can run a code on button event so that i can force Global.asax file to recompile again.

I need this for asp.net webform website

Upvotes: 0

Views: 317

Answers (1)

Rocoso
Rocoso

Reputation: 293

Here's Editable Routes how to edit the routes dynamically without compiling. The example is for MVC but the author indicates that also works for WebForms.

There is also a library that can do that RouteMagic.

Here asp.net webforms dynamic routing is a question from someone who does something similar in WebForms using that library.

Upvotes: 1

Related Questions