Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deploy Umbraco as a child IIS application not working #11891

Closed
ylangevin opened this issue Jan 20, 2022 · 12 comments
Closed

Deploy Umbraco as a child IIS application not working #11891

ylangevin opened this issue Jan 20, 2022 · 12 comments

Comments

@ylangevin
Copy link

Which exact Umbraco version are you using? For example: 9.0.1 - don't just write v9

9.1.2

Bug summary

When I setup Umbraco as a child application named "cms" of my web site in IIS, the site returns script errors.

When I browse to the backoffice, I see 404 errors on resource load (js, css, etc.).

When I browse to the client pages, the browser always display a "Page Not Found Error".

Specifics

This was tested in Chrome and Edge trying to access http://[web site url]/cms and http://[web site url]/cms/Umbraco#

IIS setup like this:
IISApp

the web site and cms application are using their own application pool.

this is the page displayed when browsing to the content pages:
PageNotfound

this is the screen displayed when accessing the backoffice. Notice the javascript 404 errors related the the url missing the cms.
BackOffice
.

To enable the child application support, the "ApplicationVirtualPath" setting was set in the appSettings.json:

...
"Umbraco": {
"CMS": {
"Hosting": {
"Debug": false,
"ApplicationVirtualPath": "/cms/"
}
...

Steps to reproduce

In IIS

1 - Create your web site (.net core 5) and set the location to a directory not being Umbraco. Create an application pool with the "No Managed Code" and assign it to the site.
2 - Create a child application to your web site and name it cms. Set the location to the Umbraco client application. Create an application pool with the "No Managed Code" and assign it to the site.
3 - Open the appSettings.json and set the "ApplicationVirtualPath" to either "/cms" or "/cms/".
4 - try to browse to the backoffice: http://[your web site/cms/Umbraco#.
5 - see the 404 errors.

BackOffice

Expected result / actual result

Umbraco should work normally without errors. I should be able to access either the backoffice or content pages.

@a-t-k
Copy link

a-t-k commented Feb 15, 2022

Hey. Yes. Umbraco 9 does not support virtual paths in IIS.
I can't say why this is the case in version 9 either. But, version 8 supported that well.

Actually that shouldn't be the problem. A "BackOfficeServerVariables" controller already supplies the whole range of URLs. If the "GetServerVariablesAsync" method is tweaked a bit, it can work again. Experimenting a bit in "LinkGenerator" would also help.

It is enough to add the virtual path from IIS to the rest of the URL.

@a-t-k
Copy link

a-t-k commented Feb 15, 2022

I hope that this will work again sometime, because there is quite a difference having a URL "https://domainname/cms/umbraco" instead of "https://cms.domainname/umbraco"

@ylangevin
Copy link
Author

Sorry for the specific version, I forgot to put it there. We are using 9.1.2.

you are totally right that using another subdomain vs adding a child application is quite different and we were trying to avoid creating a subdomain only for a child application.

I am not very familiar with the Umbraco code ( I only spent a few hours on this) but I was able to debug the code up to the LinkGenerator and noticed this is where I could probably do something but I wasn't sure where to get the virtual directory name from there (app settings vs something else). I read something about .net core having the UsePathBaseExtensions. I tried to use it to get something quickly working but no luck. If I remember well, a lot of static methods are used in this area which is not ideal to inject objects or overwrite a service from the UserComposer. I will need to look more into this code to understand it better to see what would be the best solution for us, but I'm not sure I will have the cycles to do so.

Meanwhile, I will keep my fingers crossed for a fix in the code base :). I will keep tracking this issue.

thanks!

@a-t-k
Copy link

a-t-k commented Feb 16, 2022

you can read more about server variables here: https://24days.in/umbraco-cms/2021/umbraco-9-server-variables/

@a-t-k
Copy link

a-t-k commented Mar 3, 2022

On iis you can create two rewrite routings with "Url Rewrite" tool (you must install it first).

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Umbraco" enabled="true" stopProcessing="true">
                    <match url="(.*)" ignoreCase="false" />
                    <action type="Rewrite" url="{C:1}cms/umbraco/backoffice{C:2}" logRewrittenUrl="true" />
                    <conditions>
                        <add input="{REQUEST_URI}" pattern="^(.+)umbraco/backoffice(.+)$" />
                    </conditions>
                </rule>
                <rule name="UmbracoServervariables" enabled="true" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions>
                        <add input="{REQUEST_URI}" pattern="^(.+)umbraco/ServerVariables(.+)$" />
                    </conditions>
                    <action type="Rewrite" url="{C:1}cms/umbraco/ServerVariables{C:2}" logRewrittenUrl="true" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

After this umbraco return "417 The required antiforgery cookie "UMB-XSRF-V" is not present."

@a-t-k
Copy link

a-t-k commented Mar 3, 2022

Its importend to set same app poolt to root folder "Default Web Site" as umbraco use. When its not the same app pool you get unauthorice http error.

@umbrabot
Copy link

umbrabot commented Mar 4, 2022

Hi @ylangevin,

We're writing to let you know that we would love some help with this issue. We feel that this issue is ideal to flag for a community member to work on it. Once flagged here, folk looking for issues to work on will know to look at yours. Of course, please feel free work on this yourself ;-). If there are any changes to this status, we'll be sure to let you know.

For more information about issues and states, have a look at this blog post

Thanks muchly, from your friendly Umbraco GitHub bot :-)

@a-t-k
Copy link

a-t-k commented Mar 7, 2022

Umbraco extension method "GetUmbracoApiServiceBaseUrl" for class "LinkGenerator" does not return URL with full path.
Microsoft implementation of method "GetPathByAction" for class "LinkGenerator" accept one more parameter "pathBase", but this one is not present in umbraco implementation. When this parameter ist not given, microsoft implementation will be use default one. Default one is atm allways "" and this do return allways not full URI to resource.

Web-Client use ServerVariables to get resource URL. ResourceVariables is generatet in Umbraco Backend. You can register you handler to "ServerVariablesParsingNotification" and generate own code.

In most cases handler generate here resource url with this call: this.linkGenerator.GetUmbracoApiServiceBaseUrl(controller => controller.GetUrl())}
and register frontend attribute with returned url.

This cause in this case URL without the needed pathBase.

When someone want to fix it, it would be nixe. I have atm no time for this.

To check it you can use folowed code:

var controllerMethod = ExpressionHelper.GetMethodInfo<CustomController>(c => c.GetUrl());
            var metaData = PluginController.GetMetadata(typeof(CustomController));
            var area = metaData.AreaName;
            var controllerName = ControllerExtensions.GetControllerName(typeof(CustomController));
            var d = new Dictionary<string, object>
            {
                ["area"] = area
            };
            var routeValues = d.Aggregate(
                new ExpandoObject() as IDictionary<string, object>,
                (a, p) =>
                {
                    a.Add(p.Key, p.Value);
                    return a;
                });

            var pathString = new PathString(this.hostingEnvironment.ApplicationVirtualPath);
            var resultUrl = this.linkGenerator.GetPathByAction(controllerMethod.Name, controllerName, routeValues, pathString);

@linuxct
Copy link

linuxct commented Apr 1, 2022

Subscribing to this. Turns out, this issue is not specific to child applications to IIS, and in fact when attempting to deploy it inside a Docker Linux container, it happens as well. In fact, just changing the ApplicationVirtualPath to anything that's not "/" breaks the application, even when running it locally with Visual Studio 2022.

Details on the setup in which I attempted to do it:

Umbraco 9.4.1
Using Docker CE 20.10.12, docker-compose version 1.21.0
Edge router/Proxy: Traefik 2.7

appsettings.json:

// ...
"Umbraco": {
    "CMS": {
        "Hosting": {
            "Debug": false,
            "ApplicationVirtualPath": "/cms/"
        }
    }
}
// ...

docker-compose.yml:

version: '3.3'

services:
  dotnet-umbraco:
    image: dotnetumbraco:latest # Taken from my Dockerfile
    restart: unless-stopped
    labels:
      - traefik.enable=true
      - traefik.http.routers.dotnet-umbraco.entryPoints=web
      - traefik.http.routers.dotnet-umbraco.rule=Host(`host.name.com`) && PathPrefix(`/cms`)
      # - traefik.http.routers.dotnet-umbraco.tls=true
      - traefik.http.services.dotnet-umbraco.loadbalancer.server.port=80

With this exact config, the installer shows an error (i.e. the same errors as described in this post regarding the backoffice issues), and the resources in wwwroot cannot load, because they are still mapped to host.name.com/resource instead of host.name.com/cms/resource.

If I load the application with Visual Studio 2022, I can manually change the path (removing /cms) and see how the resources load successfully:
image

image

Thanks @a-t-k for submitting the PR, hope it gets merged soon.

edit: Fixed Umbraco version, it's 9.4.1 not 9.1.4.

@IsaMorphic
Copy link

Hey question, is this fixed in v10 or v11?

@ianleeder
Copy link

ianleeder commented Nov 29, 2022

@IsaMorphic Not fixed in v10.

a-t-k pushed a commit to a-t-k/Umbraco-CMS that referenced this issue Dec 17, 2022
a-t-k pushed a commit to a-t-k/Umbraco-CMS that referenced this issue Dec 17, 2022
a-t-k pushed a commit to a-t-k/Umbraco-CMS that referenced this issue Dec 20, 2022
a-t-k pushed a commit to a-t-k/Umbraco-CMS that referenced this issue Dec 20, 2022
a-t-k pushed a commit to a-t-k/Umbraco-CMS that referenced this issue Dec 20, 2022
a-t-k pushed a commit to a-t-k/Umbraco-CMS that referenced this issue Dec 20, 2022
a-t-k pushed a commit to a-t-k/Umbraco-CMS that referenced this issue Dec 21, 2022
a-t-k pushed a commit to a-t-k/Umbraco-CMS that referenced this issue Jan 6, 2023
a-t-k pushed a commit to a-t-k/Umbraco-CMS that referenced this issue Jan 11, 2023
@nul800sebastiaan
Copy link
Member

Hey all, I am going to close this issue as "won't fix", please read the reasoning here: #13592

@nul800sebastiaan nul800sebastiaan closed this as not planned Won't fix, can't repro, duplicate, stale May 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment