Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.Net MVC url design & structure guidelines

I wanted to get some expert suggestions on designing urls for our web app. This is not a public domain website, it is a supplychain intranet based web-app used only by a group of authenticated users.

Here're some examples -

/Claim/12/Manage
FORMAT: controller/{ID}/action

The url that points to a "Claim Entry" wizard. Here "12" is the ClaimID. It is further divided into tabs for sub-data entry. Example: /Claim/12/Print, /Claim/12/FileDetails, ...

/Users/List
FORMAT: controller/action

Display's a list of existing users in Grid. Shud this be shortened to "/Users" ? Likewise we've some other entities as well like "Roles, Organizations, etc..."

/Master/Manage/FileType
FORMAT: controller/action/{argument}

We've a page which allows he user to manage different master table data. Need to know which master table is selected (i.e. sent as argument). Is it better to simplify it as "/Manage/{argument}" instead and then map that url as required above?

  • Is it sensible in MVC to hide default actions like "Claim/21/Manage" shud be "Claim/21", "/Users/List" shud be "/Users" ...
  • Arguments - are they better as embedded in url or good to append as query-string

Any generic guidelines or references would also be great.

Ref: Web services url - (Section: Designing the URI Templates) http://msdn.microsoft.com/en-us/library/dd203052.aspx

like image 758
Hemant Tank Avatar asked Dec 10 '11 13:12

Hemant Tank


2 Answers

You can use Regular Expressions to represent various routes you have. For example

protected void Application_Start()
{
RouteTable
.Routes
.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL template
new { controller="Mycontroller", action="Myaction", id=UrlParameter.Optional },
new { action = @"\d{2}-\d{2}-\d{4}" }
);
}
like image 130
amesh Avatar answered Sep 20 '22 12:09

amesh


Well, I conclude that this one is the best (and probably the most detailed) explanation I can find on MSDN - http://msdn.microsoft.com/en-us/library/dd203052.aspx

And that shud be sufficient :-)

like image 43
Hemant Tank Avatar answered Sep 18 '22 12:09

Hemant Tank