WebApi POST returns 404 on AppHarbor - asp.net-mvc-4

I have a Asp.net WebAPI service that is hosted on AppHarbor which throws 404 error on POST requests. The MVC 4 controller's POST works perfectly though that is hosted in the same virtual dir.
The same WebApi works on localhost. I tried below options with no luck:
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true" >
<remove name="WebDAVModule" />
</modules>
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
I also tried setting up action based URL to check if that works, but no luck. I have even decorated the method with:
[AcceptVerbs("POST")]
Would there be anything that needs to be added to web.config or any authentication setting that I am missing.

Solved, it was because of a database problem. I over looked the default try..catch which was returning a
HttpStatusCode.NotFound (404)
instead of a 500 error code. Its up and running now.

Related

403 Forbidden Error for .Net Core 3.1 Web Api only for Delete & PUT method

Application in .Net Core 3.1 and angular which working perfectly in locally. I hosted same application one of the hosting provider.
I am getting error "403 - Forbidden: Access is denied." for PUT & DELETE methods in web api response. I don't know why GET & POST methods are working in same application.
ASP.NET Core with IIS - HTTP Verb Not Allowed
Above link have somewhat same issue but getting 405 error. Solution given in same thread also tried but not working for me.
Please help on the same.
Are your frontend in angular? If yes, you have to add auth bearer header for put and delete correctly.
This code worked for me.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<modules runAllManagedModulesForAllRequests="false">
<remove name="WebDAVModule" />
</modules>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\XXXXXXXXXXX.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
</system.webServer>
</location>
</configuration>
I raised a ticket to my hosting provider. They made some settings and after that its working fine.

Azure web app hosted WCF services return 404

Trying to move a legacy web application from IIS8 to an Azure web app. The app includes many ajax calls to WCF services that are built with no endpoint configuration, similar to the method described here: http://stevemichelotti.com/restful-wcf-services-with-no-svc-file-and-no-config/
As suggested in the article, System.Web.Routing is used to route requests to the correct service. For example, my global.asax includes routes like this:
RouteTable.Routes.Add(new ServiceRoute("svc/cmp/", new WebServiceHostFactory(), typeof(CompanyService)));
RouteTable.Routes.Add(new ServiceRoute("svc/cont/", new WebServiceHostFactory(), typeof(ContactsService)));
So, a request for http://example.com/svc/cmp/GetCompany?id=1234 would be routed to CompanyService for handling.
These calls all work fine when running on IIS, but return 404 not found errors on Azure web app.
I tried adding handlers to web.config, like this:
<system.webServer>
<handlers>
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>
Also tried adding a handler mapping in the Azure app settings to have all extensions (*) handled by %windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll.
No luck in either case.
This was resolved by deleting the Azure web app and recreating it. It was originally created with the WordPress template with a virtual directory/application hosting the .net portion of the site.
Apparently, not all routing modules are loaded with the WordPress template so the WCF services were not routed correctly. After it was recreated with the web app template all the services worked just fine.
Update
This issue resurfaced after re-installing WordPress. Now that I have a better understanding of what's going on I thought I should update in case anyone has a similar issue.
WordPress is installed in web site root and the WCF services are in a child app. Turns out that WordPress created a rewrite rule in the web.config of the root which broke my WCF services. The rewrite rule looks like this:
<rewrite>
<rules>
<rule name="Wordpress: https://example.com" patternSyntax="Wildcard">
<match url="*" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" />
</rule>
</rules>
</rewrite>
This rule has to do with enabling pretty permalinks and says "if the URL does not correspond to a file or a folder on the file system, it will rewrite the URL to the index.php file".
Well, my WCF services have URLs that don't correspond to a file or folder, so they were all broken. The situation was resolved by clearing rewrite rules in the web.config in the child app:
<rewrite>
<rules>
<clear />
</rules>
</rewrite>
Lesson learned.

ServiceStack httpHandlers not loading

BaseLine: ServiceStack sample works for me in a stock MVC 4 app. I am using the variant, followed all the instructions in the readme, no problems.
Plugin Framework
I am building a plugin framework for MVC and servicestack.net is one of the plugins, that being all the assemblies are plugins which get loaded, using BuildManager.AddReferencedAssembly(assembly);
BuildManager.AddCompilationDependency(assembly.FullName);
All the ServiceStack dlls are found and successfully loaded from my personal shawdowFolder.
webconfig:
<location path="api">
<system.web>
<httpHandlers>
<add path="*" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory,ServiceStack" verb="*" />
</httpHandlers>
</system.web>
<!-- Required for IIS 7.0 -->
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<add path="*" name="ServiceStack.Factory" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory,ServiceStack" verb="*" preCondition="integratedMode" resourceType="Unspecified" allowPathInfo="true" />
</handlers>
</system.webServer>
</location>
*NOTE: I am calling from Application_Start AppHost.Init(), and I can step it so ServiceStack is truly loaded and usable before the ASP.NET app goes into full swing.*
On first launch: /api/metadata results in:
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: /api/metadata
Stopping the debugger and simply relaunching, which deletes all assemblies from my personal shawdowFolder, copies them, loads them, references them, results in.
A working ServiceStack.net
StarterTemplate ASP.NET Host
The following operations are supported. For a formal definition, please review the Service XSD.
etc.
I suspect that this problable has to do with .NET's shadowfolder and appdomain, but perhaps it is something with ServiceStack. Where would I find logs to see if ServiceStacks httphanderfactory is having problems.
I Changed my config as follows :
SetConfig(new EndpointHostConfig
{ ServiceStackHandlerFactoryPath = "ss"}
and my config :
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add type="DevExpress.Web.ASPxClasses.ASPxHttpHandlerModule, DevExpress.Web.v13.1, Version=13.1.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" name="ASPxHttpHandlerModule" />
<add name="FormsAuthenticationDisposition" type="ServiceStack.ServiceInterface.SuppressFormsAuthenticationRedirectModule, ServiceStack.ServiceInterface" />
</modules>
<handlers>
<add type="DevExpress.Web.ASPxUploadControl.ASPxUploadProgressHttpHandler, DevExpress.Web.v13.1, Version=13.1.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" verb="GET,POST" path="ASPxUploadProgressHandlerPage.ashx" name="ASPxUploadProgressHandler" preCondition="integratedMode" />
<add type="DevExpress.Web.ASPxClasses.ASPxHttpHandlerModule, DevExpress.Web.v13.1, Version=13.1.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" verb="GET" path="DX.ashx" name="ASPxHttpHandlerModule" preCondition="integratedMode" />
<add path="ss*" name="ServiceStack.Factory" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*" preCondition="integratedMode" resourceType="Unspecified" allowPathInfo="true" /></handlers>
<validation validateIntegratedModeConfiguration="false" />
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="30000000" />
</requestFiltering>
</security>
</system.webServer>
Now I have to type in the following to get to my servicestack area : http://localhost/ss/
My take on what is going wrong is that mvc/asp.net forms/ servicestack each needs one entry point to map its handler to an url route, servicestack is overriding the url route for "/" your MVC project hence no resources is found.
Thus in my application I used to seperate entries points:
*http://localhost/* .... is my normal entrypoint for webforms (in your case MVC4[stock])
http://localhost/ss .... is my servicesstack entrypoint
If you are using the MVC razor engine you won't run into this.

How to use EmbeddedResourceVirtualPathPovider with IIS6

While developing a ASP.NET MVC4 web application with VS2010, using the Mvc.JQuery.Datatables Nuget,
I found that the EmbeddedResourceVirtualPathProvider NuGet that is referenced, worked beautifully
on my dev box, but failed miserably on my production box.
The production box is Windows 2003, with IIS6 and .NET 4.0 installed.
I searched many things on SO, and Googling, but after implementing the suggested workarounds,
it still fails:
Here's what I've done.
Implement AppInitialize as suggested by https://stackoverflow.com/a/5178993
Implemented Wildcard mapping for ASP.NET as suggested by http://haacked.com/archive/2008/11/26/asp.net-mvc-on-iis-6-walkthrough.aspx
Implemented IgnoreRoute for static files as suggested by https://stackoverflow.com/a/3144841
but it still doesn't serve all of the files. I'm getting the embedded partial views, but not
the embedded css, js, and jpg files.
My web.config has an entry for the StaticFileHandler as follows:
<system.webServer>
<handlers>
<add path="*.css" verb="GET" name="Static css" type="System.Web.StaticFileHandler" />
<add path="*.js" verb="GET" name="Static js" type="System.Web.StaticFileHandler" />
<add path="*.jpg" verb="GET" name="Static jpg" type="System.Web.StaticFileHandler" />
<add path="*.gif" verb="GET" name="Static gif" type="System.Web.StaticFileHandler" />
</handlers>
</system.WebServer>
I appear to be missing something critical. Any Suggestions?
When using IIS6, all of the items listed in #1-3 are required, but additionally, you need to
recognize that IIS6 defines its handlers as httpHandlers in the system.web section,
whereas IIS7 calls them handlers and they are in the system.webServer section of the config file.
Therefore, you need to add the following to make it work in IIS6
<system.web>
....
<httpHandlers>
<add path="*.css" verb="GET" type="System.Web.StaticFileHandler" />
<add path="*.js" verb="GET" type="System.Web.StaticFileHandler" />
<add path="*.jpg" verb="GET" type="System.Web.StaticFileHandler" />
<add path="*.gif" verb="GET" type="System.Web.StaticFileHandler" />
</httpHandlers>
</system.web>

HTTPHandler and svc

I've got an existing web application, that is installed on several machines. script clients and .net clients consume ".asmx" services through one machine, that routes all calls to other machines.
Client ----> |Website \ Virtual directory(HttpHandler)| ----> |Other server \ real .asmx|
I added a new .svc service that does the same functionality, and added a handler for it (directory's config):
<system.webServer>
<handlers>
<add name="MY_ASMX" verb="*" path="*.asmx" type="MY.AO.HttpProxy, Astea.AO.HttpProxy" resourceType="Unspecified" preCondition="integratedMode" />
<add name="MY_ASPX" verb="*" path="*.aspx" type="MY.AO.HttpProxy, Astea.AO.HttpProxy" resourceType="Unspecified" preCondition="integratedMode" />
<add name="MY_WSDL" verb="*" path="*.wsdl" type="MY.AO.HttpProxy, Astea.AO.HttpProxy" resourceType="Unspecified" preCondition="integratedMode" />
<add name="MY_SVC" verb="*" path="*.svc" type="MY.AO.HttpProxy, Astea.AO.HttpProxy" resourceType="Unspecified" preCondition="integratedMode" />
while asmx request are routed fine, my new .svc on the end server does not get called, and even the Httphandler is skipped. if i call the .svc directly on the other machine it works.
the error i get is:
WebHost failed to process a request.
Sender Information: System.ServiceModel.Activation.HostedHttpRequestAsyncResult/26458746
Exception: System.Web.HttpException (0x80004005): The service '/Mysite/MyDirectory/settings.svc' does not exist. ---> System.ServiceModel.EndpointNotFoundException: The service '/Mysite/MyDirectory/settings.svc' does not exist.
I already tried the folowing
add "buildProviders" to compilation section that removes .svc
Click on MimeTypes and enter “.svc” and “application/octet-stream” and save
add a handler :
nothing helps, http handler is not being called
p.s. Im working with AppPool .net 4.0 Integrated
.svc extensions are considered by default to be WCF services, and handlers/modules are already present for them. You can remove the existing handlers/modules by putting a element before your <add> element:
<remove name="svc-ISAPI-4.0_32bit" />
(or, if on win64:)
<remove name="svc-ISAPI-4.0_64bit" />
And, in the <modules> element:
<remove name="ServiceModel-4.0" />
I've found it. Adding:
<compilation debug="true" >
<buildProviders>
<remove extension=".svc"/>
</buildProviders>
</compilation>
caused an error, that got me to back off, at the first time:
"~/ServiceManagement.svc" demanded that the buildProvider for ".svc" will be on
"~/ServiceManagement.svc" is automatiacally created in the machine root config when you install MS AppFabric. Since I'm using that folder only for redirection, I don't need Appfabric there, so I removed it:
<system.serviceModel>
<serviceHostingEnvironment>
<serviceActivations>
<remove relativeAddress="~/ServiceManagement.svc"/>
</serviceActivations>
</serviceHostingEnvironment>