[翻译]  Using IIS virtual directories in Visual Studio Web Application projects

[CHINESE]  在Visual Studio Web应用程序项目中使用IIS虚拟目录

I have an ASP.NET project that has the following directories


我有一个ASP.NET项目,其中包含以下目录\ ads \ photos

both these folders have thousands of files in them that get updated frequently. I currently have my IIS set up like


I am considering turning this into


这两个文件夹中都有数以千计的文件,这些文件经常更新。我目前的IIS设置如\ inetpub \ wwwroot \ foo \ inetpub \ wwwroot \ foo \ ads \ inetpub \ wwwroot \ foo \ photos \ inetpub \ wwwroot \ foo.staging \ inetpub \ wwwroot \ foo.staging \ ads \ inetpub \ wwwroot \ foo.staging \ photos我正在考虑把它变成\ inetpub \ wwwroot \ foo \ inetpub \ wwwroot \ foo \ ads \ inetpub \ wwwroot \ foo \ photos \ inetpub \ wwwroot \ foo.staging \ inetpub \ wwwroot \ foo .staging \ ads \ inetpub \ wwwroot \ foo.staging \ photos \ inetpub \ wwwroot \ foo.resources \ ads \ inetpub \ wwwroot \ foo.resources \ photos

and turning the subdirectories in foo and foo.staging into virtual directories that point to the foo.resources subdirectories. This way while I'm testing in staging, I don't have to copy all the files in ads and photos every time I deploy and worry about things being out of sync. is this a bad idea? I'm developing in Visual Studio 2008 - Is there a way to get VS to treat my web application project subdirectories as virtual directories?

并将foo和foo.staging中的子目录转换为指向foo.resources子目录的虚拟目录。这样,当我在分段测试时,我不必在每次部署时复制广告和照片中的所有文件,并担心事情不同步。这是一个坏主意吗?我正在使用Visual Studio 2008进行开发 - 有没有办法让VS将我的Web应用程序项目子目录视为虚拟目录?

6 个解决方案



A virtual directory contained within a web application in IIS simply looks like a package in Visual Studio.

IIS中的Web应用程序中包含的虚拟目录看起来就像是Visual Studio中的包。

By opening the root app and clicking on the package, it should ask you if you want to add the child app / vdir to the solution. Then open it as a second project, you can then refer to it or consume it as needed.

通过打开root应用程序并单击该程序包,它应该询问您是否要将子app / vdir添加到解决方案中。然后将其作为第二个项目打开,然后您可以根据需要引用它或使用它。

The idea behind test and live deployments is that you should have separate data in case your testing breaks something. Essentially, by using the live data for testing, you have to be sure that you wont delete / alter something you shouldn't or you will break your live copy of the data.


Having said that, if all you plan to build is something that reads the data, this is a great idea as it will save you a lot of disc space and time on deployments.


Get it looking the way you want it in IIS first then open things up in VS.


Visual Studio treats all Virtual applications defined on the server as a sub application. If the resources are not setup in the child directories as an application in IIS it should appear as a normal folder.

Visual Studio将服务器上定义的所有虚拟应用程序视为子应用程序。如果资源未在子目录中设置为IIS中的应用程序,则它应显示为普通文件夹。

For example ...

例如 ...

If you setup 2 websites on IIS and map the physical folder to your images on both as virtual directories, you should have access to them as normal folders when you open either in Visual Studio.

如果在IIS上设置2个网站并将物理文件夹映射到两个虚拟目录上的图像,则在Visual Studio中打开时,应该可以将它们作为普通文件夹进行访问。

However if you make the virtual directories into applications in IIS and then open the website in VS it should just show a package. Clicking on that adds it as a second project in VS.


I'm not the best at explaining things but hopefully that made sense.


Hope it helps :)

希望能帮助到你 :)



I think the way to go about this is to set it up the way you want it in IIS first with your vdirs, then open the website from IIS in Visual Studio. See my answer to this question.

我认为解决这个问题的方法是首先使用vdirs在IIS中设置它,然后在Visual Studio中从IIS打开网站。看看我对这个问题的回答。



You could, use linked folders in Visual Studio = this creates a virtual link to a folder in another project (or somewhere else on disc), but doesn't physically copy them on disk.

您可以在Visual Studio中使用链接文件夹=这会创建到另一个项目(或光盘上其他位置)的文件夹的虚拟链接,但不会将它们物理复制到磁盘上。



Another option...If you're using SVN and if you're happy to have the images physically twice on disk, but still have them in sync, is to use SVN Externals

另一种选择......如果你正在使用SVN,如果你很高兴在磁盘上物理两次,但仍然让它们同步,那就是使用SVN Externals



Since these are resources, is there any particular reason you need them to be in Visual Studio at all? VS, IMO, is for managing code in a solution, not necessarily directory structure.

由于这些是资源,您是否有任何特殊原因需要它们在Visual Studio中? VS,IMO用于管理解决方案中的代码,而不一定是目录结构。

In IIS, you can set your directory structure up exactly like you have it (or even have the virtual directory point to a network drive), and Visual Studio can completely ignore it, since it's likely just a bunch of static files.

在IIS中,您可以像设置目录结构一样设置目录结构(甚至将虚拟目录指向网络驱动器),Visual Studio可以完全忽略它,因为它可能只是一堆静态文件。



I see a similar problem with my application with regarding to having loads of resources to copy up on deployment.
I'm considering building a file handler that serves up image resources to the browser. I.e. When linking to images you'd having something like /filehandler.ashx?image=/ads/101/o3904838402384.jpg then you can have just have a config setting that points to different or the same filestorage folders for both Test and Live environments.

我发现我的应用程序存在类似的问题,即需要大量资源来复制部署。我正在考虑构建一个文件处理程序,为浏览器提供图像资源。即当您链接到图像时,您会有/ filehandler.ashx?image=/ads/101/o3904838402384.jpg之类的图像,那么您可以拥有一个配置设置,指向测试和实时环境的不同或相同的filestorage文件夹。

Here is a link to the fundamentals of how it works.






© 2014-2018 ITdaan.com 粤ICP备14056181号