i-e-b / Huygens

Cut down Cassini server for internally hosting IIS sites
Other
3 stars 1 forks source link

This operation requires IIS integrated pipeline mode. #2

Open icnocop opened 5 years ago

icnocop commented 5 years ago

Hi.

Thank you for Huygens.

I tried hosting my ASP.NET MVC 5 web application using Huygens but I received the following error:

Server Error in '/' Application.

This operation requires IIS integrated pipeline mode.

An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

System.PlatformNotSupportedException: This operation requires IIS integrated pipeline mode.

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

[PlatformNotSupportedException: This operation requires IIS integrated pipeline mode.]
--
  | at System.Web.HttpResponse.get_Headers()
  | at System.Web.HttpResponseWrapper.get_Headers()
  | at Microsoft.Owin.Host.SystemWeb.OwinCallContext.CreateEnvironment()
  | at Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContext.GetInitialEnvironment(HttpApplication application)
  | at Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContext.PrepareInitialContext(HttpApplication application)
  | at Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContextStage.BeginEvent(Object sender, EventArgs e, AsyncCallback cb, Object extradata)
  | at System.Web.HttpApplication.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
  | at System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step)
  | at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.7.3160.0

I can host my web application in IIS without issues.

Will implementing "Add OWIN rq/tx to the compatibility classes" in your "To do" list resolve this issue?

Thank you!

i-e-b commented 5 years ago

Can you tell me the versions you are using, and which host (direct or socket)? There are some issues with weird assumptions made by the underlying ASPNet libraries (like basing the memory model on the exe name). I thought I got them in the recent revisions (this commit https://github.com/i-e-b/Huygens/commit/1bf4737cf17fca252f2b47fe2a969b512fd007df)

icnocop commented 5 years ago

I'm using Hyugens 1.4.5 and SocketServer.

        [TestMethod]
        public void Huygens()
        {
            using (var server = new SocketServer(32768, "/", projectPath))
            {
                server.Start();

                while (keepRunning)
                {
                    Thread.Sleep(1000);
                }

                server.ShutDown();
            }
        }

Thank you.

icnocop commented 5 years ago

I've attached a sample project that can be used to reproduce the issue here: WebApplication5.zip

The web application was created using Visual Studio 2015 Update 3: File > New Project > Templates > Visual C# > Web > .NET Framework 4.5.2 > ASP.NET Web Application (.NET Framework) > MVC + Web API.

Steps to reproduce:

  1. Open solution in Visual Studio 2015.
  2. Edit ".\WebApplication5\UnitTestProject1\UnitTest1.cs" and set the value of the projectPath variable to the output path of the WebApplication5 project.
  3. Build solution.
  4. Debug the Huygens test.
  5. After the server has started, navigate to http://localhost:32768.
  6. Notice the error: this operation requires iis integrated pipeline mode

Thank you!

i-e-b commented 5 years ago

Thanks for that. I'll have a look as soon as I can.

i-e-b commented 5 years ago

There's a test in C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Web.dll in the Headers property that is testing for the worker request to be an exact internal type. I might be able to trick it, or change something further up the stack... but I'm not sure.

i-e-b commented 5 years ago

From what I can see, Microsoft have forced you to pick either IIS integration or 'real' OWIN with self-hosting, but not have both. You might be able to use the OwinHost package ( as described at https://docs.microsoft.com/en-us/aspnet/aspnet/overview/owin-and-katana/an-overview-of-project-katana ) and run the socket listener inside another process.

It might be possible to extend Huygens with something like https://github.com/aspnet/AspNetKatana/blob/dev/src/OwinHost/Program.cs#L87 But I don't have the time to do that right now, sorry.

icnocop commented 5 years ago

Thank you for doing research to find out the underlying issue.

I tried using the OwinHost v4.0.0.0 NuGet package and run OwinHost.exe, but that only runs the code in Startup.cs and so doesn't serve MVC pages, only Web API services.

From what I've read, the only way to self host MVC + OWIN is to use ASP.NET Core.

icnocop commented 5 years ago

The other options I've found:

  1. Remove OwinStartup and just use Application_Start instead. To get an instance of HttpConfiguration, use GlobalConfiguration.Configure.
  2. Replace OwinStartup with WebActivatorEx.PreApplicationStartMethod using WebActivator.

But in either case, IAppBuilder cannot be used.