Monday, September 17, 2018
In the previous post we created a Admin Area, however we had to type in localhost/Admin/Home/Index to get to the Admin index page. In this post we are going to make the Index page more user friendly.
To do that first let's assign the namespace to a local variable so that we can use it in multiple routes.
Open the "AdminAreaRegistration.cs" file in the /Areas/Admin folder and change the RegisterArea method to the following:
Now we are ready to create our custom route so that the user can just type /Admin/
Change the code to the following in RegisterArea method
We created a custom route by using the MapRoute method in the AreaRegistrationContext object. There are many method overloads in the MapRoute method. But all we need is the method with the following method signature, (name, url, object, namespaces). The first parameter is the name of the route, this could be blank, the second parameter is the actual route, the {id} is optional so I decided to leave that there. The third parameter is the definition of the object that defines the controller and action to use, and that the id is an optional parameter.
It is important to note that more narrow or descriptive route comes first, before the catchall route which is "Admin/{controller}/{action}/{id}. MVC will route to the first route that it hits so if you have the more general route firs the more custom route will never be hit because it was already caught by the more general route.
Similar Posts:
To do that first let's assign the namespace to a local variable so that we can use it in multiple routes.
Open the "AdminAreaRegistration.cs" file in the /Areas/Admin folder and change the RegisterArea method to the following:
public override void RegisterArea(AreaRegistrationContext context) { var namespaces = new string[] { typeof(NorthwindCafe.Areas.Admin.Controllers.HomeController).Namespace }; context.MapRoute( "Admin_default", "Admin/{controller}/{action}/{id}", new { action = "Index", id = UrlParameter.Optional }, namespaces ); }
Now we are ready to create our custom route so that the user can just type /Admin/
Change the code to the following in RegisterArea method
public override void RegisterArea(AreaRegistrationContext context) { var namespaces = new string[] { typeof(NorthwindCafe.Areas.Admin.Controllers.HomeController).Namespace }; context.MapRoute( "Home", "Admin/{id}", new { controller = "Home", action = "Index", id = UrlParameter.Optional }, namespaces ); context.MapRoute( "Admin_default", "Admin/{controller}/{action}/{id}", new { action = "Index", id = UrlParameter.Optional }, namespaces ); }
We created a custom route by using the MapRoute method in the AreaRegistrationContext object. There are many method overloads in the MapRoute method. But all we need is the method with the following method signature, (name, url, object, namespaces). The first parameter is the name of the route, this could be blank, the second parameter is the actual route, the {id} is optional so I decided to leave that there. The third parameter is the definition of the object that defines the controller and action to use, and that the id is an optional parameter.
It is important to note that more narrow or descriptive route comes first, before the catchall route which is "Admin/{controller}/{action}/{id}. MVC will route to the first route that it hits so if you have the more general route firs the more custom route will never be hit because it was already caught by the more general route.
Similar Posts:
Subscribe to:
Post Comments (Atom)
Search This Blog
Tags
Web Development
Linux
Javascript
DATA
CentOS
ASPNET
SQL Server
Cloud Computing
ASP.NET Core
ASP.NET MVC
SQL
Virtualization
AWS
Database
ADO.NET
AngularJS
C#
CSS
EC2
Iaas
System Administrator
Azure
Computer Programming
JQuery
Coding
ASP.NET MVC 5
Entity Framework Core
Web Design
Infrastructure
Networking
Visual Studio
Errors
T-SQL
Ubuntu
Stored Procedures
ACME Bank
Bootstrap
Computer Networking
Entity Framework
Load Balancer
MongoDB
NoSQL
Node.js
Oracle
VirtualBox
Container
Docker
Fedora
Java
Source Control
git
ExpressJS
MySQL
NuGet
Blogger
Blogging
Bower.js
Data Science
JSON
JavaEE
Web Api
DBMS
DevOps
HTML5
MVC
SPA
Storage
github
AJAX
Big Data
Design Pattern
Eclipse IDE
Elastic IP
GIMP
Graphics Design
Heroku
Linux Mint
Postman
R
SSL
Security
Visual Studio Code
ASP.NET MVC 4
CLI
Linux Commands
Powershell
Python
Server
Software Development
Subnets
Telerik
VPC
Windows Server 2016
angular-seed
font-awesome
log4net
servlets
tomcat
AWS CloudWatch
Active Directory
Angular
Blockchain
Collections
Compatibility
Cryptocurrency
DIgital Life
DNS
Downloads
Google Blogger
Google Chrome
Google Fonts
Hadoop
IAM
KnockoutJS
LINQ
Linux Performance
Logging
Mobile-First
Open Source
Prototype
R Programming
Responsive
Route 53
S3
SELinux
Software
Unix
View
Web Forms
WildFly
XML
cshtml
githu
Awesome blog. I enjoyed reading your articles. This is truly a great read for me. I have bookmarked it and I am looking forward to reading new articles. Keep up the good work!
ReplyDeleteExcelR Data Analytics courses
Great writing! You have a flair for informational writing. Your content has impressed me beyond words. I have a lot of admiration for your writing. Thank you for all your valuable input on this topic.
ReplyDeleteSEO services in kolkata
Best SEO services in kolkata
SEO company in kolkata
Best SEO company in kolkata
Top SEO company in kolkata
Top SEO services in kolkata
SEO services in India
SEO copmany in India
There are many things mentioned in this article I would not have thought of on my own. This material is inspirational, interesting.
ReplyDeleteSAP training in Kolkata
Best SAP training in Kolkata
SAP training institute in Kolkata
If I had to give a prime example of great quality content, this article would be one. It's well-written material that keeps your interest well.
ReplyDeleteSAP training in Mumbai
Best SAP training in Mumbai
SAP training institute Mumbai
That article sounds to me progressively about group joint effort are expel the interchanges hindrance with a solid arrangement and usage, a debt of gratitude is in order for sharing this.
ReplyDeleteSEO services in kolkata
Best SEO services in kolkata
SEO company in kolkata
There are numerous things referenced in this article I would not have thought of all alone. This material is uplifting, intriguing and it permits the perusers to open up their psyches to unique reasoning.
ReplyDeleteDenial management software
Denials management software
Hospital denial management software
Self Pay Medicaid Insurance Discovery
Uninsured Medicaid Insurance Discovery
Medical billing Denial Management Software
Self Pay to Medicaid
Charity Care Software
Patient Payment Estimator
Underpayment Analyzer
Claim Status
Liên hệ Aivivu, đặt vé máy bay tham khảo
ReplyDeletevé máy bay đi Mỹ hạng thương gia
hướng dẫn đi máy bay từ mỹ về việt nam
đặt vé máy bay từ nhật về việt nam
vé máy bay từ frankfurt đi hà nội
vé máy bay giá rẻ từ Canada về Việt Nam
đặt vé máy bay từ hàn quốc về việt nam
Chi phí cho chuyên gia nước ngoài
Wonderful blog. I delighted in perusing your articles. This is genuinely an incredible perused for me. I have bookmarked it and I am anticipating perusing new articles. Keep doing awesome!
ReplyDeletedata analytics courses in hyderabad with placements
Inventateq in Bangalore offers you the opportunity to learn digital marketing and get hired at a MNC, mid-sized company, or e-commerce company.
ReplyDeleteDuring digital marketing courses in Bangalore, students learn the strategies, tactics, and methods used by digital marketers around the world.
digital marketing course in Bangalore
Inventateq's digital marketing courses will prepare you to work in the industry. Starting salaries will be below average, but will rapidly increase as you gain experience.
ReplyDeletedigital marketing training online
Really awesome blog, useful information. If you want to become a data scientist, here is the best option for you. For more information click the below link.
ReplyDeleteData Science Course in Hyderabad
By reading this article, many things have piled up in my mind which made me to think about it. You have put some high quality and valuable information here that any reader would love to read. I sincerely share many of your views in this article.
ReplyDeleteSAP training in Kolkata
SAP course in Kolkata
เสริมดวง สีเสื้อ มงคล ห้ามพลาด นักเสี่ยงโชค Pg มาเปลี่ยนแปลงชีวิตให้ดียิ่งขึ้นดังเช่นว่า เสริมดวงการคลังด้วยกระเป๋าเงินใหม่ แก้ปีชงให้สุขใจ pg และก็ที่ต้องมีให้ได้เลยเป็น เสริมดวงด้วยเสื้อ
ReplyDeleteพักสายตา netflix มาเล่น เกม pg กันเถอะ เว็บเกมสล็อตที่กำลังมาแรงมากๆ ในตอนนี้ ไม่แพ้เน็ตฟลิกซ์เลย ก็คือ เว็บเกม pg-slot.game นั่นเอง pgslot มีเกมสล็อตต่างๆมากมายกว่า100เกม
ReplyDeleteเล่นสล็อตออนไลน์ ผ่านเว็บไซต์ PG SLOT ในช่วงเวลานี้ที่การเล่นสล็อตออนไลน์จัดว่าเป็นที่นิยมเป็นอันมาก เพราะว่าผู้คนจำนวนมากรับประกันว่า ได้เงินจริง pgslot บางบุคคลมีโชคจัดหนักทำแจ็คพอตแตก
ReplyDeletePGSlot 444 นั้น คุณสามารถเข้าเล่นได้โดยตรงผ่านเว็บไซต์ของพวกเขา โดยที่คุณจะต้องทำการสมัครสมาชิกก่อนเพื่อเข้าใช้งานบริการต่างๆ PG SLOT ที่มีให้ในเว็บไซต์ ธรรมชาติ
ReplyDelete