gigi81 / sharpfastcgi

C# fastcgi protocol implementation plus shome usage examples. A good example on how to self-host your web application without the need of iis or mono.
MIT License
32 stars 15 forks source link

PlatformNotSupportedException: This operation requires IIS integrated pipeline mode #12

Closed icnocop closed 5 years ago

icnocop commented 5 years ago

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

Server Error in '/' Application.
This operation requires IIS integrated pipeline mode.
Description: 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.

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

Source Error:

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.

Stack Trace:

[PlatformNotSupportedException: This operation requires IIS integrated pipeline mode.]
   System.Web.HttpResponse.get_Headers() +175
   System.Web.HttpResponseWrapper.get_Headers() +10
   Microsoft.Owin.Host.SystemWeb.OwinCallContext.CreateEnvironment() +309
   Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContext.GetInitialEnvironment(HttpApplication application) +304
   Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContext.PrepareInitialContext(HttpApplication application) +15
   Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContextStage.BeginEvent(Object sender, EventArgs e, AsyncCallback cb, Object extradata) +265
   System.Web.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +316
   System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +132
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +163

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.

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 > Checkmark Web API. WebApplication7.zip

Steps to reproduce:

  1. Open solution in Visual Studio 2015.

  2. Build solution (Debug|Any CPU).

  3. Copy the following files to the root of the web application and also in bin: Grillisoft.FastCgi.AspNet.dll Grillisoft.FastCgi.dll Grillisoft.FastCgi.Loggers.Log4Net.dll Grillisoft.ImmutableArray.dll log4net.config log4net.dll

  4. Run .\Examples\windows-nginx-1.6.2\nginx.exe

  5. Update .\FastCgi.Server\bin\Debug\Grillisoft.FastCgi.Server.exe.config and set the PhysicalPath value to the full path of the web application root.

  6. Run .\FastCgi.Server\bin\Debug\Grillisoft.FastCgi.Server.exe

  7. Browse to http://localhost:8082/index.aspx.

  8. Notice the error: asp net mvc 5 server error

Any ideas?

Thank you.

icnocop commented 5 years ago

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

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.

gigi81 commented 5 years ago

Hi @icnocop, I think you need to use Owin to host asp.net mvc 5. Not 100% sure about the details, it needs a little bit of digging and trial and error. Maybe @mikdav can shed some light on this and might be able to help since they implemented the owin support. There is also an example on the readme that might be of help.

mikdav commented 5 years ago

Correct. The default MVC template assumes an IIS or IISExpress host and adds a bunch of things that are dependent on that host. If you only need WebAPI, you can go the OWIN host route, which is already implemented. This is what I implemented because we only use WebAPI at my company--not the rest of MVC.

If you need the rest of MVC (view rendering, etc), you will need to move to ASP.NET Core. I have not tested it, but ASP.NET Core can supposedly run on top of an OWIN compatible host, so it should work with what has already been built into sharpfastcgi.

gigi81 commented 5 years ago

Since there have been no further comments, I'm closing this.