Setting default at some port be some specific web service - c#

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.

Related

Hooking up sub applications in ASP.NET Core

I have two projects in asp.net core 2.1. One is the main web application, and the other is a sub-application. The sub-application is for the most part, independent; it only needs cookies from the main application.
I'm trying and failing to set up the two projects in my local dev environment, and I will also need to set up for live IIS Deployment in the future. I have both VS projects in the same VS Solution. In their project Debug settings page, I have them both set up to launch IISExpress with app URL as 'http://localhost:44305'. I have tried setting the subapp to 'http://localhost:44305/subapp' too, but when vs run, IISExpress complains that the port is already in use.
I have a web config for both apps. The very basic defaults for both. In the sub app, I have the extra line to remove the aspnetcore handler (as I found from searching).
<remove name="aspNetCore" />
In the sub app, i have also tried adding in startup.cs:
app.UsePathBase("/subapp")
The results I get from this setup running in vs locally is that on the base URL, it actually loads up my subapp instead of my main app (browser URL is localhost:44305). Fiddling with multiple settings seems to get me nowhere; either both apps fail to load completely, or one or the other app is inaccessible.
Is there any proper documentation out there for setting up multiple apps to work together locally and in IIS? Everything I seem to find is from pre-2.0.
Thank you for your help!
Edit:
I actually managed to get a fresh project working as subapp when deploying to IIS. To set up:
Make a new VS solution with two aspnetcore 2.1 web applications.
Add a web.config to sub application with following:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
</handlers>
<aspNetCore processPath="dotnet" arguments=".\IISTestSubApp.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
</system.webServer>
</configuration>
No web config for Main app.
Add .UseIISIntegration() to Program.cs CreateWebHostBuilder to both apps.
In Startup.cs Configure method for Subapp, add app.UsePathBase("/subapp/");
Deploy main app to a folder /Mainapp. Deploy sub app to /Mainapp/subapp.
Set up iis website for main app.
Right click on main app website in IIS and click Add Application. Add the subapplication with an alias '/Subapp'
That should be all you need. Some of the steps may not be necessary. I haven't fully tested which steps are 100% necessary.
Unfortunately, I still can't get it to work with IISExpress. I have my .vs/applicationhost.config file looks almost exactly like the IIS one, but when running both apps at the same time, i get errors saying that the port is already in use. I'm still trying a bunch of new things, so, we'll see if I can figure it out.
I got it working now in IISExpress. Following the above steps for IIS first, for basic setup, include the following:
The subapp web.config file should look like this for IISExpress:
<configuration>
<system.webServer>
<handlers>
</handlers>
<aspNetCore processPath="dotnet" arguments=".\bin\Debug\netcoreapp2.1\IISTestSubApp.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
</system.webServer>
</configuration>
In your solution's .vs/config/applicationhost.config file, make sure your sites section looks like
<site name="IISTest" id="2" serverAutoStart="true">
<application path="/" applicationPool="IISTest AppPool">
<virtualDirectory path="/" physicalPath="C:\Users\user\Documents\GitHub\IISTest\IISTest" />
</application>
<application path="/subapp" applicationPool="IISTest AppPool">
<virtualDirectory path="/" physicalPath="C:\Users\user\Documents\GitHub\IISTest\IISTestSubApp" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:44301:localhost" />
</bindings>
</site>
It seems okay that both apps use a different application pool. Setting them the same gets overwritten when vs runs, for some reason.
Run only the main app from vs; Don't try to run sub apps as well. You will get port already taken error message.

Simulating WCF route in WEB API 2

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.

How to get IIS to recognize OWIN startup class?

My OWIN web service runs beautifully in Visual Studio 2013, but when I publish it to a real IIS site, it acts as if the Configuration method in the startup class has not been run. I can do "normal" things like browse to the app and see the directory structure, but nothing that was supposedly set up with the IAppBuilder is functional. For example, I get a 404.0 error when I browse to a URL that was set up in Startup to issue an OAuth2 bearer token. It's as if Startup.Configuration(IAppBuilder app) was never run.
I'm using the [assembly: OwinStartup(typeof(MyNamespacedStartupClass))] attribute to designate the startup class.
I've used NuGet to get both Microsoft.Owin.Host.SystemWeb and Microsoft.Owin.Diagnostics per instructions I've seen, but that doesn't make a difference.
What more do I have to do?
Make sure your app pool is in v4.0 integrated mode.
Make sure you have bin placed Microsoft.Owin.Host.SystemWeb (I see you have installed it) - Just make sure its also in the bin folder.
This article will have more information on how an OWIN middleware runs on Integrated pipeline.
I also had to add an extra setting to my web.config
<configuration>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
</configuration>
From: https://katanaproject.codeplex.com/wikipage?title=Static%20Files%20on%20IIS
IIS has a native static file module that is optimize to skip other
portions of the pipeline if it sees file paths that do not match other
handlers (e.g. not aspx). This means that the directory browser
middleware is likely to work, but then the static file middleware may
be bypassed in favor of the native static file module.
This tells IIS not to skip the managed Asp.Net modules even if the
native static file module thinks it has a match.
It also describes another step, but this was not needed for me:
Also, add the following stage marker AFTER your static file middleware
(in namespace Microsoft.Owin.Extensions):
app.UseStageMarker(PipelineStage.MapHandler);
Probably the reason if you upgraded at some point from an older MVC:
Make sure you don't have
<add key="owin:AutomaticAppStartup" value="false" />
in your web.config. It will suppress calling the startup
Instead change it to this
<add key="owin:AutomaticAppStartup" value="true" />
Somewhere along the line - when I upgraded to MVC 5 this got added (actually almost ironically it was a year ago tomorrow) and I never even knew what owin was until today when I tried to use it.
I also faced same problems when I migrated my already running MVC5 site to a new server. It gave me nightmares, just to recap I had to do all this to get it working
Add [assembly: OwinStartupAttribute(typeof([YourAssemblyName].Startup))] this to the Startup class (after the using statements and before the namespace declaration)
Add these keys to the <appSettings> section of web.config
<add key="owin:AppStartup" value="[NamespaceForYourStartUpClass].Startup, [YourAssemblyName]" />
<add key="owin:AutomaticAppStartup" value="true" />
And lastly as suggested by Martijn Evens add the following to <system.webserver> section in web.config
<modules runAllManagedModulesForAllRequests="true" />
For those who deal with legacy and (or) have migrated versions. Check windows "Roles and features", find what version of ASP.net is installed, and use exactly the same version in web.config for targetFramework, for example in my case it was 4.6 not 4.8, so
<system.web>
<httpRuntime targetFramework="4.6" requestValidationMode="2.0" maxQueryStringLength="2097151" />
<compilation targetFramework="4.6" optimizeCompilations="true">

Forbidden to browse WCF svc file?

I am using VS2010 + C# + .Net 4.0 + IIS 7.5 + Windows 7. When I open an svc file (in IIS manager, right click the svc file and select browse) for a WCF project in IIS, there is an error like this, any ideas what is wrong?
This type of page is not served.
Description: The type of page you have requested is not served because it has been explicitly forbidden. The extension '.svc' may be incorrect. Please review the URL below and make sure that it is spelled correctly.
Here is the content of the web.config file I am using, is it correct?
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<staticContent>
<remove fileExtension=".svc" />
</staticContent>
<handlers>
<remove name="svc-ISAPI-2.0" />
<remove name="svc-Integrated" />
<add name="svc-ISAPI-2.0" path="*.svc" verb="*" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="Script" preCondition="classicMode,runtimeVersionv2.0,bitness32" />
</handlers>
</system.webServer>
</configuration>
You may have to launch the command servicemodelreg –ia in Visual Studio command prompt.
If it's not working, check if you have "WCF http activation" feature installed (Add/Remove Programs - Turn Windows Features On or Off - Microsoft .Net 3.5.1).
UPDATE 1: Probably your application is hosted under .NET 2.0 App Pool. Go to IIS Manager and check for Basic Settings… link. Click Select button and you will see which option are you using. Change it to use .NET 4.0
UPDATE 2: Your web.config file seems incomplete. I suggest you to configure your service using WCF Configuration Editor tool. Launch it (make sure you are using .NET 4 version of the tool) and open your web.config file. Create service configuration and service endpoint configuration, then save it.
Its likely the mime types not setup correctly on IIS, try using the aspnet_regiis tool. Failing that, I'd recommend adding a mimetype to your virtual directory in iis for .svc files to be handled by the .NET runtime.

Getting "The WebResource.axd handler must be registered in the configuration to process this request." error

I'm getting this error while running my ASP.NET app on IIS7. I've tried doing what it says to do but it doesn't help.
The WebResource.axd handler must be
registered in the configuration to
process this request.
> <!-- Web.Config Configuration File -->
>
> <configuration>
> <system.web>
> <httpHandlers>
> <add path="WebResource.axd" verb="GET" type="System.Web.Handlers.AssemblyResourceLoader" validate="True" />
> </httpHandlers>
> </system.web>
> </configuration>
I'm using a little bit of AJAX which is what I think is causing the issue. Has anyone encountered this before?
I figured it out so I'm posting it here for search reasons. It is a bug in ASP.NET and it has to do with having ColdFusion installed. Microsoft hasn't yet released a fix.
There are two ways to fix this.
Change the AppPool in IIS7 to "Classic .NET AppPool". I'm not sure of any implications with this setting.
Remove all the references to ColdFusion from your applicationHost.config file in system32\inetsrv\config.
ColdFusion installs a global wildcard handler mapping which apparently overrides many of the standard .NET handlers. The solutions mentioned work just fine, but if you can't switch to Classic Mode and don't want to screw with your ColdFusion installation, you can remove the inherited handler mapping at the individual site level.
To do this, go to the site in question in IIS, double-click on "Handler Mappings" under the "IIS" section, and find the handler named something like "AboMapperCustom-XXXXXX" with "*" for the Path. Select the entry and click "Remove" in the sidebar. This will only remove the mapping for your application, so it won't break any existing CF sites on the server.
In IIS7 you need to add the <httpHandler> section to <system.webServer> instead of <system.web>. Here is an example.
I got this error after carelessly copying my app's web.config between a pair of clustered servers, which overwrote the tag:
<system.webServer>
<handlers>
<remove name="AboMapperCustom-XXXXXXXX" />
</handlers>
</system.webServer>
with
<system.webServer>
<handlers>
<remove name="AboMapperCustom-YYYYYYYY" />
</handlers>
</system.webServer>
Locating the proper ID as per Josh's response and correcting the tag fixed it, but more importantly, will presumably keep that handler mapping from sneaking back in.
The issue happened to me on new Windows 2016 server where ASP.NET 4.6 was not installed. After installation everything got fixed.
Steps
- Run Server Manager
- Manage > Add Roles and Features
- Server Roles
- Web Server (IIS) > Web Server > Application Development > ASP.NET 4.6
I had this problem and that reason was incompatibility between Coldfusion and some configurations of ASP.NET applications when IIS App pool is in integrated mode. Coldfusion must be disable .

Categories