I am developing mv4 website,
would you please tell me why these command do not do anything in my application when I write them into RouteConfig:
routes.LowercaseUrls = true;
routes.AppendTrailingSlash = true;
First up, you need to be generating the routes via something @Html.ActionLink
, @Url.Action
or similar for anything to work. It's not a magic bullet.
From MSDN:
AppendTrailingSlash
Gets or sets a value that indicates whether trailing slashes are added when virtual paths are normalized.
(Source)
LowercaseUrls
Gets or sets a value that indicates whether URLs are converted to lower case when virtual paths are normalized.
(Source)
The URL format is (source):
scheme:[//[user:password@]host[:port]][/]path[?query][#fragment]
The portion of that this affects is the path portion and that only. Any query-string portion is unaffected. AppendTrailingSlash adds a / to the end of the path portion.
So for this code:
@Html.ActionLink("About this Website", "About")
With the route parameters set to routes.LowercaseUrls = true;
and routes.AppendTrailingSlash = true;
it would generate:
<a href="/home/about/">About this Website</a>
With the route parameters set to routes.LowercaseUrls = false;
and routes.AppendTrailingSlash = true;
it would generate:
<a href="/Home/About/">About this Website</a>
With the route parameters set to routes.LowercaseUrls = true;
and routes.AppendTrailingSlash = false;
it would generate:
<a href="/home/about">About this Website</a>
With the route parameters set to routes.LowercaseUrls = false;
and routes.AppendTrailingSlash = false;
it would generate:
<a href="/Home/About">About this Website</a>
For this code:
@url.action("someAction","someController",new{Name=Test})
With the route parameters set to routes.LowercaseUrls = true;
and routes.AppendTrailingSlash = true;
it would generate:
/somecontroller/someaction/?Name=Test
Some bugs that you could be hitting:
There is a bug with areas in MVC 4, in regards to lowercase Urls.
The NuGet package LowercaseRoutesMVC preports to fix this bug.
Possible solutions to lowercase URLs on your Application
If you're wanting to alter behavior outside of the app, consider using something like Url Rewrite for IIS which can transform your URLs. Example of this here.