未知 [信息技术] VS2005SP1的新建ASP.NET WEB应用程序     阅读:11744  

VS2005SP1的新建ASP.NET WEB应用程序
作者: haiyun 编辑: 海韵 发布日期: 2007-03-07 00:00:00 点击量: 11744 来源: haiyun.net

提示:

VS2005在安装SP1补丁后可以在新建项目中新建ASP.NET WEB应用程序,此时新建的ASP.NET程序和以前用03时候的类似,可以把公共的类文件放在任意的地方而不需要放置在专门的APP_CODE目录下了,而在新建网站时建立的ASP.NET程序是必须要放在这个目录下的.

WebApplication 和 WebSiteProject 的区别

做项目中想自己写一个web的控件,看了MSDN的示例,感觉不是太难,那就做个DEMO试试看吧,不动手不知道,一动手问题就来了,照葫芦画瓢,可总是用不了,书上明明是这么写的啊,这么会错呢,GOOGLE之,大惑解矣。
 
 
我们的项目是以WebApplication模式建立的,这是MS在发布VS2005之后追加的SP1扩展包里的一种新的Web模式,而MSDN是基于最初的WebSite模式,照搬当然要出错。二者的区别在于编译模式的不同,WebApplication要快不少,原因在于:
There are a few reasons why the VS 2005 Web Application Project ends up being significantly faster than Web Site Projects in these "full rebuild" scenarios.  The main reason is that (like VS 2003), the VS 2005 Web Application Project option only compiles your page's code-behind code and other classes within your project.  It does not analyze or compile the content/controls/in-line code within your .aspx pages -- which means it does not need to parse those files.  On the downside this means that during compilation it will not check for errors in those files (unlike the VS 2005 Web Site Project option which will identify any errors there).  On the positive side it makes compilations much faster.
WebApplication编译时忽略了页面中代码的检查,不需要做分析,江这些任务交给了运行时。WebSite的优势在于可以单个页面独自编译,这对大项目而言是一个相当大的优势,二者的直观区别在于,对每一个aspx页面文件,WebApplication在有对应cs文件的同时还拥有designer.cs文件。
 
之所以MSDN的示例无法运行原因就在于编译的方式,示例中的控件代码放在App_Code文件夹下,该文件夹由.net run time在运行的时候自动编译,这在WebSite模式没问题,当项目在WebApplication模式时,由于该模式自动的也会编译一遍所有代码,所以会出现重名的问题,这在http://webproject.scottgu.com/CSharp/migration2/migration2.aspx中有详细提示:
VERY, VERY IMPORTANT: Because ASP.NET 2.0 tries to dynamically compile any classes it finds under the /App_Code directory of an application at runtime, you explictly *DO NOT* want to store classes that you compile as part of your VS 2005 Web Application Project under an "app_code" folder. If you do this, then the class will get compiled twice -- once as part of the VS 2005 Web Application Project assembly, and then again at runtime by ASP.NET. The result will most likely be a "could not load type" runtime exception -- caused because you have duplicate type names in your application. Instead, you should store your class files in any other directory of your project other than one named "app_code". This will be handled automatically by the "Convert to Web Applicaiton" command. This command will rename the folder Old_App_Code.
 
http://west-wind.com/weblog/posts/5601.aspx对两种模式有着详细的阐述。
 
关于在两种模式中控件开发的不同点,关键问题还有一个,就是aspx mark up页面中注册控件代码的方式
在WebApplication模式下,需要引用整个程序集的命名空间。
比如,aspx所在页面的namesapce为ControlTest则注册代码应该为:
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.CS.Controls"  Assembly="ControlTest"%>
其中Assembly这项在WebSite模式中是不需要的,切记切记

[ 海韵 于 2007-03-07 00:00:00  Wednesday   ]  
相关文章:

网友评论
正在加载评论...


免责申明 | 版权申明 | 联系我们 | 关于
Copyright © 2001-2024 Haiyun.Net All Rights Reserved
地址:深圳市南山区南油天安工业区1栋3楼 邮编:518000
有我可以帮您的吗?QQ:12457275  
粤ICP备05017321号-1