How do I install an ASP.Net MVC application on IIS

2019-03-11 02:35发布

For IIS6 I can use the IIS helpers in Wix to install a web application like this:

<iis:WebAppPool 
    Id="AP_MyApp" 
    Name="My Application Pool" 
    Identity="networkService" />
<iis:WebApplication 
    Id="WA_MyApp" 
    Name="MyApp" 
    WebAppPool="AP_MyApp">
    <iis:WebApplicationExtension
        CheckPath="no"
        Executable="[NETFRAMEWORK20INSTALLROOTDIR]aspnet_isapi.dll"
        Verbs="GET,HEAD,POST"/>
</iis:WebApplication>

Unfortunately, this doesn't work for IIS7. We don't want to use the aspnet_isapi.dll mechanism, and instead want the integrated pipeline to handle the request routing. The app pool created by this script is in Classic mode not Integrated mode so none of the handlers get run correctly.

How can I correctly install an MVC app on IIS 7?

3条回答
做个烂人
2楼-- · 2019-03-11 03:18

Thanks to @matthewthurlow, I was able to use the XML utils to achieve what I needed to do:

<util:XmlFile 
    Id="ModifyAppPoolPipelineType"
    Action="setValue"
    ElementPath="//configuration/system.applicationHost/applicationPools/add[\[]@name='My Application Pool'[\]]/@managedPipelineMode"
    File="[WindowsFolder]System32\inetsrv\config\applicationHost.config"
    Value="Integrated"/>

The rest of the actions do seem to work fine with IIS 7.

查看更多
混吃等死
3楼-- · 2019-03-11 03:22

The IIS extensions for WIX don't support IIS7. The IIS team keep rewriting the metabase between versions. There are quite a few things that don't work, the lack of an integrated app pool amongst them.

Until the extensions get rewritten, you're left with three options:

  • Use build in custom actions to invoke appcmd.exe
  • Use XmlConfig to update applicationHost.config
  • Write your own custom actions

I've opted for the xmlconfig option at the moment as you can do this within a component and tie it to a feature.

查看更多
不美不萌又怎样
4楼-- · 2019-03-11 03:31

I personally recommend using AppCmd.exe (matthewthurlow's first bullet) because you don't have to count on the legacy management components being installed, or risk modifying the configuration XML manually.

If you are not comfortable with AppCmd, Mike Volodarsky has a great article on Getting Started with AppCmd.exe, and the Microsoft IIS Configuration Reference is excellent, offering UI, Code and AppCmd examples for modifying each of the configuration items (e.g. Application Pools ). The IIS7 Administration Pack also includes a Configuration Editor that allows you to generate AppCmd scripts from any existing configuration.

To integrate AppCmd into WiX, you need to create and schedule two custom actions for each command. There is general information in the WiX v3 manual documenting this procedure, and I've included a concrete example below.

First, you need to set up an immediate action to store the command line in a property:

<CustomAction 
  Id="CreateAppPool_Cmd" 
  Property="CreateAppPool" 
  Execute="immediate" 
  Value="&quot;[WindowsFolder]system32\inetsrv\APPCMD.EXE&quot; add apppool /name:&quot;[APP_POOL_NAME]&quot;" /> 

Next you set up a deferred action which references this property:

<CustomAction 
  Id="CreateAppPool" 
  BinaryKey="WixCA" 
  DllEntry="CAQuietExec" 
  Execute="deferred" 
  Return="ignore" 
  Impersonate="no"/> 

And finally, you need to schedule these. The immediate action that sets the properties seem to work well after InstallFinalize, and the deferred action works after InstallFiles. I haven't got as far as figuring out rollback actions yet.

MapGuide Open Source does this method extensively; you can see the CA scheduling in our MapGuide.wxs file, and the CA definition in our IIS7.wxs file.

查看更多
登录 后发表回答