3

In my ASP.NET 5 application, I generate a drop-down list thanks to the HtmlHelper. Anything works fine in localhost except in production, we have a 500 server error.

enter image description here

I was able to find the cast which is performed, on github, and it's performed into the MVC lib, precisely into the DefaultHtmlGenerator class :

enter image description here

This cast is performed when we want to render a drop-down list depending on the SelectList we pass in parameter.

We can see that the comment specify we have to use at least the version 4.5 of the framework. At the end of the stacktrace we see the version of the framework which is used in production :

enter image description here

However, the version 4.5 is installed on our server, and I tried to insert a web.config file into the wwwroot of the projet to force the target framework :

enter image description here

But it doesn't work, and we indicate correctly the framework we want to use into our project.json :

enter image description here

So my question is : can we use compilation targetFramework="4.5" and httpRuntime targetFramework="4.5" to force IIS for using the version 4.5 ?

Christophe Gigax
  • 3,211
  • 4
  • 25
  • 37

1 Answers1

0

NOTE

You are trying to run in IIS managed code. You can't do that. IIS doesn't manage the process anymore. Basically, IIS is going to run an EXE and is going to forward requests to it. That's it.

Check the procedure bellow to properly deploy a DNX application to IIS. Or better, read the documentation right here: http://docs.asp.net/en/latest/publishing/iis.html


Requirements

  • Windows 7 or better
  • Windows Server 2008 R2 or better
  • Have IIS installed

Procedure

First, make sure you have the HTTP Platform Handler installed in your IIS (x86 / x64).

Publish your application to the file system and take the content of the \artifacts\bin\MyWebApp\Release\Publish folder and copy it into your IIS Server.

When configuring your application, target the wwwroot folder that you copied over.

Now you'll need to unlock the system.webServer/handlers section which can be found in IIS Manager on the server node under Configuration Editor. Search for the right section and unlock it from the right action pane.

Make sure that the App Pool is set to No Managed Code. DNX is being run as an external process. IIS doesn't need to know about what it's currently running.

Finally, create a web.config with the following content:

<configuration>
  <system.webServer>
    <handlers>
      <add name="httpplatformhandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
    </handlers>
    <httpPlatform processPath="..\approot\web.cmd" arguments="" stdoutLogEnabled="false" stdoutLogFile="..\logs\stdout.log" startupTimeLimit="3600"></httpPlatform>
  </system.webServer>
</configuration>

It should be running at that point.


Source

Maxime Rouiller
  • 13,614
  • 9
  • 57
  • 107