C# and ASP.NET interview questions and answers: - What is URL routing?

369 0 0
                                        

This ASP.NET interview question was asked in cognizant Mumbai to one of the senior developers.

URL routing helps us to define more user friendly names for pages rather than end users getting in to physical file names. For example rather than typinghttp://www.questpond.com/Contactcompany.aspx , it would make end users life simpler if he can type http://www.questpond.com/Contact.

The benefits of URL routing are the following:-

Short and sweet URL’s. Users can easily navigate sites without complicated file extensions like .ASPX, .PHP, .CGI etc.URL becomes permanent and they do not change if you change the physical file names.

You get benefit of search engine optimization as the search engine can now correlate content with file names.

To implement URL routing in ASP.NET is a three-step process(below is the code behind for the same):-

Add “Global.asax” file to your ASP.NET project.

Import “System.Web.Routing” namespace in the “global.asax.cs” file (behind code).In “Application_Start” event of “Global.asax.cs” file use the routes collection to map the URL names with the physical ASPX file names.

Below is a simple sample code of “global.asax.cs” file which maps “Home” with “DisplayHome.aspx”.

You can also read MVC interview questions and answers series posted by us onwww.codeproject.com

The above question is taken from the best-selling .NET interview questions and answers book published by BPB publication delhi.

This is an awesome video on a famous c# and ADO.NET interview question and answers : – Difference between dataset and data reader.

...Where stories live. Discover now