Web API 404 File or Directory not Found for "root" routes - visual-studio-2010

I am developing a RESTful web api service. It's web api v.1, not v.2. Also I am developing on Visual Studio 2010 SP1. I have installed the MVC 4 for VS2010 SP1.
Please understand and keep in mind that Upgrading to newer versions of VS or Web Api 2 is not an option.
I have the following problem after a Windows Update ocurred.
When I try to use my RESTful api this way....
http://url.com/documents/ (get all the documents) I get the following error...
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.
Here is the stack trace.
[HttpException]: File does not exist. at System.Web.StaticFileHandler.GetFileInfo(String virtualPathWithPathInfo, String physicalPath, HttpResponse response) at System.Web.StaticFileHandler.ProcessRequestInternal(HttpContext context, String overrideVirtualPath) at System.Web.DefaultHttpHandler.BeginProcessRequest(HttpContext context, AsyncCallback callback, Object state) at system.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
If I specify the action name directly, it works. For example...
http://url.com/documents/get (gets all the documents) or
http://url.com/documents/7 (gets document id=7.
It only fails when you call it by its default name. I have already read similar situations here and I have tried to follow their solutions but they are not working for me properly.
Now, I know this is not a "web api routing" issue because I actually get the .net default exception page html markup (I am using Postman to test my webservice). When I force a "routing issue", then I get a JSON error description, which means that the Controller actually got created in the pipeline and returned a response.
Also, I have a custom file (SecurityHandler) that inherits from DelegatingHandler. This file gets executed almost first in the pipeline with each call to the api. Even before the actual Controller. Well, this file is never called when I get the error, which confirms to me that the "webserver" (either VS Development Server or IIS 7) is the one throwing the exception.
I have exhausted every single solution that I have found here. Change my web.config to multiple handlers configurations, re-installed MVC 4 for VS2010, created an entire new project... all these efforts have shown no results whatsoever.
Like I said, this was working perfectly fine until my pc restarted from a Windows Update BUT... why does it fail in the server as well? I did deploy my api to the server after the error started to occur.
Thanks.

The issue is not in Web API (and has nothing to do with it's version or Visual Studio 2010), it's the static file handler trying to serve and failing.
Alternatives:
0. Do you have a documents folder in your site? Get rid of it.
1. Remove the static file handler for directory browsing and re-add it.
2. Use RAMMFAR (less recommended)

Related

Bot Framework emulator not posting to localhost after renaming my solution (500 error)

I created a Web App Bot in Azure with a basic template, downloaded the files and tested it with no problems on localhost with the Bot Framework Emulator.
However, once I renamed the solution/project/namespaces from the default Microsoft.Bot.Samples.SimpleEchoBot to MyBotName, the Bot Emulator received 500 - Internal Server Error.
The solution builds and runs, and setting a breakpoint in the MessagesController shows that the Post method is never reached.
How do I fix this?
A GET request to localhost:[PORT]/api/messages (open that url in the browser) reveals the error message Multiple types were found that match the controller named 'messages'. It was somehow finding both the old messages controller (Microsoft.Bot.Samples.SimpleEchoBot.MessagesController) and the new one (MyBotName.MessagesController).
Solution: delete the bin/ folder and re-build/run the project.

IIS : Exception from HRESULT: 0xC00CEF03

I have my website hosted on IIS with window 2016 OS. When I am going to disable the Form Authentication under IIS, it is giving me the following error.
Form Authentication.
Exception from HRESULT: 0xC00CEF03
i had a similar issue but it occurred when i was trying to disable the 'Machine key' - 'automatically generate at runtime' and then Applying the same.
For your error, please verify if the authentication is enabled/disabled for Default Web-site. Change that setting and then try disabling you specific websites status. It should ideally work.
I've seen this error stem from three different controls on the authentication method:
If configuring the authentication method on an application, and the authentication method you're trying to disable is enabled on the containing site.
If configuring the authentication method on a site, and the authentication method you're trying to disable is enabled on the Default Web Site.
If configuring the authentication method that has been defined in a web.config file. You should adjust it in the config file.
0xC00CEF03 error code translates to WR_E_NSPREFIXWITHEMPTYNSURI which refers to “Writer: cannot use prefix with empty namespace URI” (Reference).
This error occurs when there is something wrong with the web.config file. It’s probably corrupted or there are incompatible tags and parameters. As a result of this corruption and incompatibility, IIS is not able to read this file. Therefore, it can’t make a change.
The issue mostly happens after migration because a piece of configuration that works in the older version of IIS (and .NET Framework) probably became unsupported in the newer version.
The shortest way of finding what part of the web.config is causing the issue is to remove sections one by one and test. High-level steps:
Remove a section from the bottom of the file (Let’s say you removed system.serviceModel section)
If the issue goes away, add the section back and start removing the subsections of it one by one. (For example, ws2007HttpBinding subsection in system.serviceModel section)
If the issue goes away again, bring the subsection back and go through each lines. Prefixes like wsid:, asm:, and trust: are the most common causes of this issue
Source: 0xC00CEF03 error (Cannot use prefix with empty namespace URI)

WCF not working when debugging in visual studio but works in IE

I have a WCF that is hosted in an ASP.NET application. Suddenly, the WCF service has stopped working when i debug it in visual studio 2010. When i try to access the service, it throws the below exception.
CommunicationException was unhandled by user code. The remote server returned an error: NotFound
I have WCF tracing enabled but no errors are being logged.
The strange bit is that if i deploy the code to my QA server and access the application, the service works fine, so the code looks like not the problem.
If i also get the source code currently running in production successfully & try debugging it in my dev environment, it fails with the same error i mention above.
Any one have an idea what could be messed up in my dev environment?. I have tried both IE, Firefox & Chrome & the results are the same.
I after a very long debugging involving deleting Bin & obj folders and lots of rebuilds, i finally got this WCF service working again.
First, i suspected the service could be corrupted somehow, so i tried to update the service reference in my silverlight application but was bumped with the following error.
There was an error downloading 'http://localhost/mySite/Webservice/GetData.svc'.
The request failed with HTTP status 404: Not Found.
Metadata contains a reference that cannot be resolved: 'http://localhost/mySite/Webservice/GetData.svc'.
The remote server returned an unexpected response: (405) Method Not Allowed.
The remote server returned an error: (405) Method Not Allowed.
I then browsed to the physical folder path to confirm if really my .svc file was there and indeed as expected, the file was there.
Trying to Browse to the path http://localhost/mySite/Webservice/GetData.svc in my browser bumped me with another error below.
HTTP Error 404.7 - Not Found The request filtering module is
configured to deny the file extension.
Most likely causes: Request filtering is configured for the Web server
and the file extension for this request is explicitly denied.
This made me start thinking that suddenly, IIS 7.0 has decided to block access to my .svc files.
I then added fileExtension=".svc" mimeType="application/octet-stream" to IIS, restart IIS but got the same error.
I then read on some blog i cant remember about adding <add fileExtension=".svc" allowed="true" /> under <requestFiltering> tag in file applicationHost.config located at C:\Windows\System32\inetsrv\Config, still nothing changed. Tried adding <mimeMap fileExtension=".svc" mimeType="application/octet-stream" /> under serverSideInclude in the same file, again with no luck.
Tried this http://www.adamwlewis.com/articles/iis-7-not-serving-files-4047-error still with no luck.
The following 2 steps are i think what resolved the issue.
I added a mapping for the SVC extension to ASP.NET by running ServiceModelReg.exe -i from C:\Windows\Microsoft.NET\Framework\v3.0\Windows Communication Foundation
Browsed to my .svc file in the browser and this time it looked like i had made some progress but still, i had one more error to overcome . The is bellow.
Could not load type 'System.ServiceModel.Activation.HttpModule' from assembly 'System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
I resolved the above error by registering the correct version of ASP.NET using the ASP.NET IIS Registration Tool (aspnet_regiis.exe,) as described in the link below
https://msdn.microsoft.com/en-us/library/hh169179(v=nav.70).aspx
At this point my service was back to normal as it had always been. I still haven't figured out what messed up my development machine.

Mapping *.MVC to aspnet_isapi.dll on IIS7

We have a .net 3.5 application (MVC and WebForms mixed) that was hosted on IIS6. In order to make it work on IIS6 we had to add custom mappings to IIS such that *.MVC would map to aspnet_isapi.dll.
So our URL's would end up looking like this:
<host>\someController.mvc\action
But now that were setting this web app up on IIS7, with classic mode pooling, were trying to do the same thing so that we don't have to change anything about the application.
But after adding the *.MVC Handler mapping in IIS7 it still does not seem to be picking it up. Every time we navigate to our MVC pages, we get 404 errors. However, our .aspx pages load fine.
On closer inspection the Failed Request Tracing keeps complaining about the following
ModuleName="IIS Web Core", Notification="MAP_REQUEST_HANDLER", HttpStatus="404", HttpReason="Not Found", HttpSubStatus="0", ErrorCode="The system cannot find the file specified.
(0x80070002)", ConfigExceptionInfo=""
I'm running in circles. We were able to set this up on another IIS7 machine yet this one were trying to set it up on just refuses to work. I really don't know what I'm missing. Its like the mapping rule is not triggering at all. Because the same error occurs if we just type in random things for the file name in the URL.
I just dealt with this, and what really did it for me was getting rid of the entire MvcHttpHandler (remove it from your
<system.webServer>/<handlers>
configuration tag).
MSDN states that this handler is only useful when the UrlRoutingModule is not enabled for all requests (which in IIS7+ we can), hence why it's useful for IIS6 (and also why we need the *.mvc extension to route properly).
So just remove the MvcHttpHandler reference in your handlers, and make sure you:
Have the application running in an app pool with Integrated Mode (not Classic)
You have the runAllManagedModulesForAllRequests modules attribute set to "true"
<modules runAllManagedModulesForAllRequests="true">
If you are still getting 404's then it's either your MVC doing it (which really sidetracked me :S) another reason.

My Working Application MVC3 Razor Unexplainably stopped working :-( IIS 7

I have the following projects within my solution.
MyWebApplication.Data --> Here i interact with my Data Repository
MyWebApplication.Services --> Here i interact with the Data Layer
MyWebApplication.Web --> The UI which relies on the Service Layer
MyWebApplication.Tests --> Unit testing project
For MONTHS i have had NO problems with IIS in my local dev environment. Ready for a long weekend of programming but all day i have been getting 500 Server Errors when simply trying to resolve the Home page. Before I went to bed all was well, the entire day thereafter i could NOT even load the home/index view.
After looking at the logs it says continually MyWebApplication.Data.System (which is a class i created called System()) does not include Web. But no where in code is this true. Then i get another error of mismatching files in the Temp Directory.
Steps I have taken:
Deleted all temp files
Created a new repository in IIS and pointed URL there, No luck
Cleaned solution
Deleted all bin folders to have regenerated... No Luck
PLEASE HELP!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Without the details of the error messages, one strategy may be to create a new MVC project and copy/paste the files over to it.
A few other common causes:
Are you referencing any 64-bit libraries but compiling the project as 32-bit (or vice-versa)? Try changing the "bitness" of your application.
If your application is 32-bit and is running on a 64-bit server, you need to enable running 32-bit apps in IIS. See http://exhibita.com/blog/post/2010/03/30/IIS-75-on-x64-with-32bit-applications.aspx
If all else fails, please post the exact error messages. If all it says is "HTTP 500: Internal Server Error", you should enable debug output or run your app from the server itself (actually using a web browser on the server), which will tell IIS it's "safe" to display full debug information. The debugging messages have actually been pretty useful in my experience.
Figured it out. In
MyWebApplication.Web project, within the Shared/Site.Master I added a imported a reference to my Data Layer. (i.e., <%# Import Namespace="MyWebApplication.Data" %>
I resolved by removing the static reference to my ShoppingCart class in the Data layer and just created an ActionResult to return the same and in the MasterPage (which currently holds the javsscript to allow the user to peek into their cart from anywhere in the site without a redirect to a specific page) used the Html.RenderAction() and just returned Content(shoppingCartString).
Guess I have learned that within the Site.Master page it is complied differently than every other page in an MVC application. I can positively say this because in other pages I am doing exactly as I attempted to do here without any issues. Maybe its the build process?
Anyhow, problem solved and hopefully it can help someone else too.

Resources