Hosted web api is accessible through browser but not through application - asp.net-mvc-4

I have hosted web api in iis 10.0 then accessing it's method through browser.
But the same method is not able to access through my MVC application.
Getting 404 Not found issue.
But when i run web api application i am able to access methods through application.
I did some googled and found some handlers that needs to be set in hosted web api web.config. But it also did not worked for me.
Below is my complete system.webserver tag used in web api web.config.
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<remove name="WebDAVModule" />
<remove name="FormsAuthentication" />
</modules>
<handlers>
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="UrlRoutingModule-4.0" />
<remove name="ApiURIs-ISAPI-Integrated-4.0" />
<add name="UrlRoutingModule-4.0" path="*." type="System.Web.Routing.UrlRoutingModule" preCondition="" verb="GET,HEAD,POST,DEBUG,PUT,DELETE" />
<add name="ApiURIs-ISAPI-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv4.0" />
<!--<add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS,XYZ" 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,XYZ" 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,XYZ" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />-->
</handlers>
</system.webServer>
Need help.

I was doing some mistakes when passing the Web api url in application.
e.g: for web api Root url i was using like below:
http://localhost:25968
But it should be like : http://localhost:25968/
Last slash was missing due to it web api method was not accessing through application.

Related

IIS 7.5 error 405 the PUT method not supported

i have Web api WCF RESTfull Server on IIS 7.5 on windows 7 64-bit.
i am tring to update one record via PUT method, but i get error 405. i have tried allowing PUT verb in my Web.Config like this:
<system.webServer>
<modules>
<remove name="WebDAVModule" />
</modules>
<handlers>
<remove name="WebDAV" />
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" resourceType="Unspecified" requireAccess="Execute" preCondition="integratedMode,runtimeVersionv4.0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="*" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="Execute" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="*" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="Execute" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
</handlers>
....
i also disabled WebDAV as you can see, but still getting 405.
any one has a suggestion?
Try removing the webdav module manually from GUI of IIS.
1) Goto the iis.
2) Goto the respective site.
3) Open "Handler Mappings"
4) Select WebDav. Right click on it and delete it.
Note: this will also update your web.config of the web app.

How to deploy an ASP NET MVC 4 Web Application using Windows Server 2008 R2 and IIS 7.5?

Firstly, I am sorry for repeat a question but its solution:
Solution
It doesn't work for me. I read the articles in this solution but I can't deploy my ASP NET MVC 4 web application. I tried this:
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
...
</system.webServer>
and I tried this too:
<system.webServer>
<modules>
<remove name="UrlRoutingModule-4.0" />
<add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="" />
</modules>
</system.webServer>
I downloaded an update:
An update is available that enables certain IIS 7.0 or IIS 7.5 handlers
to handle requests whose URLs do not end with a period
Windows Update
but When I tried to install then
I am working on:
-Windows Server 2008 R2 Service Pack 1
-Internet Information Services 7.5
-Visual Studio 2013 Update 2 (Publish using Web Deploy)
-.Net Framework 4.5
My Modules
and finally my web.config (without the module tag because I was using both of them and I got the same result)
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<appSettings>
<add key="webpages:Version" value="2.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="PreserveLoginUrl" value="true" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
<system.web>
<httpRuntime targetFramework="4.5" />
<compilation debug="true" targetFramework="4.5" />
<pages>
<namespaces>
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages" />
</namespaces>
</pages>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<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>
</configuration>
When I publish my web application this is the result:
Does anyone have an idea about What am I doing wrong?
I can't deploy my MVC Web Application using one click Publish web deploy, but I deployed my Web Application using the configuration below:
I didn't need to use this tags:
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
...
</system.webServer>
or
<system.webServer>
<modules>
<remove name="UrlRoutingModule-4.0" />
<add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="" />
</modules>
</system.webServer>

How do I configure this route in asp.net mvc 4?

I currently have a website that is serving static files from a simple website that just points to a directory and I want to replace it by grabbing the files from DropBox.
I already have the files on DropBox and grabbing them is easy BUT I now need a website that will parse the URL to the files and give me the parameters I need to access the files on DropBox.
Typical file URL:
http://companyfiles.mywebsite.com/18/RepZio/companyfiles/subfolder1/SampleFile.docx
The route I configured that I hoped would work:
routes.MapRoute(
name: "Default",
url: "{id}/{dropboxfolder}/companyfiles/{path}",
defaults: new { controller = "CompanyFiles", action = "Index" }
);
I know my issue is all of the extra /'s in my URL, how can I parse whatever comes after /companyfiles/ to be a single parameter?
I cannot change the URL's that are being called since they already exist everywhere else in my system.
1. The file path info can be caught by a wild card matching pattern, like
url: "{id}/{dropboxfolder}/companyfiles/{*path}",
2. In ASP.net Classic mode URL with extension are served by Static file handler. To make all url go through ASP.net pipeline in Integrated mode, the following should be added in system.webserver.handlers section
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true" />
<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>
This should put the urls with extension through asp.net pipeline.
Regards

How do I map all routes in my MVC application to a static file?

I'm currently writing a single page application and would like to map all incoming requests (except /api/{controller}) to my web application to a static file (index.html) in root. The routes to /api need to be accessible for WebApi calls from the front end. Any suggestions on how to achieve this?
You could use the IIS 7 url rewrite module. This module is part of the IIS Express webserver, so you don't need anything special to enable it. And on your production IIS 7 server you might need to install and enable the extension.
Just add the following rule to your <system.webServer> section:
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true" />
<rewrite>
<rules>
<rule name="Rewrite to index.html">
<match url="^(?:(?!api\/))" />
<action type="Rewrite" url="index.html" />
</rule>
</rules>
</rewrite>
<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 since you are not using ASP.NET MVC you could get rid of the ~/App_Start/RouteConfig.cs file because you don't have any MVC controllers. Just keep the ~/App_Start/WebApiConfig.cs where you will have a route for the ~/api endpoint mapped to your Web API controllers:
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
}

How to configure IIS 7.5 for extensionless url's on castlerock monorail

I'm using Windows 7 (IIS 7.5) and have been struggling with getting it setup to use extensionless url's. This is what my web.config looks like:
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<clear />
<add name="ASPX" path="*.aspx" verb="*" type="" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="Script" allowPathInfo="false" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="4194304" />
<add name="StaticF" path="*.*" verb="FILE, GET" type="" modules="StaticFileModule" scriptProcessor="" resourceType="Unspecified" requireAccess="Script" allowPathInfo="false" preCondition="" responseBufferLimit="4194304" />
<add name="MR" path="*" verb="*" type="" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="Script" allowPathInfo="false" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="4194304" />
</handlers>
</system.webServer>
Going to any url without an extension gives a 404 - resource cannot be found error thrown by ASP.NET. Any help would be greatly appreciated.
Assuming you do not want regular webforms you could remove the "ASPX" line
As for the mapping of "*" to MR, you need another handler factory to set in the "type" attribute:
<add name="MR" path="*" verb="*"
type="Castle.MonoRail.Framework.MonoRailHttpHandlerFactory,
Castle.MonoRail.Framework"
modules="ManagedPipelineHandler"
scriptProcessor=""
resourceType="Unspecified"
requireAccess="Script"
allowPathInfo="false"
preCondition=""
responseBufferLimit="4194304" />