作者: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 文件夹中,具体取决于操作系统。 从配置文件运行站点时,可以指定要运行的站点。

可以使用以下命令:

  • 若要在默认配置文件中运行网站 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