MVC 5 Lowercase URL isn't working as expected - asp.net-mvc

I am trying to setup my MVC application to only accept lowercase URLs with routes.LowercaseUrls = true; within route config file but It seems it isn't working the way it is supposed to be.
For example I can access my MVC web app home page with both of below URLs.
http://localhost:58482/Home/indeX
http://localhost:58482/home/index
I want my application to change any uppercase letter in URL to lowercase. Is it possible?
Your help is much appreciated.

Related

How to Reorder Language Parameter In URL using URL Rewrite

We have a Ruby On Rails application on parent folder and a Wordpress Multisite hosted in a subfolder named Blog. Hosting is provided by Azure and we are using IIS.
On the Ruby On Rails app an example url is below:
http://sitename.azurewebsites.net/{language-parameter}/card.html
Note that language parameter e.g. tr comes first.
Wordpress Multisite contains sites with each site has it's own url with language parameter only.
For example the Turkish site's homepage url is
https://wxtemp.azurewebsites.net/blog/tr/
and a sample post url is
http://sitename.azurewebsites.net/blog/tr/{post-slug}/
Notice that language parameter tr comes after /blog/ directory. Although we host Ruby on Rails app on / parent folder, can we customize its web.config file and add some kind of URL rewrite rule to handle changes, so browser address bar displays Wordpress links as
http://sitename.azurewebsites.net/tr/blog/{post-slug}/
and redirects visitors to this url if they are coming from:
http://sitename.azurewebsites.net/blog/tr/{post-slug}/
We want to have same approach for urls with language parameters of other languages we use as well. Parameters we use are de, es, fr, it, ms, ar etc... So I think what we need is a rule with a regex pattern.

Is it possible to not using url for routing in MVC?

In a mvc project that we have developed for 6 months to now, we don't want to change the url when redirecting to another view. For example, our domain is xyz.net, we want customers to see only our domain name in url. Is it possible? Can we do it with mvc routing?
When we use return View("ViewName"), url is not changing. Is it meaningful to use for all in project for not changing url?
Now project contains RedirectToAction("ViewName", "ControllerName") for redirection between views, and it is changing url like "xyz.net/controllername/viewname".
How can we do without using url routing?

Running MVC application on IIS without domain

My application contains lots of links to the root ("/login/dologin"). When I'm running the application under a domain, there's no problem.
Right now I'm moving to a new server, and I can't test my application. My application sits in "localhost/md", I need the link to go to "localhost/md/login/dologin". Instead, it goes to "localhost/login/dologin", and, ofcourse, the resource cannot be found.
What do I need to configure on my IIS to make this works without domain?
Thanks.
It's just a guess, since you haven't posted any of your configuration.
In your authentication element in the web.config, do you have the route to the login page specified as /login/dologin? could you try ~/login/dologin
The second option, should give you a relative path from the home of the virtual directory application, rather than going to the root of the 'site'
For referencing files (e.g. javascript & css) you could do #Url.Content("~/path/to/file.js")
EDIT: Based on additional comments
in Layout.cshtml...
var SITE_ROOT = '#Url.Content("~/")'
then in your JS file use SITE_ROOT as a prefix in your routes
var url = SITE_ROOT + "Home/Index";

asp.net mvc using HREF in application running on IIS

There is a partial view representing pager control (very similar to this) for blog content. Code generates HTML with references and href like, "/Blog/Posts/Page/1", "/Blog/Posts/Page/2" etc.
It worked absolutely fine on Cassini, but after I switched to IIS problems appeared.
IIS application running in virtual folder, so URL is
http://localhost/tracky
and blog area located,
http://localhost/tracky/blog
As I press on pager button, I recieve 404, because the URL would be
http://localhost/blog/page/3
Instead of
http://localhost/tracky/blog/page/3
My question is, how to handle such situation? how to change code generation to provide correct URL? how to make it work same - as root applicaton or application in virtual folder?
Source code is here
You need to generate your urls either by using ActionLink in your view, or using an UrlHelper in your href as follows: <a href="<%=Url.Content("~/blog/page/3")%>" ..>bla</a>. This will generate Urls that are adjusted accoring to your application root.
You should be using the following:
UrlHelper.GenerateContentUrl("~/Blog/Posts/Page/1");
The ~ allows the url to be resolved relative to the application path and should produce correct results in both cassini and IIS.

asp.net mvc routing, ignore route with extension in the middle of url

Hi How can make the asp.net routing engine ignore routes with an extension of the type
/pathtofile/filename.aspx/morepaths
I know this is hardly a real scenario but I need to know for another similar issue for an autogenerated url
Thanks
The MVC routing engine will not intercept a url if there is a matching file on the file system. (See RouteCollection.Ignore Method) So your example url will work fine. Query strings will also work fine.
You can test this out as follows:
Create an MVC application in Visual Studio
Run it
In your browser enter the url of the Site.css file in the Contents folder.
The file will be served and the browser will pop up the "Save" dialog.
Create an html file anywhere on the site and enter the url.
Your browser will display the html page.
Create an aspx web form anywhere on the site and enter the url.
Your browser will display the web form.
Add a query string or additional path to the url.
Your browser will display the web form.
You can also do this with .asp (classic ASP) pages (although the VS web server won't serve .asp pages, you have to set the site up in IIS for that to work.)
I hope that answers your question.

Resources