ASP.net web API GET method called twice - asp.net-web-api

I am trying to compile and run ASP.net web api project in mono. On windows this projects works fine but in mono the GET method is called twice. This happens only with GET method. The project has authentication requirement, so if any end point is hit without authentication the returned error response is also twice. What can be the issue?

Finally I was able to narrow down the issue. This was happening because WebApiConfig.cs was getting registered twice

Related

When adding new endpoints to my net6 API on Azure App Service slot, I receive 404 not found ONLY on the new endpoints

I have an API that has lots of controllers and endpoints. It was built on net 3.1 and was recently migrated to net 6. The migration worked fine.
Let's say that this API has one controller called ProductController, and this controller have a bunch of endpoints. One of them we can call it GetProductsByUserAndType.
I had to create a new endpoint, inside this existing controller, called GetProductsByUser.
I run my api locally and the new endpoint works fine.
I publish it on an appservice hosted in a testing environment and it works fine
I publish it in release mode in a folder, run the .exe file and it works fine
But when I publish it in on an appservice-slot hosted in a production environment, this new endpoint throws a 404 not found.
I recently added a new Controller to this API with a new endpoint, and this new endpoint also throws 404 not found.
I'm really lost here because this problem doesn't make sense to me. Why come only new endpoints doesn't work ? I have 2 endpoints living side-by-side on a controller and one of them throws 404 (the new one) and the other not.
I tried to:
search for the problem: I found nothing related, this situation looks very specific;
re-deploy the code to the appservice-slot (I use the Local git option);
deploy using the Publish configuration on Visual Studio 2022;
As I was writing this question, a teamate suggested to delete the slot and create a new one.
I did that, deployed again and it worked. So, I hope this helps someone out there.

500 error from controller even it is not reaching action method of the controller in asp.net

Assalamu alaykum. I did an API controller. When I run in the visual studio and query, the swagger returns 500 errors, but when I debug it doesn't reach the controller action.
This is why and how to fix it?
I also create a simple, no parameter, just a test endpoint that simply returns an int variable. Any method inside this controller file is not reached when this controller's endpoints are queried.
By the way, this is a .NET framework application.
Knowing brothers #help
I found why this happened. It is because the service used in controller is not registered in DI container. In my opinion, it should just throw an exception instead of returning 500 without reaching to controller action. Anyway, I don't know why, but this worked for me after I added the service to DI.
I actually forgot about this question of mine. But, anyway, there may be something useful for someone in this answer.
I found the answer: If there is some kind a service which is not registered in Dependency Injection, then there will be 500 error in swagger - for any request. Any call will be faced with thrown exception before reaching the controller.

"~" symbol created automatically after running project with service worker

My project is a simple login page. I am using asp.net core with MVC.
Everything was working well and I wanted to add service worker to my project. I followed the known steps. Add a manifest.json file in wwwroot, fill it correctly and add this function services.AddProgressiveWebApp(); after services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);.
When others do these steps, service worker works properly. When I run it (IIS Express), service worker produces an error: "Uncaught (in promise) TypeError: Failed to register a ServiceWorker: A bad HTTP response code (404) was received when fetching the script."
Then I realized this thing: https://localhost:44331/~/serviceworker.
The ~ symbol is created automatically and I am not knowing how to remove it.
The following https://localhost:44331/serviceworker works.
Help?
It is solved.
I updated the version from v1.0.42 to v.1.0.33 and it worked.
v1.0.42 has a bug.

OWin Startup attribute not found error on Web API REST Request

I have a Web API project along with the built in help website. When I start up the project locally, the help website home page displays no problem. But when I send a REST POST request to an API controller using fiddler, I get the following response.
The following errors occurred while attempting to load the app.
- No assembly found containing an OwinStartupAttribute.
- No assembly found containing a Startup or [AssemblyName].Startup class.
To disable OWIN startup discovery, add the appSetting owin:AutomaticAppStartup with a value of "false" in your web.config.
To specify the OWIN startup Assembly, Class, or Method, add the appSetting owin:AppStartup with the fully qualified startup class or configuration method name in your web.config.
I have tried to solve using the suggestions in the error message but no joy.
It works OK on the test server.
Can anyone suggest why this error is returned only on a REST request and not when the help website starts up and any tips on how to solve?

Web API 404 File or Directory not Found for "root" routes

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)

Resources