Error accesing ASP.net MVC Application under Umbraco Application IIS - c#

I am using Umbraco 7.2.4 Application in our Project, I have another application which should run under Umbraco Site. Like as Below:
Umbraco Root URL: SampleUmbraco.com
Child Application : SampleUmbraco.com/MyApplication
I create a sub application under the Root Umbraco Application in IIS, and I added my Application URL to “umbracoReservedPaths”: “~/myApplication”.
But still my child application “SampleUmbraco.com/MyApplication” is still not running.
Do I need to change any other configuration settings?
Can any one one Help me in this issue?

Is myApplication not running at all, or does it give an error? We have previously had to add a location element around system.web and system.webServer in the web.config to make "sub" applications work. Like this:
<location path="." inheritInChildApplications="false">
<system.web>
..
</system.web>
<system.webServer>
..
</system.webServer>
</location>
But our sub applications were up, they "just" threw different YSOD errors.

Related

How to get user configured at <identity impersonate="true"> in web.config to execute some code with it own privileges (ASP.NET Core)

I'm having access denied errors when trying to create directories, move files etc. So I added (web.config) the impersonate user that have the right privileges to execute that functions.
So, in my web.config I have the current code:
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>...</handlers>
<aspNetCore .../>
</system.webServer>
</location>
<system.web>
<identity impersonate="true" password="password123" userName="DOMAIN\user123" />
</system.web>
</configuration>
And in my IIS, the DefaultAppPool pool have the Identity property set to ApplicationPoolIdentity.
iis pool configuration identity
And now I use WindowsIdentity.RunImpersonated() to run my code that create the folders and etc that I talked earlier with the purpose to use the configured user (DOMAIN\user123), and not the current User.Identity logged into, like DOMAIN\anyOtherCurrentUser:
WindowsIdentity.RunImpersonated(WindowsIdentity.GetCurrent().AccessToken, () => {
// create directory, move files, etc
});
The problem is when I run this code, calling WindowsIdentity.Getcurrent(), The user that I'm getting is the current one set on IIS Configuration IIS APPPOOL\DefaultAppPool and not the configured user in web.config DOMAIN\user123. Why this happens? How should I use this user configured in web.config?
You simply cannot.
Anything under <system.web> applies to only ASP.NET 4.x or older, and ASP.NET Core does not honor such.
Even for ASP.NET 4.x you should grant all permissions based on the application pool identity, not relying on impersonation for your own good.

Why is web.config getting created on publish not on build the project in Asp.Net Core API?

I have Asp.net Core 3.1 API project. When I build it doesn't create any web.config file, but when I publish the API using VS 2019 in a folder, it creates a web.config file.
So why it's not creating web.config on build ( I think it should not create because there is no web.config file in the project) but why does it create web.config file on publishing?
Edit: I am trying to deploy the application through Octopus, So I copy the bin folder content, and I need the web.config also. So for time being, I have manually created the web.config in the project and then building the project. so it copies the web.config to the bin folder. So Is this the right approach? or is there any way to generate web.config in the bin folder without manually creating it?
As far as I know, the web.config is used to tell IIS about how to use asp.net core module and handler to host the asp.net core application. When you build and test the application in the VS, there is no need to create the web.config, since it will read the launchSettings.json not web.config.
Web.config is a server configuration file, it is used to configures the ASP.NET Core Module.
The web.config file may provide additional IIS configuration settings that control active IIS modules. For information on IIS modules that are capable of processing requests with ASP.NET Core apps, see the IIS modules topic.
Asp.net core web.config content(Without this file, we couldn't directly host the asp.net core application on IIS)
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\basket.api.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout">
</aspNetCore>
</system.webServer>
</location>
</configuration>
IIS requires a web.config file for apps that run there.
In ASP.NET Core, web.config is lazy-generated. The assumption (flawed, IMO) is that you don't need web.config until you are ready to publish to IIS. But what if you have your IIS app pointed to your local code instance so that you don't have to republish your app every time you make a code change and want to test it in IIS? Or what if, like OP, you want to use alternate deployment methods?
A workaround in that case is to publish your app once, take the generated web.config, and copy it to the root of your VS project (same level as the bin folder). Subsequent builds will then copy the web.config to bin\debug\net6.0. Still not ideal, but this is better than manually creating web.config and potentially introducing an error in the file.

Having trouble adding asp.net projects on Visual Studio 2017

I am building two separate webpages, contained within two separate projects on Visual Studio 2017, using asp.net framework. I am trying to add my first project into my current solution, to link with my new project. I have no issues adding the project, but when I try to run the imported project, it is giving me the following message:
HTTP Error 403.14 - Forbidden The Web server is configured to not list
the contents of this directory
Most likely causes:
A default document is not configured for the requested URL, and
directory browsing is not enabled on the server.
It also states in the title bar:
IIS 10.0 Detailed Error - 403.14 - Forbidden
I can run the first project and the new project by themselves and everything works fine, but when they are in the same solution, only the original project seems to work. Can anyone help me?
I think you just need to set some configurations in the web.config
<configuration>
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
<system.webServer>
<directoryBrowse enabled="true" />
</system.webServer>
</configuration>

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.

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