1

I am going to implement routing feature in my asp.net4.0 application and following the given link:

URL-Routing

This is fine if an application has limited no. of pages but my application has lots of pages. so i have to write code [ routes.MapPageRoute("","",""); ] many times. Can we map all pages by looping through any collection classes or by any other method.

Thanks

1 Answer 1

1

If you have a standard pattern for your url and your file structure you can use the placeholders in the mapped url too

eg. If you can map every "{controller}/{action}/{id}" to "/Pages/{controler}/{action}.aspx"

For example, i build a site that has this folder structure

Project Folder Structure

Under the root folder there is the Views folder where all my pages reside. Under the Views folder there is one subfolder for every "controller" (there is no controllers in webforms, but I follow the MVC conventions here) Under the controllers subfolders there are the aspx pages that represent different actions

The aspx page names are the same for each controller ("Index.aspx","Add.aspx","Edit.aspx" etc)

So I can have a general mapping rule

routes.MapPageRoute("GeneralAction", "{controler}/{action}/{id}", "~/Views/{controler}/{action}.aspx");

I don't need different rules for different pages as long as the folder structure follows this pattern

Now

"/Patient/Add" will map to "~/Views/Patient/Add.aspx"
"/Incident/Add" will map to "~/Views/Incident/Add.aspx"
"/Patient/Edit/31" will map to "~/Views/Patient/Edit.aspx" (with id=31)

etc, all matching this one rule above.

of course if you want to override this rule you can define more specific routes BEFORE defining this one.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.