wildcards in asp.net mvc routes - asp.net-mvc

i'm using asp.net mvc with vs2008 and IIS7.
What i want to accomplish is that all requests that START WITH 'summer' are routed to the same controller.
'till now i've built tons of routes, but they were all for one path (with parameters offcourse) but this one must route:
www.mysite.com/summercity
www.mysite.com/summermadness
www.mysite.com/summer
www.mysite.com/summerweather
to the same controller.
the only solution i've come up with is 'summer*', but that didn't work :)
Michel

You can use:
/Summer{*Data}

Related

Debug Attribute Routing in ASP.NET

The AttributeRouting package contains a handler called LogRoutesHandler that "emits the routes in the RouteTable to a browser".
Is there something similar in the new MVC5 attribute routing functionality?
I also miss the routes.axd feature of AttributeRouting in ASP MVC 5. I am using currently using Glimpse to debug routes. It's not quite the same, far from friendly compared to routes.axd, but it helps.

When deploying an ASP.MVC 3 application to a subfolder (not root), how do I handle routes?

I'm developing an ASP.MVC 3 project on my local computer where it is located at the root of the local web server.
localhost:12345/(project is here)
However, when I deploy to our public web server this application will be located in a subfolder
www.mycompany.com/myapp/(project goes here)
How do I deal with that mismatch? A few questions come to mind:
Do I need to adjust my MVC routes? Or will they just capture anything after /myapp/ ?
Do I use HomeController when I don't really want 'Home' to appear in the route? i.e. /myapp/home/(action)/(id) - rather I want this: /myapp/(action)/(id) if Home is the controller.
Should I match this folder structure on my local machine? (This project will never have access to anything outside that 'myapp' folder)
If 3 is yes, how?
I'm using VS 2010 with IIS Express locally.
The routes are relative to the web application. Which means that you don't need to have /myapp/ in your routes.
No you don't need to have Home appear in the route. Personally as a practice I take out the default route.
No you don't need to match this folder structure.
In our experience I found that within the Controllers there is no problem with the routes.
However, if you use HTML helpers within your views, like Html.BeginForm or Html.Action, these do not work with the overloaded methods that receive controller, action arguments. You need to put the whole Url in the Html helpers using Url.Content,
This does not work:
Html.BeginForm()
or
Html.BeginForm("ResetPassword", "Account")
But this works:
Html.BeginForm(Url.Content("~/Account/ResetPassword");

Integrating ASP.NET MVC 2 with classic ASP

I'm in the process of moving a large classic ASP application to ASP.NET MVC 2. Questions:
My question is about project organization.
I would prefer to not mix the MVC code with the ASP code in the same VS project. I'd like to have an MVC WAP with areas that match the parts of the website that I'm migrating. For instance, the old site has a folder
/products/default.asp.....
/products/productName/default.asp
etc.
In the MVC WAP, I'd like to have an area called "products", which I could then, either through a rewrite, routing, or preferably through some IIS configuration, point the "products" folder on the ASP site to. In this way, I could gradually move root folders from the ASP site to the MVC application.
However, if I create the MVC WAP in a virtual folder, then my routes wind up looking like
http://localhost/virtualFolder/products
instead of
http://localhost/products
Any suggestions on how to conquer this?
I know that, during deployment, I could deploy the MVC WAP into the root of the ASP site, but this doesn't help with debugging.
I'll write my answer assuming this is hosted on an IIS7 instance. If it's IIS6, then you'll need to look for a suitable ModRewrite module for it.
So, assuming IIS7, you'll be far better off using URL Rewrite:
http://learn.iis.net/page.aspx/460/using-the-url-rewrite-module/
You can manage your rewrite rules and rewrite maps, depending on your level of access and control, either from within the IIS7 Administration Console, or manually via your web.config file.
These rewrite rules and maps can be as simple or complex as you need them to be. You can also set them up to be either a temporary or permanent redirect - which will assist if any search engines are indexing the site as the correct redirect code will be returned with the HTTP request to ensure crawler results are updated promptly.

Trying to make Weborb .NET work with ASP.NET MVC

We have been using weborb for .net on an existing application for some time now and it has worked very well. We decided to rewrite our application in ASP.NET MVC and now I need to make weborb work with mvc. I have been getting a 404 the resource cannot be found error while trying to connect to the weborb.aspx page. I have added all of the appropriate entries to the web.config file and I even found this article explaining how to make the two work together
http://aspzone.com/tech/how-to-get-weborb-and-asp-net-mvc-to-work-together/
But to no avail. I can't make it work. Thanks.
If 404 is given then there is no such resource. Most likely the MVC tries to route the request and cannot find appropriate one.
Try to add ignore route in the beginning of routes registration. Something like this:
routes.IgnoreRoute("weborb.aspx/{*pathInfo}");
My problem was that I had the project set up incorrectly as a website and not an mvc application. Once I did that the route explained the blog post I referenced worked like a charm.

Unit test that aspx pages get routed correctly?

I have a hybrid ASP.NET MVC application, and I'd like to test that the route table properly allows my .aspx pages to be loaded. In particular I'm interested in making sure that the root of my site goes to index.aspx, not to a controller.
Update: You can test for the Ignored paths in the routing table. However, this doesn't test for the route on the root if you haven't provided a default controller. The routeData comes out null.
MvcContrib has a RouteTestingExtensions class in their TestHelper. This is how I test routes. The tests end up looking like this:
"~/computer-accessories/".ShouldMapTo<CategoryController>(x => x.Accessories());
You could try Phil Haack's route debugger, although what Craig said is correct.
Well that's easy. Root always goes to Default.aspx, even in "pure" MVC. MVC apps have a special Default.aspx to reroute to Home/Index. Yours will be a real page, instead.

Resources