在IIS Express中创建虚拟目录 [英] Creating virtual directories in IIS express

查看:115
本文介绍了在IIS Express中创建虚拟目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以在IIS express中创建虚拟目录吗?我知道Cassini无法做到这一点,并且不使用完整版本的IIS就可以做到这一点.

到目前为止,我已经可以在IIS Express中本地浏览到我的应用程序,如下所示:

http://localhost:1132/

我想做的是创建一个名为"OffSiteStuff"的虚拟目录,并将其指向我的C驱动器上的某个位置,例如"c:\ offsitestuff",然后浏览到该文件夹​​中的项目,如下所示:

http://localhost:1132/OffSiteStuff/UserUploadedImage.jpg

我知道我可以使用站点内的文件夹来执行此操作,并且仍然使用IIS Express,或者就此而言,它是普通的老式Cassini,但是此文件夹将存储用户上传的图像,我真的不想拥有这些图像与应用程序文件混在一起.

另一种大方法"解决方案是,每次我要调试使用异地内容的功能时,都将站点部署到完整的Server 2008 IIS 7.5实例上,但这也有点麻烦.

<System.WebServer /> Web配置元素中有什么方法可以做到这一点?

解决方案

IIS Express配置由applicationhost.config管理.
您可以在

中找到它

Users \ <用户名> \ Documents \ IISExpress \ config文件夹.

在内部,您可以找到站点"部分,其中包含每个IIS Express配置的站点的一部分.

添加(或修改)网站部分,例如:

<site name="WebSiteWithVirtualDirectory" id="20">
   <application path="/" applicationPool="Clr4IntegratedAppPool">
     <virtualDirectory path="/" physicalPath="c:\temp\website1" />
   </application>
   <application path="/OffSiteStuff" applicationPool="Clr4IntegratedAppPool">
     <virtualDirectory path="/" physicalPath="d:\temp\SubFolderApp" />
   </application>
    <bindings>
      <binding protocol="http" bindingInformation="*:1132:localhost" />
   </bindings>
</site>

实际上,您需要在站点中为每个虚拟目录添加一个新的应用程序标签. 由于可以为虚拟目录设置不同的配置(例如,不同的.Net Framework版本),因此具有很大的灵活性.

编辑 感谢FevziApaydın提出了一种更为优雅的解决方案.

您可以通过将一个或多个virtualDirectory标签添加到Application标签来实现相同的结果:

<site name="WebSiteWithVirtualDirectory" id="20">
   <application path="/" applicationPool="Clr4IntegratedAppPool">
     <virtualDirectory path="/" physicalPath="c:\temp\website1" />
     <virtualDirectory path="/OffSiteStuff" physicalPath="d:\temp\SubFolderApp" />
   </application>
    <bindings>
      <binding protocol="http" bindingInformation="*:1132:localhost" />
   </bindings>
</site>

参考:

Is there any way to create a virtual directory in IIS express? I know that Cassini can't do this and it would be nice to be able to do this without using a full version of IIS.

I've got it so far that I can browse to my application locally in IIS express like this:

http://localhost:1132/

What I would like to do is create a virtual directory called "OffSiteStuff" and point it to some location on my C drive, like "c:\offsitestuff" and then browse to items in that folder like this:

http://localhost:1132/OffSiteStuff/UserUploadedImage.jpg

I know I could do this with a folder within my site and still use IIS Express, or, for that matter plain old Cassini, but this folder will store images uploaded by users and I really don't want to have these images mixed up with application files.

The other, "go big" solution is to deploy the site onto a full blown Server 2008 IIS 7.5 instance every time I want to debug the features that use offsite content, but that is a bit cumbersome too.

Is there any way I can do this in the <System.WebServer /> Web config element?

解决方案

IIS express configuration is managed by applicationhost.config.
You can find it in

Users\<username>\Documents\IISExpress\config folder.

Inside you can find the sites section that hold a section for each IIS Express configured site.

Add (or modify) a site section like this:

<site name="WebSiteWithVirtualDirectory" id="20">
   <application path="/" applicationPool="Clr4IntegratedAppPool">
     <virtualDirectory path="/" physicalPath="c:\temp\website1" />
   </application>
   <application path="/OffSiteStuff" applicationPool="Clr4IntegratedAppPool">
     <virtualDirectory path="/" physicalPath="d:\temp\SubFolderApp" />
   </application>
    <bindings>
      <binding protocol="http" bindingInformation="*:1132:localhost" />
   </bindings>
</site>

Practically you need to add a new application tag in your site for each virtual directory. You get a lot of flexibility because you can set different configuration for the virtual directory (for example a different .Net Framework version)

EDIT Thanks to Fevzi Apaydın to point to a more elegant solution.

You can achieve same result by adding one or more virtualDirectory tag to the Application tag:

<site name="WebSiteWithVirtualDirectory" id="20">
   <application path="/" applicationPool="Clr4IntegratedAppPool">
     <virtualDirectory path="/" physicalPath="c:\temp\website1" />
     <virtualDirectory path="/OffSiteStuff" physicalPath="d:\temp\SubFolderApp" />
   </application>
    <bindings>
      <binding protocol="http" bindingInformation="*:1132:localhost" />
   </bindings>
</site>

Reference:

这篇关于在IIS Express中创建虚拟目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆