We currently have an old legacy WCF service that I really don't want to maintain but several clients still have access. We currently run all our API services in WEB API 2 in Azure. To enable backward compatibility I was hoping to simulate the WCF routing in WEB API using attribute routing like so:
[RoutePrefix("registration.svc")]
public class RegistrationDeprecatedController : ApiController
{
[HttpPost]
[Route("login")]
public async Task<HttpResponseMessage> Login(CredentialModel creds)
{...
Locally this runs like a dream. As soon as I publish to an Azure AppService however all I get is 404 not found. The specific route in question:
/registration.svc/login
My suspicion is that IIS hosting has the .svc route file associate to process the requests as a WCF call. An extensive search online failed to find anything on how I can change this association or even confirm if this is the case. Any ideas on how to fix or alternative solutions will be greatly appreciated.
Update
Found a solution but its not perfect. Found out that it is possible to directly connect to IIS on the AppService instance and change the Handler Mappings. This is not perfect as it would require a manual change when creating a new instance or deployment slot and I would prefer to automate the entire process.
If anyone else would like to do this you can follow a tutorial by benjamin perkins. I did have to install an IIS Manager for remote administration extension on windows 10 however for this to work. I removed all mappings associated to *.svc and the routing is now working.
Final solution was to remove the handlers in the web.config.
<system.webServer>
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<remove name="svc-Integrated" />
<remove name="svc-Integrated-4.0" />
<remove name="svc-ISAPI-2.0" />
<remove name="svc-ISAPI-2.0-64" />
<remove name="svc-ISAPI-4.0_32bit" />
<remove name="svc-ISAPI-4.0_64bit" />
....
</handlers>
I was able to find the names by connection to IIS on the AppService instance. I was unsure which ones needed to be removed so I removed all that handlers associated with *.svc.
Related
I've inherited a class library that is using .NET Framework 4.7.2. In the library there are a bunch of ApiControllers with a number of HttpPost and HttpGet Methods on them. Errors have started occurring on some of the methods and these methods are typically called from a wordpress site.
To try and make things a bit easier for me to debug, I'm trying to install swagger into the solution. I've installed Swashbuckle.core with a runtimne version of 4.0.30319 and this has created a basic SwaggerConfig.cs file in my App_Start folder.
In the properties for the solution the project url is http://localhost/WordpressService and it's running under local IIS.
I have a local version of wordpress running in Microsoft Edge, and in IIS I can see that the WordpressService is running on port 80.
So now in the WordpressService solution I try to attach the debugger to the browser, then in the browser I try to enter http://localhost/WordpressService/swagger and other variations of the address, but all the time I receive the following error:
HTTP Error 500.21 - Internal Server Error Handler
"ExtensionlessUrlHandler-Integrated-4.0" has a bad module
"ManagedPipelineHandler" in its module list
I have this section in my web.config file:
<system.webServer>
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer> >
within IIS in the Handler Mappings section I can see ExtensionlessUrlHandler-Integrated-4.0 and it is enabled.
it also suggests that asp.net may not be installed correctly but it must be as I'm using VS 2017 and would need to be there for that. Looking around the net, the default SwaggerConfig.cs should be enough to get me going.
The only thing I can think of is that I may have installed the wrong version of swagger, but I'm not sure in that case which version I should be installing for this .NET Framework.
Ok, I figured the issue out and thought I'd post my answer for anyone else that may come across this issue. From IIS installation, it appears that only Framework 3.5 had been installed and not Framework 4.8. Installing 4.8 in the IIS section seems to have resolved this and I can now see my end points via swagger.
I am creating a .NET web forms application and attempting to use friendly URLs for the first time. The application is targeting framework 4.7.1. Everything is easy and works great on localhost. When I deploy it to a testing server (which is running IIS version 8.5.9600.16384), I get some odd results. The page will route correctly, and retain the friendly url structure, if the routeUrl is equal to the physical page name, but if the routeUrl is not equal, it gives a 404. Even when the route does work, the route values don't come through to the page. Page.RouteData.Values.Count always comes back as 0, even when I'm setting a default value.
I have looked all over Stack Overflow and the rest of the internet and looked at I don't even know how many posts from people with similar problems, but in the few cases that there were suggested solutions, none of them worked for me. See below things I have changed in my web config based on those suggestions, all to no avail.
What I have right now:
RouteConfig.cs
public static class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.MapPageRoute( //"works", but no route values when navigate to /giftcard/something
"new-giftcard",
"giftcard/{action}",
"~/giftcard.aspx",false, new RouteValueDictionary { { "action", "add" } });
routes.MapPageRoute( //returns 404 when navigate to /random/something
"randomtest",
"random/{action}",
"~/giftcard.aspx", false, new RouteValueDictionary { { "action", "test" } });
var settings = new FriendlyUrlSettings();
settings.AutoRedirectMode = RedirectMode.Permanent;
routes.EnableFriendlyUrls(settings);
}
}
Global.asax
void Application_Start(object sender, EventArgs e)
{
RouteConfig.RegisterRoutes(RouteTable.Routes);
}
Web.config (things I added based on research of possible issues, none of which helped)
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" >
<remove name="UrlRoutingModule-4.0" />
<add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="" />
</modules>
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>
All of this seems to work perfectly fine on localhost. Because it all works locally, there has to be something wrong with how IIS is handling the routing, but I am out of my area of expertise here, so any other ideas for what to change or how to debug would be great.
Here's my current settings on the live server again for reference:
IIS version 8
Application pool .NET 4.0 Integrated
Target framework .NET 4.7.1
I checked IIS Express on my local development machine, and it's version 10.
EDIT: further info - I tried it on a new test server with a fresh install of server 2012, and it seems to work. Unlike the test server described above, this new server has ONLY had .NET 4.0 installed. The first server is older and had .NET 3.5 and 4 both installed. Perhaps a conflict with versions of .NET?
I'm trying to understand how IIS knows how to start my ASP.Net Web Application My understanding so far is that, when creating a web application we create a Web.Config which defines how IIS will start it's process
So We have a Web Config
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="LogRequests" type="BDBPayroll.Apps.API.Web.Shared.HttpModules.LogRequestsHttpModule, BDBPayroll.Apps.API.Web.Shared" />
<add name="MiniProfiler" type="BDBPayroll.Apps.API.Web.Shared.HttpModules.MiniProfilerHttpModule, BDBPayroll.Apps.API.Web.Shared" />
</modules>
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>
And The Global Asax:
public class WebApiApplication : WebApiHttpApplication<WebModule>
{
protected override void Configure(HttpConfiguration config)
{
config.Filters.Add(new Filters.ContextResolverFilter());
config.Filters.Add(new ValidateModelAttribute());
config.Filters.Add(new PaginationFilter());
GlobalContext<JsonFormatterRule>.Instance.SetDefaultJsonFormatter(config);
}
//...
}
Since IIS can run multiple applications e.g php, .net etc, How does IIS Know from the Web Config To run the Global Asax.
My guess is that it looks up the application type from the web config, and then searches for WebApiHttpApplication, Does anybody have any more information on this process?
Since IIS can run multiple applications e.g php, .net etc, How does IIS Know from the Web Config To run the Global Asax.
My guess is that it looks up the application type from the web config, and then searches for WebApiHttpApplication, Does anybody have any more information on this process?
As far as I know, if use send the request to the IIS.
After handling the http request by http.sys, IIS will move this request to the w3wp.exe to handle it.
Since IIS could only handle htm or html static page, IIS will use ISAPI to handle the page which IIS couldn't handle.
ISAPI is a kind of extention handler to handle different kinds of pages like php, aspx, cshtml or something else.
You could find it from IIS manager console handler mapping icon.
Image as below:
The IIS will send the request to right http hanlder according to its extension. The handler moudule(e.g asp.net isapi) will load the CLR and web application(include the globalasax) to handle the request.
currently I am running my web service from following path
http://localhost:16022/MachineService.asmx
and usage of some web method like
http://localhost:16022/MachineService.asmx?op=GetData1
I want to do it in following way
to run the web service from following path
http://localhost:16022/
and usage of some web method like
http://localhost:16022?op=GetData1
Is it possible to set it be the default ?
I am using VS2010.
Also possible to do so at the IIS7 itself ?
You can set the defaultDocument Element in your web.config file so you won't have to specify MachineService.asmx with each and every call.
<system.webServer>
<defaultDocument>
<files>
<clear />
<add value="MachineService.asmx" />
</files>
</defaultDocument>
</system.webServer>
Instead of manually modifying web.config you can configure the default document in Internet Information Services (IIS) Manager.
I've created an OData service (WCF Data Service), and a consumer to test it.
Previously, when I attempted to delete, I got the WebDAV 405 error message, "Method Not Allowed".
So I googled and found:
http://nikhilthaker86.wordpress.com/2010/03/27/issue-hosting-restful-services-on-iis-7/
I followed the instructions and removed the WebDav module from my website (service) in IIS 7.
Now I get this error message instead:
"HTTP Error 500.21 - Internal Server Error
Handler "WebDAV" has a bad module "WebDAVModule" in its module list
Module: IIS Web Core
Notification: ExecuteRequestHandler"
If you have a solution that will make this problem go away, I would really appreciate it... otherwise, if you're an IIS guru, and you're thinking "This guy has no idea what he's doing", please point me in the direction of some useful online reading material.
Thanks in advance.
The WebDAV module will block both the DELETE and PUT (update) verbs for IIS. You can either uninstall WebDAV (recommended) or simply remove it from the Handlers of the site. More details can be found here: http://forums.iis.net/t/1166025.aspx
One way to do this is to add the following remove lines to your site's web.config:
<system.webServer>
<modules>
<remove name="WebDAVModule" />
</modules>
<handlers>
<remove name="WebDAV" />
</handlers>
</system.webServer>