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).
Related
I have an ASP.net MVC 5 site. The home page is at http://mydomain.
However, there's also a second route to the home page - http://mydomain/home/index - which I think
This causes problems because it may be seen as duplicate content, and images are broken on this page.
How can I totally remove this route (so it goes to a 404, I guess?).
I've searched Google but can only find articles on removing Home from routes entirely - not what I need.
I'm using Attribute routing, and this is all that's in the RouteConfig.cs:
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
// Enable Route Attributes in Controllers
routes.MapMvcAttributeRoutes();
// Fall through all routes
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
The Home Index action has no attribute route on it (as you'd probably expect?). This /home/index route works even on newly generated MVC projects - which I think is a bad idea?
How can I do this?
Are there any problems with removing this route I may not have considered?
thx.
You can block unintended routes that you don't want by using IgnoreRoute().
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("Home");
routes.IgnoreRoute("Home/Index");
// Enable Route Attributes in Controllers
routes.MapMvcAttributeRoutes();
// Fall through all routes
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
However, if these URLs are already in the wild, you should instead setup a 301 redirect to the canonical URL you intended. The simplest way to do that is with the URL rewrite module.
This /home/index route works even on newly generated MVC projects - which I think is a bad idea?
I see this as more of a blessing in disguise. It is an advantage over any SEO competitor using MVC who doesn't do the extra work to remove these routes when you are the one who does.
This is not necessary.
The default route provides optional controller and action names. So if user does not put any name for controller and/or action in path (/Home/Index or /Home in this situation) asp.net will put the right values in application routing.
Whenever you use Url.Action or Url.Route functions it will produce the shortest link for you. So in your website there will be always http://mydomain produced for your root. And for example Category > Index action it will produce http://mydomain/category.
In your website bots will never get to duplicate content if your links are in this way. If you are writing your links manually write as short as you can or simply use Url.Action.
About the images there must be something different, because images are static files. just use "~/imagefolder/imagename.jpg" way to get them. "~" is important to start link from the root of application if you are making your application work on a subfolder in IIS.
Creating a new section to my MVC site called "Reports".
Created a simple controller and starter Index view.
If I try to browse to ".../Reports/Index" things work fine. I am greeted with my page.
If I try to browse to ".../Reports", I get the message listed in the title. (...default document not configured...)
When I try the same with another section like ".../Customers", I get my index page... so, I think my routing is setup properly.
Here is my RouteConfig just in case:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new {
controller = "Home",
action = "Index",
id = UrlParameter.Optional }
);
I must be missing something simple related to the new reports page, but I just can't see it. I need some fresh eyes.
I had another folder name "Reports" at the top level of the directory tree in my project. I had planned to, well, put the reports in there. Anyway, MVC did not know which folder to route to, since there were to folders name "Reports" in my project.
Just to test the fix I renamed the report storage location to "Report" (dropped the "s"), ran again and tada... MVC is happy again.
I suspect the issue was because you had a SQL server with SQL Server Reporting enabled, as it will take over the Reports folder name.
As The answerer pointed out if you rename the folder it avoids SQL server Reportings use of the alias
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
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!
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.