Routing in ASP.NET MVC - asp.net-mvc

I want to identify categories in my site in url not by id, but by its name. When i'm adding category, which name contains "+" symbol - i have 404 error. This situation is on product internet server, when i'm deploying on local visual studio server - all work fine. Please, suggest me smth.
Example:
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "Home", action = "Catalog", id = "" }
);
http://wazy.ru/Catalog/Category/18+

Server wont throw 404 error when category names wrong. I think IIS cannot reach-invoke controller or action. Maybe this link help to figure out how to deploy.

Related

How do I identify the start page in MVC4 app?

I should preface this question by saying I have never done any MVC work before. My assignment is to move an MVC project from one server to another, and I am not sure what to set the IIS start page to. I have done some research an reviewed the app, and I found this code in the RouteConfig.cs file:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "KOOL", action = "AdvancedSearch", id = UrlParameter.Optional }
);
Does this mean the start page is Default.aspx? If so, where would I find it? I don't see it in the project (it is a large project with lots of folders).

Is possible to publish web application mvc 4 (template 4.5.2) on iis7 using file system as publishing method since vs 2015?

The application in local environment runs well, but when it's published
on live web server displays
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
I solved the problem. Yes, it is possible.
However the default page is not defined in web.config. It must be specified in RouteConfig.cs inside of App_Start directory. Something like this:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Account", action = "Login", id = UrlParameter.Optional }
);
As you can see, the absolute path is without cshtml extension, so could be put in url browser something like:
http://server:prort/Account/Login

ASP.NET MVC2 Routing IIS6 - only default routes work

I've deployed an ASP.NET MVC2 website on a Windows Server 2003 machine running IIS 6.
I'm using pretty much the default routing in a standard MVC project:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Products", action = "List", id = UrlParameter.Optional } // Parameter defaults
);
}
Navigating to http://localhost/MyApplication takes me to the List page just fine. Navigating to http://localhost/MyApplication/Products/Details/21 gives me a 404. This routing worked fine on the inbuilt development server in VS2010.
I've put in the standard IIS wildcard aspnet_isapi.dll mapping mentioned all over the place - navigating to the List page didn't work before I did - but navigating to anything other than the default route is broken.
I'd really like to keep my extensionless URLs. Does anyone have any idea as to why the routing would work for the default webpage, but no others?
*Edit: just tried adding the .aspx extension, ie now my route looks like this:
routes.MapRoute(
"Default", // Route name
"{controller}.aspx/{action}/{id}", // URL with parameters
new { controller = "Downtime", action = "List", id = UrlParameter.Optional } // Parameter defaults
);
And it has the same behaviour, except this time I get the asp 404 page instead of the html 404 page...
*Edit 2: tried it again using the following route and making sure .mvc was mapped to aspnet_isapi.dll:
routes.MapRoute(
"Default", // Route name
"{controller}.mvc/{action}/{id}", // URL with parameters
new { controller = "Downtime", action = "List", id = UrlParameter.Optional } // Parameter defaults
);
This time I got an 'Internet Explorer cannot display the webpage' 404-style page. I've now got 3 different 404 errors from using these 3 different methods...
*Edit 3 Return of the Edit: I have the site running in IIS 5.1 on Windows XP professional with only a wildcard remapping on the virtual directory, but heaven forbid I can get it to run on the webserver...
First of all, you should follow this walk-through: http://haacked.com/archive/2008/11/26/asp.net-mvc-on-iis-6-walkthrough.aspx
(just to make sure you've not missed something). This shows how to get the extension-less and extention'd versions working. You might want to at least check whether the extension'd version works to check that other things aren't misconfigured.
After that, perhaps you should try adding something like this..
http://haacked.com/archive/2008/03/13/url-routing-debugger.aspx
... as it can really help in determining where your routes are broken.
Some other things to check:
Is IIS configured with ASP.NET? Check properties of the virtual directory. On the VDir select the configuration button and check that the usual ASP.NET extensions are mapped to the .NET 2.0 ISAPI dll. This will be something along the lines of
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll.
Is ASP.NET 2 enabled on IIS (under IIS 6 this is off by default): in IIS manager check the Web Service Extensions folder to enable it.
Have you deployed global.asax?
Found it - the routing is actually working, my URLs were not. I was using javascript to build some of the URLs and it turns out that I wasn't linking to
http: //localhost/MyApplication/Controller/Action/ID
I was actually linking to
http: //localhost/Controller/Action/ID
Building the links like this was working on the development server, but once the site was deployed to a virtual directory on the webserver those addresses are incorrect because of the extra application name in the URL.
In conclusion, be careful with your URLs - don't build them out of strings like I did.

.net MVC 2 default Route suddenly stopped working

today the default route for my site stopped working, but the strange thing is that the global.ascx has not changed at all.
when i enter the URL mysite.com/
i get this 404 error
The resource cannot be found.
Requested URL: /Views/Start/Index.aspx
i have a bog standard default MVC route
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "Index", action = "Index", id = "" }
);
the oddball thing is that even if i create a Start folder with a copy of my index view, it still doesn’t work and throws the same 404 error.
has anyone else had this issue ??
any help is most appreciated
Truegilly
Re-add ASP.Net MVC's default Default.aspx file to the site root.
This file forces requests to / to run through the routing engine.
Although not necessarily the answer to this question, when Haack's debugger is showing that your routing tables are set up fine but you're still getting 404s, check your Controller is public!

How to handle empty URL in ASP.NET MVC

How do you set up the routing to handle http://mysite.com/Foo?
Where foo can be any value. I want it to go to /Home/Action/Id where foo is the id.
These are the mappings I have tried:
routes.MapRoute("Catchall", "{*catchall}",
new { controller = "Home", action = "Index", id=""});
routes.MapRoute("ByKey", "{id}",
new { controller = "Home", action = "Index" id=""});
They both generated a 404.
Thanks for any help.
Try this (note you had a missing comma in your original post):
routes.MapRoute("ByKey", "{id}",
new { controller = "Home", action = "Index", id=""});
I would, however, make it a bit more explanatory to prevent clashes later, even if it means a bit longer URIs:
routes.MapRoute("ByKey", "ByKey/{id}",
new { controller = "Home", action = "Index", id=""});
And place this as the first MapRoute command. Order does matter there, and the first route you add is the first route for a URL to be tested with.
Your second route is correct. It should work. Maybe you have another routes above? Debug your routes with Phil Haack's ASP.NET Routing Debugger
Steps to solve
Right click on the project
Go to web tab of the page.
My Start URL was found to be empty
I copied what in Project url of Servers section
Pasted at Start Url
It worked.

Resources