ASP.NET :Virtual Application vs Virtual Directory
原文地址:http://blogs.msdn.com/b/wenlong/archive/2006/11/22/virtual-application-vs-virtual-directory.aspx。
People are always confused by these two IIS concepts, especially for the new IIS7/WAS. These are not new concepts. They are available since IIS6 on Windows 2003 Server. However the terms were misused in IIS6 and they are corrected in IIS7 in Windows Vista and higher versions of Windows.
Virtual Application
What is it?
The term “virtual application” is a fundamental concept for IIS and ASP.NET. Here is the definition in my own words: a virtual application is a construction unit of a web site that participates protocol listening and process management. It can be uniquely identified by its absolute virtual path from that web site. For example, you can create a virtual application with virtual path “/foo” in the “Default Web Site”. For simplicity, we also call virtual application as "Default Web Site/foo" or simply “/foo”. Every web site has at least one virtual application, a.k.a, the root virtual application “/”.
A web site can be uniquely identified by its site ID. All of the web sites are under the same root “/W3SVC”. So each web site can be represented in the format of “/W3SVC/<SiteID>”. For example, the “Default Web Site” can be represented as “/W3SVC/1”. With this, we can uniquely identify a virtual application with its full path, for example,
/W3SVC/1/Root/foo
If you have the IIS6 scripting tool “adsutil.vbs” installed, you would be able to check the settings of the virtual application with the following command:
cscript %systemdrive%\inetpub\adminscripts\adsutil.vbs enum /W3SVC/1/Root/foo
Protocol Listening
When you create a virtual application, you would expect your new virtual application to receive requests that are dedicated to it. There are two aspects of “protocol listening”:
- For a particular protocol (for example HTTP), a web site is nothing but a list of virtual applications. This means that the protocol activation service (which is IIS or W3SVC in the HTTP case) registers a list of Urls in the protocol listener service (which is HTTP.sys driver for HTTP). Each of this Url is associated with a virtual application.
- You can specify which protocol is enabled for a virtual application. In IIS6, you can specify HTTP or HTTPS. In IIS7, however, you can specify any protocol(s) through the “enabledProtocols” property of the virtual application. For example, you can specify protocols “net.tcp”, “net.pipe”, “net.msmq”, or “msmq.formatname” that are implemented by WCF.
Application Pool
The other aspect of a virtual application is that it also participates in process management. IIS/WAS has the concept of application pools. An application pool is a definition or template of a worker process (w3wp.exe) that is used by IIS/WAS to create new worker process instances. Two most important properties of an application pool are:
- It has an identity which is the running account of the worker process in this pool. You can configure the identity to a specific account so that you can achieve security isolation from other pools.
- It has a list of settings to control the health of worker processes running in this pool. For example, you can set process recycling and idle timeout, enable debugging, configure Web Gardens, or enable Rapid-Fail Protection (RFP), etc. For IIS6, more information can be found athttp://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/c9b5db6f-874e-4ec9-93ed-1733367c117b.mspx?mfr=true.
Each virtual application must be assigned to an application pool in IIS. All of the requests (except for static content) will be handled in worker processes in that application pool.
Please note that Application Pool is managed by WAS instead of IIS in the IIS7 family. This separation makes non-HTTP activation possible. With this refactoring, “IIS” is simply the web server that only handles HTTP/HTTPS requests.
ASP.NET Application
For ASP.NET, a virtual application has its real meaning as an “application”. When an ASP.NET request is first received in a virtual application, a new AppDomain is created in the worker process that handles subsequent ASP.NET requests. This includes all WCF requests. So in the ASP.NET world, a virtual application is mapped to an AppDomain. This provides important code isolation for managed applications that sits in the same worker process. It is even more important for web hosting when the applications are running in the partial trust environment.
Virtual Directory
Isn’t “virtual directory” the same as “virtual application”? In IIS6, from the IIS Manager (UI), if you right click on “Default Web Site” -> New, you will see “Virtual Directory …” from the list. What is going on there? Well, as I said, the terms are misused in IIS6. When it says “Virtual Directory”, it actually means “Virtual Application”.
Am I kidding? No. A real “virtual directory” is just a container of files. It is a construction unit of a virtual application, just like a virtual application to a web site. A virtual application must have at least one virtual directory. Here is a sample configuration section that defines the virtual application “/foo” and its virtual directories in the WAS' configuration file %windir%\system32\inetsrv\config\applicationhost.config:
<sites>
<site name="Default Web Site" id="1">
<application path="/foo" enabledProtocols="http">
<virtualDirectory path="/" physicalPath="c:\inetpub\foo" />
<virtualDirectory path="/bar" physicalPath="\\myremote1\bar" />
</application>
...
</site>
</sites>
Note that the virtual directory “/bar” points to a different physical path, actually it points to a network share (UNC) path!
How can we create a real virtual directory in IIS6 then? It is a little bit trickier from the UI. In the IIS Manager UI, you can right click on the virtual application and then click on New -> “Virtual Directory …”. After specifying the alias and path, you will get the virtual directory using all default settings.
However, there is another trick to convert a virtual application into a virtual directory. Here are the steps:
- Create a virtual application “/foo” and a sub virtual application “/foo/bar”.
- Right click on the virtual application “/foo/bar” and select properties. You will see the properties dialog popped up.
- Under the “Virtual Directory” tab, look for the “Remove” button. See the image below:
- Click the “Remove” button and click on “OK” button.
Now you have created a virtual directory “/bar” under the virtual application “/foo”. The icon for the virtual application is different than that of the virtual application. Here is what you will see:
Nesting
Virtual applications and virtual directories can be nested, meaning, a virtual application or directory can be created under another virtual application or directory in any combinations.
This nesting has the following implications:
- The virtual path of the parent application/directory is the prefix of the child application/directory.
- For ASP.NET, the web.config of the parent virtual application/directory affects the child application/directory.
- For ASP.NET, the assemblies referenced by the parent virtual application are inherited by the children.
Other than those, virtual applications still have their own isolation that I mentioned in the above sections.
ASP.NET :Virtual Application vs Virtual Directory的更多相关文章
- ASP.NET整理:Cookie,Application,Session,页面生命周期
一.设置Cookie的2种方式 1. Repsonse.Cookie[“名”] = 值; 2. HttpCookie hcCookie = new HttpCookie(“名”,值); h ...
- 转载ASP.NET 状态管理Application,Session,Cookie和ViewState用法
转载原地址 http://www.cnblogs.com/cuishao1985/archive/2009/09/24/1573403.html ASP.NET状态管理 APPlication,Ses ...
- ASP.NET 应用程序(Application)生命周期概述
原文:ASP.NET 应用程序(Application)生命周期概述 引用MSDN:ASP.NET 应用程序生命周期概述 本 主题概述应用程序生命周期,列出重要的生命周期事件,并描述如何编写适合应用程 ...
- 总结ASP.NET MVC Web Application中将数据显示到View中的几种方式
当我们用ASP.NET MVC开发Web应用程序的时候,我们都是将需要呈现的数据通过"Controllers"传输到"View"当中,怎么去实现,下面我介绍一下 ...
- ASP.NET MVC 3 Application Upgrader
ASP.NET MVC 3 Application Upgrader: http://aspnet.codeplex.com/releases/view/59008
- c++ virtual 和 pure virtual的区别
参考资料: http://stackoverflow.com/questions/1306778/c-virtual-pure-virtual-explained 验证代码: #include < ...
- [转]ASP.NET MVC 3 Application Upgrader
本文转自:http://aspnet.codeplex.com/releases/view/59008 Recommended Download ASP.NET MVC 3 Applicat ...
- warning:This application is modifying the autolayout engine from a background thread
警告提示:This application is modifying the autolayout engine from a background thread, which can lead to ...
- ASP.Net:Javascript 通过PageMethods 调用后端WebMethod方法 + 多线程数据处理 示例
ASP.Net:Javascript 通过PageMethods 调用后端WebMethod方法 + 多线程数据处理 示例 2012年04月27日 16:59:16 奋斗的小壁虎 阅读数:4500 ...
随机推荐
- 关于overflow: hidden;的一个诡异问题
<!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8&quo ...
- python基础类型 —— Sets集合
集合(set)是一个无序不重复元素的序列. 基本功能是进行成员关系测试和删除重复元素. 运行结果如下: sets其他操作: myset.add('x') # 添加一项 myset.update([10 ...
- 全键盘操作Windows
计算机机用户在使用计算机的时候,是用键盘多一点?还是用鼠标多一点?如果是专业打字员,应该会说他使用键盘多一点,除此之外,多数人都会告诉你,他已经离不开鼠标了,没有鼠标,就不会操作电脑. 如果某一天 ...
- Fiddler 常用功能总结
1.fiddler相关配置 2.如何抓包 移动端 ①保持手机和电脑处于同一网络中 ②设置手机的代理为电脑当前所处网络的IP,端口号为:8888,eg:10.12.1.64:8888. ③ 启动ap ...
- doc文档生成带目录的pdf文件方法
准备软件: 福昕PDF阅读器 下载地址:http://rj.baidu.com/soft/detail/12882.html?ald 安装福昕PDF阅读器,会自动安装pdf打印机. 准备好设置好各级标 ...
- Storm常用操作命令及WordCount
Storm常用操作命令 1.任务提交命令:storm jar [jar路径] [拓扑包名.拓扑类名] [拓扑名称] storm jar /export/servers/storm/examples/s ...
- COJ1013 WZJ的数据结构(十三)
WZJ的数据结构(十三) 难度级别:D: 运行时间限制:1000ms: 运行空间限制:262144KB: 代码长度限制:2000000B 试题描述 给你一棵N个节点的有根树(根节点为1),每个节点有权 ...
- Vakuum开发笔记01 开天辟地
1.缘起 先驱--COGS 早在2008年,我自学PHP后开发了COGS,并成功用于学校内部的OJ,ruvtex.也曾经对外开放过,但是由于学校网络不稳定,后来一直连不上了.我还把COGS推荐给了OO ...
- 【转载】VC GDI 像素转厘米(英寸)
[转载]http://blog.sina.com.cn/s/blog_638dd78201018663.html 函数原型:int GetDeviceCaps(int nIndex); 常用的参数有( ...
- Codeforces Round #368 (Div. 2) A. Brain's Photos 水题
A. Brain's Photos 题目连接: http://www.codeforces.com/contest/707/problem/A Description Small, but very ...