পৃষ্ঠাসমূহ

Search Your Article

CS

 

Welcome to GoogleDG – your one-stop destination for free learning resources, guides, and digital tools.

At GoogleDG, we believe that knowledge should be accessible to everyone. Our mission is to provide readers with valuable ebooks, tutorials, and tech-related content that makes learning easier, faster, and more enjoyable.

What We Offer:

  • 📘 Free & Helpful Ebooks – covering education, technology, self-development, and more.

  • 💻 Step-by-Step Tutorials – practical guides on digital tools, apps, and software.

  • 🌐 Tech Updates & Tips – simplified information to keep you informed in the fast-changing digital world.

  • 🎯 Learning Support – resources designed to support students, professionals, and lifelong learners.

    Latest world News 

     

Our Vision

To create a digital knowledge hub where anyone, from beginners to advanced learners, can find trustworthy resources and grow their skills.

Why Choose Us?

✔ Simple explanations of complex topics
✔ 100% free access to resources
✔ Regularly updated content
✔ A community that values knowledge sharing

We are continuously working to expand our content library and provide readers with the most useful and relevant digital learning materials.

📩 If you’d like to connect, share feedback, or suggest topics, feel free to reach us through the Contact page.

Pageviews

Wednesday, March 8, 2017

MVC Framework - Routing Engine

Introduction to Routing

ASP.NET MVC Routing enables use of URLs that are descriptive of the user actions and are more easily understood by the users. At the same time, Routing can be used to hide data which is not intended to be shown to the final user. For example, in an application that does not uses routing, user would be shown the URL as http://myapplication/Users.aspx?id=1 which would correspond to the file Users.aspx inside
myapplication path and sending id as 1 Generally we would not like to show such file names to our final user.
To handle MVC URLs, the ASP.NET platform uses the routing system which lets you create any pattern of URLs you desire, and express them in a clear and concise manner. Each route in MVC contains a specific URL pattern. This URL pattern is compared to the incoming request URL and if the URL matches this pattern, it is used by the routing engine to further process the request.

MVC Routing URL Format

To understand the MVC routing, consider the following address URL:
http://servername/Products/Phones
In the above URL, Products is the first segment and Phone is the second segment which can be expressed in the following format:
{controller}/{action}
The MVC framework automatically considers the first segment as the Controller name and the second segment as one of the actions inside that Controller. Note that if the name of your Controller is ProductsController, you would only mention Prodcuts in the routing URL. The MVC framework automatically understands the Controller suffix.

Creating a Simple Route

Routes are defined in the RouteConfig.cs file which is present under the App_Start project folder.
mvc_route_config You will see the following code inside this file:
public class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id =    UrlParameter.Optional }
            );
        }
    }
This RegisterRoutes method is called by the Global.ascx when the application is started. The Application_Start method under Global.ascx calls this MapRoute function which sets the default Controller and its action (method inside the Controller class).
To modify the above default mapping as per our example, change the following line of code:
 defaults: new { controller = "Products", action = "Phones", id =    UrlParameter.Optional }
This setting will pick the ProductsController and call the Phone method inside that. Similarly, if you have another method such as Electronics inside ProductsController, the URL for it would be:
http://servername/Products/Electronics

No comments:

Post a Comment