从命令行运行 IIS Express

作者:Vaidy Gopalakrishnan

概述

IIS Express 是一个简单、独立版本的 IIS,已针对开发人员进行了优化。 本演练介绍如何使用 IIS Express 命令行运行站点。

先决条件

为了完成此演练中的过程,你必须已经安装以下服务:

  • Windows XP 或更高版本
  • IIS Express

若要了解如何下载和安装 IIS Express,请参阅 IIS Express 概述

从命令行使用 IIS Express 运行站点

  1. 打开命令提示符。

    无需管理员用户权限即可运行本演练中的命令。 但是,如果要在 1024 或更小编号的端口上运行 IIS Express,必须具有管理员用户权限。

  2. 运行以下命令,导航到 IIS Express 安装文件夹:

    cd \Program Files\IIS Express
    

    或者,如果使用 64 位 OS,请运行以下命令:

    cd \Program Files (x86)\IIS Express
    
  3. 运行以下命令,查看 IIS Express 使用情况字符串:

    iisexpress /?
    
    IIS Express Usage:
    ------------------
    iisexpress [/config:config-file] [/site:site-name] [/siteid:site-id] [/systray:boolean] 
    iisexpress /path:app-path [/port:port-number] [/clr:clr-version] [/systray:boolean] 
    
    /config:config-file 
    The full path to the applicationhost.config file. The default value is the IISExpress8\config\applicationhost.config file that is located in the user's Documents folder.
    
    /site:site-name 
    The name of the site to launch, as described in the applicationhost.config file. 
    
    /siteid:site-id 
    The ID of the site to launch, as described in the applicationhost.config file.
    
    /path:app-path 
    The full physical path of the application to run. You cannot combine this option with the /config and related options. 
    
    /port:port-number 
    The port to which the application will bind. The default value is 8080. You must also specify the /path option. 
    
    /clr:clr-version The .NET Framework version (e.g. v2.0) to use to run the application. The default value is v4.0. You must also specify the /path option. 
    
    /systray:boolean 
    Enables or disables the system tray application. The default value is true. 
    
    /trace:debug-trace-level 
    Valid values are info or i,warning or w,error or e. 
    
    Examples: 
    iisexpress /site:WebSite1 
    This command runs WebSite1 site from the user profile configuration file.
    
    iisexpress /config:c:\myconfig\applicationhost.config 
    This command runs the first site in the specified configuration file. 
    
    iisexpress /path:c:\myapp\ /port:80 
    This command runs the site from c:\myapp folder over port 80.
    
  4. 使用以下方法之一运行站点:

  5. 站点运行后,可以使用 IIS Express 系统托盘来管理该站点。 有关详细信息,请参阅使用 Windows 系统托盘管理网站和应用程序。 或者,可通过运行以下选项来禁用系统托盘:

    /systray:false
    

从配置文件运行站点

IIS Express 和 IIS 使用 ApplicationHost.config 文件,该文件指定了站点、应用程序池、处理程序等的全局设置。IIS Express 使用默认的特定于用户的 ApplicationHost.config 文件,允许许多用户共享同一台计算机,而不会干扰其他用户的设置。 此文件位于 %userprofile%\Documents\IISExpress\config 文件夹或 %userprofile%\My Documents\IISExpress\config 文件夹中,具体取决于 OS。 从配置文件运行站点时,可以指定要运行的站点。

可以使用以下命令:

  • 若要在默认配置文件中运行 Website1 网站,请运行:

    iisexpress /site:WebSite1
    
  • 若要在默认配置文件中运行第一个网站,请运行:

    iisexpress
    
  • 若要在自定义配置文件中运行第一个网站,请运行:

    iisexpress /config:c:\myconfig\applicationhost.config
    
  • 若要从自定义配置文件运行名为 MyBlog 的站点,请运行:

    iisexpress /config:c:\myconfig\applicationhost.config /site:MyBlog
    

注意:/config 选项指定配置文件的完整路径。 如果要使用默认配置文件,可以省略此选项。 /site 选项指定配置文件中的特定站点。 如果要在配置文件中运行第一个站点,可以省略此选项。

从应用程序文件夹运行站点

还可以使用 /path 选项直接从文件夹运行站点。 此选项适用于任何类型的应用程序,包括静态 HTML、ASP.NET、PHP 和 WCF。 默认情况下,IIS Express 将在 http://localhost:8080/ 上运行站点。 对于托管网站(例如 ASP.NET),IIS Express 将使用 .NET 4.0。 可以使用 /port 和 /clr 选项来替代这些默认值。

例如,以下命令使用 .NET 2.0 在 http://localhost:9090/ 上运行指定的应用程序“myapp”:

iisexpress /path:c:\myapp\ /port:9090 /clr:v2.0