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

IIS virtual directories #14

Closed
Tratcher opened this Issue Oct 15, 2015 · 42 comments

Comments

Projects
None yet
@Tratcher
Member

Tratcher commented Oct 15, 2015

When we're spun up behind IIS / HttpPlatformHandler how do we know what the virtual directory is? We need this to correctly set PathBase in the app. Ideally we'd set PathBase as part of the initial server address configuration, but at that point we're only given the port via environment variable.
@davidfowl

@davidfowl

This comment has been minimized.

Show comment
Hide comment
@davidfowl

davidfowl Oct 15, 2015

Member

Should handle that based on the path passed into server.urls

Member

davidfowl commented Oct 15, 2015

Should handle that based on the path passed into server.urls

@Tratcher

This comment has been minimized.

Show comment
Hide comment
@Tratcher

Tratcher Oct 15, 2015

Member

Yes, but how do you get that information from IIS to server.urls? Right now we only get the port.

Member

Tratcher commented Oct 15, 2015

Yes, but how do you get that information from IIS to server.urls? Right now we only get the port.

@davidfowl

This comment has been minimized.

Show comment
Hide comment
@davidfowl

davidfowl Oct 19, 2015

Member

We'd need to restructure a bit. It can be setup in the M.A.Hosting.json file.

Member

davidfowl commented Oct 19, 2015

We'd need to restructure a bit. It can be setup in the M.A.Hosting.json file.

@muratg muratg added this to the 1.0.0-rc1 milestone Oct 19, 2015

@Tratcher

This comment has been minimized.

Show comment
Hide comment
@Tratcher
Member

Tratcher commented Oct 19, 2015

@muratg muratg removed this from the 1.0.0-rc1 milestone Oct 19, 2015

@Tratcher

This comment has been minimized.

Show comment
Hide comment
@Tratcher

Tratcher Oct 23, 2015

Member

Workaround: put your app in a app.Map("/vdir" ...
aspnet/Hosting#416 (comment)

Member

Tratcher commented Oct 23, 2015

Workaround: put your app in a app.Map("/vdir" ...
aspnet/Hosting#416 (comment)

@rubenprins

This comment has been minimized.

Show comment
Hide comment
@rubenprins

rubenprins Nov 2, 2015

Please don't require us to hard code the IIS vdir in external config files, like M.A.Hosting.json, when IIS and HttpPlatformHandler already know this.

Just pass this information on for example in an environment variable, like %HTTP_PLATFORM_VDIR%, so you can say

    <httpPlatform stdoutLogEnabled="false" stdoutLogFile="log.log" startupTimeLimit="20" processPath="%HOME%\site\kestrel.cmd" arguments="http://localhost:%HTTP_PLATFORM_PORT%/%HTTP_PLATFORM_VDIR%">
      <environmentVariables></environmentVariables>
    </httpPlatform>

rubenprins commented Nov 2, 2015

Please don't require us to hard code the IIS vdir in external config files, like M.A.Hosting.json, when IIS and HttpPlatformHandler already know this.

Just pass this information on for example in an environment variable, like %HTTP_PLATFORM_VDIR%, so you can say

    <httpPlatform stdoutLogEnabled="false" stdoutLogFile="log.log" startupTimeLimit="20" processPath="%HOME%\site\kestrel.cmd" arguments="http://localhost:%HTTP_PLATFORM_PORT%/%HTTP_PLATFORM_VDIR%">
      <environmentVariables></environmentVariables>
    </httpPlatform>
@davidfowl

This comment has been minimized.

Show comment
Hide comment
@davidfowl

davidfowl Nov 2, 2015

Member

@rubenprins That fix is coming. This is a workaround until the fix is available. We're working with the httpPlatformHandler team to fix bugs found in beta8 and rc1.

Member

davidfowl commented Nov 2, 2015

@rubenprins That fix is coming. This is a workaround until the fix is available. We're working with the httpPlatformHandler team to fix bugs found in beta8 and rc1.

@Fosol

This comment has been minimized.

Show comment
Hide comment
@Fosol

Fosol Dec 9, 2015

I don't understand the workaround.

Are you saying we need to configure the sub-application within the parent application. Essentially copying the Configure method of the sub-application into the parent?

Fosol commented Dec 9, 2015

I don't understand the workaround.

Are you saying we need to configure the sub-application within the parent application. Essentially copying the Configure method of the sub-application into the parent?

@Tratcher

This comment has been minimized.

Show comment
Hide comment
@Tratcher

Tratcher Dec 9, 2015

Member

Sup-apps have different paths (e.g. /subapp/controller/foo) which breaks routing. The workaround is to use Map("/subapp"... In your sub app to remove the extra path segment.

Member

Tratcher commented Dec 9, 2015

Sup-apps have different paths (e.g. /subapp/controller/foo) which breaks routing. The workaround is to use Map("/subapp"... In your sub app to remove the extra path segment.

@pksorensen

This comment has been minimized.

Show comment
Hide comment
@pksorensen

pksorensen Jan 13, 2016

        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            app.Map("/testvirt", map => Configure1(map, env, loggerFactory));
        }
        // Configure is called after ConfigureServices is called.
        public void Configure1(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {

            loggerFactory.MinimumLevel = LogLevel.Information;
            loggerFactory.AddConsole();
            loggerFactory.AddDebug();

            // Add the platform handler to the request pipeline.
            app.UseIISPlatformHandler();

            app.UseDefaultFiles();
            // Configure the HTTP request pipeline.
            app.UseStaticFiles();

        }

I havent been able to get the workaround to work with an app configuration above.

pksorensen commented Jan 13, 2016

        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            app.Map("/testvirt", map => Configure1(map, env, loggerFactory));
        }
        // Configure is called after ConfigureServices is called.
        public void Configure1(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {

            loggerFactory.MinimumLevel = LogLevel.Information;
            loggerFactory.AddConsole();
            loggerFactory.AddDebug();

            // Add the platform handler to the request pipeline.
            app.UseIISPlatformHandler();

            app.UseDefaultFiles();
            // Configure the HTTP request pipeline.
            app.UseStaticFiles();

        }

I havent been able to get the workaround to work with an app configuration above.

@Tratcher Tratcher added 3 - Done and removed 0 - Backlog labels Jan 13, 2016

@Tratcher

This comment has been minimized.

Show comment
Hide comment
@Tratcher

Tratcher Mar 25, 2016

Member

This as been fixed in AspNetCoreModule v0.8: #105.

Member

Tratcher commented Mar 25, 2016

This as been fixed in AspNetCoreModule v0.8: #105.

@leo9223

This comment has been minimized.

Show comment
Hide comment
@leo9223

leo9223 Nov 1, 2016

Asp.net core still not working under virtual directory in IIS

leo9223 commented Nov 1, 2016

Asp.net core still not working under virtual directory in IIS

@Tratcher

This comment has been minimized.

Show comment
Hide comment
@Tratcher

Tratcher Nov 1, 2016

Member

@leo9223 virtual directories or sub applications? These are commonly confused. Sub applications should work but there's no support for virtual directories.

Member

Tratcher commented Nov 1, 2016

@leo9223 virtual directories or sub applications? These are commonly confused. Sub applications should work but there's no support for virtual directories.

@leo9223

This comment has been minimized.

Show comment
Hide comment
@leo9223

leo9223 Nov 2, 2016

@Tratcher Virtual directories are not working, but when I convert that directory to application then it is working. yea sub application is working.

leo9223 commented Nov 2, 2016

@Tratcher Virtual directories are not working, but when I convert that directory to application then it is working. yea sub application is working.

@leo9223

This comment has been minimized.

Show comment
Hide comment
@leo9223

leo9223 Nov 2, 2016

@Tratcher However different webconfigs working for IIS10 and IIS8.5

on IIS10 app works with this setting
<aspNetCore processPath="dotnet" arguments=".\myApp.dll" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false" />

on IIS8.5 app works with this setting
<aspNetCore processPath="C:\Program Files\dotnet\dotnet.exe" arguments=".\myApp.dll" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false" />

I don't know why. can you please tell me why it is happening?

leo9223 commented Nov 2, 2016

@Tratcher However different webconfigs working for IIS10 and IIS8.5

on IIS10 app works with this setting
<aspNetCore processPath="dotnet" arguments=".\myApp.dll" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false" />

on IIS8.5 app works with this setting
<aspNetCore processPath="C:\Program Files\dotnet\dotnet.exe" arguments=".\myApp.dll" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false" />

I don't know why. can you please tell me why it is happening?

@Tratcher

This comment has been minimized.

Show comment
Hide comment
@Tratcher

Tratcher Nov 2, 2016

Member

Your IIS 10 machine probably has dotnet on the system path, where your other machine doesn't. Did you restart the second machine after the install?

Member

Tratcher commented Nov 2, 2016

Your IIS 10 machine probably has dotnet on the system path, where your other machine doesn't. Did you restart the second machine after the install?

@leo9223

This comment has been minimized.

Show comment
Hide comment
@leo9223

leo9223 Nov 2, 2016

@Tratcher I just restarted the IIS not the machine, let me check. Thank you

leo9223 commented Nov 2, 2016

@Tratcher I just restarted the IIS not the machine, let me check. Thank you

@guardrex

This comment has been minimized.

Show comment
Hide comment
@guardrex

guardrex Nov 2, 2016

Contributor

@leo9223 Just for future reference, @pan-wang advised for the docs that you should be able to avoid a restart if you execute net stop was /y followed by net start w3svc.

Contributor

guardrex commented Nov 2, 2016

@leo9223 Just for future reference, @pan-wang advised for the docs that you should be able to avoid a restart if you execute net stop was /y followed by net start w3svc.

@buddalasunil999

This comment has been minimized.

Show comment
Hide comment
@buddalasunil999

buddalasunil999 Nov 5, 2016

I have the same problem.. I want to add ASP.NET Web API application (Admin) under ASP.NET Core website (Test) as shown in the image below. But the admin doesn't work because of the corehandler. How do I ask the corehandler to just work with the root application but not the applications inside it.
image

buddalasunil999 commented Nov 5, 2016

I have the same problem.. I want to add ASP.NET Web API application (Admin) under ASP.NET Core website (Test) as shown in the image below. But the admin doesn't work because of the corehandler. How do I ask the corehandler to just work with the root application but not the applications inside it.
image

@Tratcher

This comment has been minimized.

Show comment
Hide comment
@Tratcher

Tratcher Nov 5, 2016

Member

@buddalasunil999 Web.Config files are inherited by child apps. inside your admin web.config in the handlers section you can remove the aspNetCore handler that was added in the parent site.

Member

Tratcher commented Nov 5, 2016

@buddalasunil999 Web.Config files are inherited by child apps. inside your admin web.config in the handlers section you can remove the aspNetCore handler that was added in the parent site.

@buddalasunil999

This comment has been minimized.

Show comment
Hide comment
@buddalasunil999

buddalasunil999 Nov 5, 2016

@Tratcher Yeah just figured it out.. it's inherting the handler, added remove handler to child config and started working. Thanks

buddalasunil999 commented Nov 5, 2016

@Tratcher Yeah just figured it out.. it's inherting the handler, added remove handler to child config and started working. Thanks

@sturlath

This comment has been minimized.

Show comment
Hide comment
@sturlath

sturlath Dec 4, 2016

@Tratcher you say "there's no support for virtual directories.". After I saw this comment I have searched everywhere to have it confirmed without finding anything on it, except in comments from you.

Are you saying I will have to set up a new site and deploy there?

So the setup below will never work because posservice is a virtual directory?
fyrirspurn

What I need is to be able to call this web api url ? https://A.HTTPS.Site/posservice/api/v1/authentication/accesstoken

My api controller attribute routing looks like [Route("api/v1/authentication")] with this on a method [HttpPost("accesstoken"), AllowAnonymous]

  1. Create a sub application (lets call it POS) straight under A.HTTPS.site
  2. Where do I point the service (physical path) to? Where does the "api/v1" part plug in? Nb. I tried every version I could think of, to no avail.

I have tried just about everything under the sun I believe (even some map #14 (comment) things).. so some help would be appreciated :-)

sturlath commented Dec 4, 2016

@Tratcher you say "there's no support for virtual directories.". After I saw this comment I have searched everywhere to have it confirmed without finding anything on it, except in comments from you.

Are you saying I will have to set up a new site and deploy there?

So the setup below will never work because posservice is a virtual directory?
fyrirspurn

What I need is to be able to call this web api url ? https://A.HTTPS.Site/posservice/api/v1/authentication/accesstoken

My api controller attribute routing looks like [Route("api/v1/authentication")] with this on a method [HttpPost("accesstoken"), AllowAnonymous]

  1. Create a sub application (lets call it POS) straight under A.HTTPS.site
  2. Where do I point the service (physical path) to? Where does the "api/v1" part plug in? Nb. I tried every version I could think of, to no avail.

I have tried just about everything under the sun I believe (even some map #14 (comment) things).. so some help would be appreciated :-)

@Tratcher

This comment has been minimized.

Show comment
Hide comment
@Tratcher

Tratcher Dec 5, 2016

Member

Yes, if you made the posservice level a sub-application and pointed it at your ASP.NET Core app then it should work. Also remove the nested posservice/api and /posservice/api/v1 sub-applications definitions, they'll mess up your routing. Any segments marked as a sub-application get moved from HttpContext.Path to HttpContext.PathBase and Rout only operates on Path.

Member

Tratcher commented Dec 5, 2016

Yes, if you made the posservice level a sub-application and pointed it at your ASP.NET Core app then it should work. Also remove the nested posservice/api and /posservice/api/v1 sub-applications definitions, they'll mess up your routing. Any segments marked as a sub-application get moved from HttpContext.Path to HttpContext.PathBase and Rout only operates on Path.

@evil-shrike

This comment has been minimized.

Show comment
Hide comment
@evil-shrike

evil-shrike Sep 8, 2017

Hi,
previously on full .net there was System.Web.Hosting.HostingEnvironment.ApplicationVirtualPath which returned virtual dir/app name.
Having HttpContext.PathBase is very nice, but it exists only during request handling, which ApplicationVirtualPath was available in IHttpModule.Init for example.

Is there any way to get base path before on starup/configure (before request processing)?

evil-shrike commented Sep 8, 2017

Hi,
previously on full .net there was System.Web.Hosting.HostingEnvironment.ApplicationVirtualPath which returned virtual dir/app name.
Having HttpContext.PathBase is very nice, but it exists only during request handling, which ApplicationVirtualPath was available in IHttpModule.Init for example.

Is there any way to get base path before on starup/configure (before request processing)?

@davidfowl

This comment has been minimized.

Show comment
Hide comment
@davidfowl

davidfowl Sep 8, 2017

Member

@evil-shrike why do you need it?

Member

davidfowl commented Sep 8, 2017

@evil-shrike why do you need it?

@evil-shrike

This comment has been minimized.

Show comment
Hide comment
@evil-shrike

evil-shrike Sep 8, 2017

@davidfowl I'm migrating some app/lib onto core from mvc5 and there I have some global singleton config (let's call it XConfig) which is available via DI for other components. I put the base path from ApplicationVirtualPath into that XConfig on start.
Then for example some View calls its Model's method, which returns some html markup, for this it uses other injected component which only has XConfig and takes basePath from it.
Now I have to pass HttpRequest all the way (better), on initialize XConfig on first request (worse).
I'm not telling that it will be impossible or bad but just decided to ask. As probably server (IIS) can pass this info on initializing not only on request handling.

evil-shrike commented Sep 8, 2017

@davidfowl I'm migrating some app/lib onto core from mvc5 and there I have some global singleton config (let's call it XConfig) which is available via DI for other components. I put the base path from ApplicationVirtualPath into that XConfig on start.
Then for example some View calls its Model's method, which returns some html markup, for this it uses other injected component which only has XConfig and takes basePath from it.
Now I have to pass HttpRequest all the way (better), on initialize XConfig on first request (worse).
I'm not telling that it will be impossible or bad but just decided to ask. As probably server (IIS) can pass this info on initializing not only on request handling.

@bharathpbk

This comment has been minimized.

Show comment
Hide comment
@bharathpbk

bharathpbk Feb 20, 2018

Hi when i deploy asp.net core 2.0 with IIS Windows authentication I am getting Cors Error with angular. Please suggest any example

bharathpbk commented Feb 20, 2018

Hi when i deploy asp.net core 2.0 with IIS Windows authentication I am getting Cors Error with angular. Please suggest any example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment