Deploy .net MVC 2 application on IIS6 - asp.net-mvc-2

I want to deploy my .net MVC 2 application on IIS6.0.
Will it require to change route path in global.asax file.
In my application i have used html link, ajax request and Html.ActionLink.
The code lines in the Global.asax file are:
routes.MapRoute(
"LogOn",
"{controller}/{action}/{id}",
new { controller = "Account", action = "Index", id = UrlParameter.Optional }
);
Please suggest me.

MVC2 works just fine in IIS6, though there are some gotchas with the 4.0 framework. Your routes won't be a problem, but you'll have to add a wildcard map for aspnet_isapi.dll to enable extensionless URLs.

Can't see a reason why it won't work. The routes don't need to be setup differently if you intend to deploy to IIS6.
The best way to find out is to try it ;)

I just put in an extension to tell iis to use the asp_net.dll. My urls aren't as pretty, but they work. i.e. they are like http://example.com/Home.aspx/ActionName/Id
routes.MapRoute(
"root", // Route name
"", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
routes.MapRoute(
"Default", // Route name
"{controller}.aspx/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);

Related

MVC routing not working when default and custom route refer to same controller

I have two routers in my global.asax, one is a default router which is like:
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}",
new { controller = "Test", action = "Action1", id = UrlParameter.Optional }
);
and other is Custom router:
routes.MapRoute(
"CustomRouter", // Route name
"Test/{id}/{FacetString}/{CurrPageNo}",
new { controller = "Test", action = "Action12", id = "", FacetString = UrlParameter.Optional, CurrPageNo=UrlParameter.Optional }
);
some how when I pass url "http://localhost/Test/1001/State=TX" the second router should get executed but some how its not executing.
I had read that the sequence of router is important, hence I tried to exchange there sequence, but it is still not working, if I place it above default router than, the cutom router gets called for all the other actions in that router, which should not happen
the last URL-component State=TX looks like a query string parameter to me. Shouldn't it be ?State=TX (which then wouldn't match your route) or /State/TX
it seems like you should use constraints, reducing match rate for your custom router. You can use forth parameter to define your constraints. In this case it can be something like this
routes.MapRoute(
"CustomRouter", // Route name
"Test/{id}/{FacetString}/{CurrPageNo}",
new { controller = "Test", action = "Action12", id = "", FacetString = UrlParameter.Optional, CurrPageNo=UrlParameter.Optional
, new {id=#"\d+"});
in this way your second URL section requires to be numeric in order to get executed.
According your second route your url should be in one of these formats
http://localhost/Test/1001
http://localhost/Test/1001/State
http://localhost/Test/1001/State/3
Also there is no need of controller = "Test", action = "Action12" as they are not part of the second route definition
Have a look at this MSDN link on ASP.NET routing

Asp.net Mvc 2 How to reroute to www.example.com/my-profile

i would like to reroute this address www.exmaple.com/my-profile to a profile controller i have in my mvc application. There is my global.aspx, as you can the the default routing is
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}/", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
This is the Maproute i'm trying to use to reroute to www.exmaple.com/my-profile
routes.MapRoute(
"Profile", // Route name
"{profile_name}/", // URL with parameters
new { controller = "Portfolio", action = "Index", page = UrlParameter.Optional } // Parameter defaults
);
The problem is when i type www.exmaple.com/profile it trys to direct me to the default maproute, not the one i have specified.
But when i can do this www.example.com/profile/my-profile
routes.MapRouteLowercase(
"Profile", // Route name
"profile/{profile_name}/", // URL with parameters
new { controller = "Portfolio", action = "Index", page = UrlParameter.Optional } // Parameter defaults
);
it works fine, but i dont want to add profile before my-profile. I would like it to work like facebook.com/my-profile or youtube.com/my-profile.
Does anyone one know how i accomplish this, i have been looking for a solution for over 2 months (on and off)
Thanks
Your routing if I remember rightly will return the first matching pattern for the URL. I would expect in your case, your URL is matching your default pattern first.
Move your more specific route above your 'default' route and see if this helps.

MVC 2 multilanguage in URL

I'm building a multilanguage application with MVC 2. I read a lot of posts about different ways to get the user's language. I think the best way to save the language, is to put it into the URL like this: www.example.de/language/controller/view.
My questions:
1. how should global.asax.cs look? I tried it to setting something below but it did not work:
routes.MapRoute("Default with language", "{lang}/{controller}/{action}/{id}", new
{
controller = "Home",
action = "Index",
id = UrlParameter.Optional,
}, new { lang = "de|en" });
routes.MapRoute("Default", "{controller}/{action}/{id}", new
{
controller = "Home",
action = "Index",
id = UrlParameter.Optional,
lang = "en",
});
There was a "en" for example in the route, but it always did not take the Resourse.en, it only took the default.
Question: How to get the current language in the controller?
Question: How to change the language?
Maybe this can help?
MVC Localization route

asp.net mvc2 Routes

So I have added this route to my map:
routes.MapRoute(
"Default",
"/Bikes/{id}",
new { controller = "Bike", action = "Detail" }
);
But for SEO reasons we need to have urls like: /bikes/54/name-of-bike/kind-of-bike/number-of-wheels ... etc etc. But everything after id (54) can be ignored.
Does anyone know how to create such a MapRoute to allow that, the route above does not work actually for urls that contain stuff after the id.
You can use a catchall parameter like so
routes.MapRoute(
"Default",
"/Bikes/{id}/{*stuff}",
new { controller = "Bike", action = "Detail", stuff = UrlParameter.Optional }
);
then anything after id will be stored in stuff
Something like this
routes.MapRoute(
"Default",
"/Bikes/{id}/{slug*}",
new { controller = "Bike", action = "Detail",
slug = UrlParameter.Optional}
);

Problem with custom routes

I'm using the following route
routes.MapRoute(
"PatientList",
"User/{SearchName}/{LocationID}/{Page}",
new { controller = "User", action = "Index", SearchName = "", LocationID = 0, Page = 1 }
);
It fails on the following URL: /user//1/1
Can anyone tell me what I'm doing wrong?
The URL /user//1/1 is interpreted by ASP.NET as a request for /user/1/1. Only the last parameters can be optional. You can't skip a parameter this way.