Resource Not Found - 404 - asp.net

So, I've copied a few methods from one controller to another, moved the respective views into the correct view folder and tried to debug my project..
After trying to navigate to one of the newly copied methods and views I get hit with this lovely error.
Server Error in '/' Application.
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.
Requested URL: /subscriber/addphonenumber
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.6.57.0
Now, I've double and triple checked that the views are in the right folder, even deleted them, went to the controller actions, right click -> add view and copied the view code over and still no joy.
The controller actions are there, the views are there, what gives?
I've tried cleaning the project, the solution, closing VS and restarting and still... nothing.
Also, when debugging, my breakpoints are never getting hit on the newly copied methods... Not sure what is going on there.
Note: I have NOT made any changes whatsoever to any of the routing configuration, I simply copied the ChangePassword, AddPhoneNumber and VerifyPhoneNumber actions/views from the Manage Controller and Views folder to my Subscriber Controller. These methods and views worked fine before I moved them.
Questions:
Why is Visual Studio not hitting my breakpoints
Why are these views and controller actions not being recognized?
EDIT
I resolved this issue, check below to see my answer.

The solution in my case ended up being this.
I had an area in my project with the same name as a controller in the root controllers folder, that was causing a routing issue and in turn the 404 error. The routing issue prevented my actions from being found, hence the breakpoints not being hit. After removing or renaming the area, everything seems to be working fine.
Project Structure
areas/subscriber - empty
controllers/subscriber
views/subscriber/index
views/subscriber/addphonenumber

Related

API setup missing something?

I am setting up a web api for the first time and I have another project for reference. It is a .NET framework project that will have a React frontend. I am running it using Visual Studio and IIS Express.
I have no build errors when I start the api project. It has swagger added so I can test database calls, so I know the api itself is working. But I am missing adding something as I am looking to add more security to it.
I am trying to verify authentication and I want to use integrated Windows authentication. When I set a break point, the user in the HttpContext.Current is never set and is never authenticated, so I can't add any authorization filters.
I went back to just the basic empty api project that has the frontend web pages removed to see if I removed something and it shows the same issue. So I either removed it again or I am actually missing adding something.
I am not sure where to look for what is missing, so any pointers would be appreciated.
The left browser is what I am expecting and the right browser is what I am seeing.
I don't need the directory browse turned on, so seeing a 403.14 - Forbidden is fine. But I am clearly missing something to get to that point. Is there a better way to figure out which resource/dependency is causing this error?
I can also see the working version requested url is what I am expecting, but the other is just a /.
Is there a way to resolve that if this is the error?
I can add code snippets if needed, but I haven't yet as I am not sure where the issue is.
I ended up finding the answer using blank test web apis to see what I may have left in that wasn't needed. The project was set up using this option:
After removing the views, etc., to make it strictly an api project. I started removing references (and clearing the associated errors) and seeing what happened with the build after each change.
Under the App_Start folder, there were some additional files that weren't present in the project I had for comparison - FilterConfig, and RouteConfig - which were also called in the Global.asax.
I removed the call in Global.asax for all three and I was able to see the expected http error page.
I dont have enough reputation for a comment, but you got 404 error, which, as you know, means there is nothing on that url. So check the route config and startup.cs Edit: I am on the phone so I didnt saw you already solved it. Good :)

Azure - Uploaded MVC Project returns 404

Using Visual Studio 2019 I tried to Publish the MVC Project I've been working on. It goes well, but the default route returns a 404 Not Found. Other routes for login/register load the correct html content. This all works well on my localhost. I've been searching around but can only find things relating to Angular etc.
The index page loads content from a database, which I haven't set-up yet if that causes any issues?
Any help is appreciated as I'm boggled.
Issue solved. For anyone wondering in the future, if the page reads content from a database make sure the Migrations are applied and the database is exactly how it is on your local machine (This was my issue anyway).

HTTP 404.0 Error Local IIS Site

I have several IIS sites running on my local machine running IIS 8. 3 of the sites work perfectly fine, the 4th returns a 404.0 Error:
"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 have tried everything I can think of but nothing will work. To save people some time I will list some of the things I tried:
Adding UrlRoutingModule to my Web.config
Removing the WebDAVModule
Adding ExtentionlessURLHandlers
I have also confirmed that the path is correct and the site is in the correct application pool. I am running out of things to try everything I see on the web seems to say one of these things I tried will fixed it but it hasn't. My IIS local web server seems to be installed corrected as my other sites work fine, please help!!
After a very frustrating day I solved my issue, and it was really due to my last of MVC routing knowledge. I was attempting to navigate to "localhost/example" which had not controller routing associated with it because I had no home controller. I either needed to map a home controller to it, change the default controller to map to one of my existing controllers, or the easiest fix was to navigate to "localhost/example/controllername" where "controllername" is the name of the controller that I wanted to start at. I hope this can save someone else hours of time.

MVC3 Server Error in '/' Application

I'm not new to ASP.NET MVC but I have a really strange issue that I haven't been able to solve. I've checked most other related queries on SO and further afield but I haven't yet found a solution. I have a really simple ASP.NET MVC 3 application running under Cassini which was working fine until I added log4net logging. I've since removed all the references to log4net to try and get it back but I always get the error:
Server Error in '/' Application.
The resource cannot be found.
HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed blah...
This is the result, no matter which url is requested.
The application still has the original HomeController, Index.cshtml etc and the default route from the standard 'out-of-the-box' Visual Studio 2010 template.
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}
I've checked and double-checked that there is no file missing (e.g. a css or js file) thats required and another issue which prevents me from moving forward on this issue is that no breakpoints are hit when trying to debug it. In fact, if I put a breakpoint on the first line in the Application_Start method, and start debugging, the breakpoint is not hit at all and a second breakpoint appears (see the image below)!
This happens even if I do a clean and rebuild.
I've tried using Phil Haacks Route Debugger but still get the same error and the fact that the Application_Start breakpoint is not being hit makes me suspect my web.config. I've checked it several times and in fact replaced it with a web.config from my hosted site where the application is running ok, but still get the same result on my development setup.
I've checked there is no StartUp page in the properties.
I want to add some more functionality and be able to debug it before deploying to my hosted site but this is stopping me.
Has anyone come across breakpoints being added when you start debugging? Considering the symptoms, where would you start looking for the root of the problem?
Just solved it, so for those who might trip over this one, I've noted the reason why below. However, what might be of more value was my approach to find the issue in the face of no debugging or tracing available. As it is still a small site I decided to create another standard 'out-of-the-box' MVC 3 application and manually compare files. There appeared to be no difference between files but while going through this exercise I noticed that in the problem application, the Global.asax files were sitting in the Views folder! I must have inadvertantly moved them - it wasn't immediately obvious because the Views folder was always expanded and glancing at it, would appear that the Global.asax files were in the right place because they are normally immediately below the Views folder (just not indented as they are when inside the Views folder).
Anyway, problem caused by me but did cause some weird behaviour!

Web.Routing for the site root or homepage

I am doing some work with Web.Routing, using it to have friendly urls and nice Rest like interfaces to a site that is essentially rendered by a single IHttpHandler. There are no webforms, the handler generates all the html/json and writes it as part of process request.
This works well for things like /Sites/Accounting for example, but I can't get it to work for the site root, i.e. '/'.
I have tried registering a route with an empty string, with 'default.aspx' (which is the empty aspx file I keep in my root folder to play nice with cassini and iis). I set RouteExistingFiles to false explicitly, but whatever I do when hitting the root url it still opens default.axpx, which has no code it inherits from, and contains a simple h1 tag to show that I've hit it.
I don't want to change the default file to redirect to a desired route, I just want the equivalent of a 'default' route that is applied when no other routes are found, similar to MVC.
For reference, the previous version of the site didn't use Web.Routing, but had a handler referenced in the web.config that was perfectly capable of intercepting requests for the root or default.aspx.
Specs: ASP.NET 3.5sp1, C#, no webforms, MVC or openrasta. Plain old IHttpHandlers.
Fixed my own problem: the issue is the integrated web server, Cassini or some such. Seems that it doesnt play nice with routing, and will by default simply return the default.aspx file or, if it is missing, show a directory listing.
Using IIS with a virtual directory works fine, but is annoying (frustrates code sharers because they need to set up new virtual directories when they open my app, and pollutes my own IIS instance. Bah. Probably what I'll do for the moment however, or setup a new application manually so I can use the domain host only path like what will exist in live.
An alternative is to use the updated version of cassini, seen here, which works if the default.aspx file is missing, but I have not worked out how to integrate it with visual studio yet. Any help would be appreciated, but its not a big priority given I have workarounds.
I realise that this is a really old post, but I just ran into the same problem using VS2012, so I'm posting this here just in case.
I solved the problem by installing IIS Express and setting the project to use IIS Express in Visual Studio. Solved the problem.

Resources