A default document is not configured for the requested URL - asp.net-mvc

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

Related

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

Help with MVC view

When I create new MVC 3 project in Visual Studio the first thing I do is create a new controller called Home, and then right click in the Index stub and create a new view.
My question is when I have the Index file selected in the solution explorer and build the solution I get an error saying it can't be found. If I navigate to the page using root/ Home or root/Home/Index it still doesn't work.
I also created a new project using the sample website that ships with MVC and cannot figure out what code differs between an empty solution and the sample solution that could be giving me this problem. In the global.asax it looks like there is already a route setup for a home controller so I'm confused.
Your controller class should be called HomeController, not Home. On the screenshot you've shown I see that you've called it Home. By convention all controller classes in ASP.NET MVC must have the Controller suffix. In Global.asax you should have a default routing rule which states:
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
which means that when you run the site and you request / it will look for the Index action on the HomeController.
I am unable to reproduce with Microsoft Web Developer 2010 Express, ASP.NET MVC 3 and creating a new empty Razor-view project. When you choose "Add View" did you enable "Create as a partial view"? If so, that may be the issue. Did you enable "Use a layout or master page" and select an existing master page? If not, that may be the issue...
The routing looks fine in an empty project. I see the Home/Index view with these URLs:
/
/home
/home/index
Post problematic project as .zip?

Default route problem

If I want to hit a url like
http://localhost:8080/controllername
I want the "Index" action to be the default action called. I assumed the default route mapping would be fine and the "Index" action would be called on whatever controller was specified - seems I need to specify
http://localhost:8080/controllername/index
Is this correct?
Mapping:
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
What you're trying should definitely work. In fact, the code you posted is from the default templates, and I've just tested it by adding an "Index" action to the AccountController and visiting /Account in my browser.
I'd recommend creating a new project and testing this behaviour (first with the built-in web server, then with IIS, if you're not always using the built-in server). If it works, there's probably something different in your project that's causing the issue.
I had a similar problem and it occured because of a collision with a directory in the project. I had a structure like this in my project:
Controllers \
HomeController.cs
CmsController.cs
Cms \
WhateverFile.cs
The Cms subdirectory collided with the /Cms URL, while Cms/Index worked. I simply renamed my colliding folder name. If you have to keep it, there is a RouteCollection.RouteExistingFiles that can be used to prevent automatic lookup of files. If that is enabled I think that a lot exclusions have to be added for the Script etc, see this blog post for an example.

ASP.NET MVC - Running in a Subdirectory

I am attempting to deploy an ASP.NET MVC application in a subdirectory of an existing application and I am running into some routing issues. I have set up the folder structure such that all of the binaries and config files for the MVC app are correctly located in the root directory, while the rest of the content is in the subdirectory. Additionally, I updated all of the routes in the MVC application to reflect the subdirectory; however, every request to the application produces:
The incoming request does not match
any route.
All defined routes are being ignored, including the default route:
routes.MapRouteLowercase(
"Main_Default",
"blog/{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = "" }
);
I tried enabling RouteDebug to test the issue, but even that is not getting routed to. Any advice on what else I can try?
Note: This question is not a duplicate.
Try running it as a virtual directory instead of just a directory, otherwise your routes are not going to be called. You will not need to put the name of the virtual directory in the route.
Here's a route that I have setup in a v-dir MVC app that works just fine...
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Tour", action = "Index", id = "" } // Parameter defaults
);
Looks like I found the problem.
In addition to the binaries and the config files, Global.asax must also be placed in the root in order for its code to be executed.
Thanks guys. :)

Strange route problem in ASP.NET MVC - default route not hit

I have this two routes currently in my application after decommenting out many other ones. Let me first explain that I have quite a big application already but have come to a problem where my application does not start at the root url anymore.
If I set starting page to default.aspx then webapp starts at (example) http://localhost:55421/Default.aspx. I don't want that. I want it without Default.aspx
So I went into app properties and removed Default.aspx as starting page - now it is blank field (just like in a sample new MVC app if you create it in VS 2008).
But now application does start at the required URL but issues an error:
"The incoming request does not match any route."
Also If I use route debugger it also misses all routes and catches it by catchall route.
I don't know how all of this is possible since as I said above I have two default routes configured at this time:
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default",
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Pages", action = "Display", slug = "Default" }
);
Any help appreciated
Am I right in thinking you are trying to hit
http://server/{controller}/{action}/{id}
with
http://server/
If you are I think you need to provide a default for the last parameter {id}. You have a default for a parameter slug but without a default for {id} I don't think ASP.NET Routing can hit it.
If I'm right
http://server/Pages/Display
should also not hit the default route, because you are expecting id in Display?
HTH
Alex

Resources