When you request any page into MVC Application, it will go through the Routing Architecture. Your Routing system will decide your URL pattern. The default routing algorithm is like {controller}/ {action}/ {id} patterns. But it can be possible to change that pattern using Custom Routes.
Default Route
You can configure Route into the Global.aspx's Application Start Event. When you are creating an MVC application, it will already define Default route. Default route can be configured using the following code:
Custom Routes
It is possible to develop an MVC application without creating a Custom Route. But sometimes, there is a situation to change the pattern of URL in which it makes sense to create Custom Routes.
Examples of Valid Route Patterns in ASP.NET MVC
Suppose I have a BlogController like below.
1- Imagine that you want to route a request look like: /Archive/12-25-2010.
2- Imagine that you want to route a request look like: /MyBlogs/All/12 or /MyBlogs/All/
3- Imagine that you want to route a request look like: /MyBlogs/Suraj/Post/101
https://www.tutorialsteacher.com/
Default Route
You can configure Route into the Global.aspx's Application Start Event. When you are creating an MVC application, it will already define Default route. Default route can be configured using the following code:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional });
Custom Routes
It is possible to develop an MVC application without creating a Custom Route. But sometimes, there is a situation to change the pattern of URL in which it makes sense to create Custom Routes.
Examples of Valid Route Patterns in ASP.NET MVC
Route Pattern | URL Example |
mysite/{username}/{action} | ~/mysite/jatten/login |
public/blog/{controller}-{action}/{postId} | ~/public/blog/posts-show/123 |
{country}-{lang}/{controller}/{action}/{id} | ~/us-en/products/show/123 |
products/buy/{productId}-{productName} | ~/products/but/2145-widgets |
Suppose I have a BlogController like below.
public class BlogController : Controller
{
public string Archive(DateTime? entryDate)
{
return "You wants Blog Entry on
Date:=" + entryDate.ToString();
}
public string All()
{
return "All function";
}
public string getData(string name, int empId)
{
return "name: " + name + " id= " + empId;
}
}
1- Imagine that you want to route a request look like: /Archive/12-25-2010.
routes.MapRoute(
"myBlogRoute1",
"{Archive}/{entrydate}",
new { Controller = "Blog", action = "Archive", });
2- Imagine that you want to route a request look like: /MyBlogs/All/12 or /MyBlogs/All/
//
MyBlogs/All/12
// MyBlogs/All/
routes.MapRoute(
name: "myBlogRoute2",
url: "MyBlogs/{action}/{id}",
defaults: new
{
controller = "Blog",
action = "All",
id = UrlParameter.Optional
}
);
3- Imagine that you want to route a request look like: /MyBlogs/Suraj/Post/101
//
MyBlogs/suraj/Post/101
routes.MapRoute(
name: "myBlogRoute3",
url: "MyBlogs/{name}/Post/{postId}",
defaults: new
{
controller = "Blog",
action = "getData",
}
);
https://www.tutorialsteacher.com/
Well you use a hard way for publishing, you could find much easier one!
ReplyDeletepython course institute in bangalore
python Course in bangalore
python training institute in bangalore
Nice post. By reading your blog, i get inspired and this provides some useful information. Thank you for posting this exclusive post for our vision.
ReplyDeleteJava training in Bangalore | Java training in Marathahalli
Java training in Bangalore | Java training in Btm layout
Java training in Bangalore |Java training in Rajaji nagar
Thank you a lot for providing individuals with a very spectacular possibility to read critical reviews from this site.
ReplyDeleteBest Devops training in sholinganallur
Devops training in velachery
Devops training in annanagar
Devops training in tambaram
Awesome article. It is so detailed and well formatted that i enjoyed reading it as well as get some new information too.
ReplyDeleteData Science Training in Chennai | Best Data science Training in Chennai
Data Science training in kalyan nagar
Data science training in Bangalore | Data Science training institute in Bangalore
Data Science training in marathahalli | Data Science training in Bangalore
Data Science interview questions and answers
Data science training in jaya nagar | Data science Training in Bangalore
This is an excellent post that is being shared. Kindly do share more post in this sorts.
ReplyDeleteIELTS Classes in Mumbai
IELTS Coaching in Mumbai
Best IELTS Coaching in Mumbai
IELTS Center in Mumbai
IELTS Training in Mumbai
Best IELTS Classes in Mumbai
IELTS Class in Mumbai
Thanks for sharing this information admin, it helps me to learn new things. Continue sharing more like this.
ReplyDeleteRPA Training in Chennai
Robotics Process Automation Training in Chennai
Blue Prism Training in Chennai
Blue Prism Training
UiPath Training in Chennai
Data Science Course in Chennai
Data Science Training in Chennai
Informative post, thanks for taking time to share this page.
ReplyDeletePython course in Chennai
Best Python Training in Chennai
ccna Training in Chennai
ccna course in Chennai
Data Analytics Courses in Chennai
Big Data Analytics Courses in Chennai
Python Training in Anna Nagar
Python Training in T Nagar
Outstanding blog with lots of information. Keep posting more like this.
ReplyDeleteAmazon web services Training in Chennai
AWS Certification in Chennai
DevOps course in Chennai
Best devOps Training in Chennai
Data Analytics Courses in Chennai
Big Data Analytics Courses in Chennai
AWS Training in Anna Nagar
AWS Training in T Nagar
You are doing a great job. I would like to appreciate your work for good accuracy
ReplyDeleteData Science Course in Chennai
You are provided the information was very useful for me and I want more different details about this topic, keep posting...
ReplyDeleteExcel Training in Chennai
Excel Advanced course
Pega Training in Chennai
corporate training in chennai
Tableau Training in Chennai
Unix Training in Chennai
Oracle Training in Chennai
Spark Training in Chennai
Embedded System Course Chennai
Linux Training in Chennai
Thanks for the blog post buddy! Keep them coming... boxes uk
ReplyDeleteGreat survey, I'm sure you're getting a great response. Zebra Blinds
ReplyDeletecustom boxes online
ReplyDeleteprinted packaging boxes
custom printed boxes uk
custom boxes and packaging
buy packaging boxes
wholesale packaging boxes
Custom Packaging
custom packaging boxes with logo
Thanks for sharing