Skip to content
This repository has been archived by the owner on Nov 1, 2018. It is now read-only.

IIS virtual directories #14

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

IIS virtual directories #14

Tratcher opened this issue Oct 15, 2015 · 42 comments

Comments

@Tratcher
Copy link
Member

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
Copy link
Member

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

@Tratcher
Copy link
Member Author

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

@davidfowl
Copy link
Member

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
Copy link
Member Author

Depends on aspnet/KestrelHttpServer#214

@Tratcher
Copy link
Member Author

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

@rubenprins
Copy link

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
Copy link
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.

@Fosol
Copy link

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
Copy link
Member Author

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
Copy link

        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
Copy link
Member Author

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

@leo9223
Copy link

leo9223 commented Nov 1, 2016

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

@Tratcher
Copy link
Member Author

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
Copy link

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
Copy link

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
Copy link
Member Author

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
Copy link

leo9223 commented Nov 2, 2016

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

@guardrex
Copy link
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
Copy link

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
Copy link
Member Author

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
Copy link

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
Copy link

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
Copy link
Member Author

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
Copy link

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
Copy link
Member

@evil-shrike why do you need it?

@evil-shrike
Copy link

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
Copy link

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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests