Petshop3.0
是微软
.net框架实例中比较著名的一个,它主要是向大家展示
.net平台在开发企业级应用程序的潜力及性能,附带着和
java版的
Petshop对比对比,作为
.net平台的经典的例子,不能不学,看看它的源代码、分析一下,比看书强
……
对于petshop的分析网上很早都有高手分析,也有一大堆的文章,高手不必看我写的东东,我只是在我学习的时候总结一下而已。
web.config配置文件是asp.net编程的关键所在,有了这个配置文件,我们几乎可以设置应用程序的所有功能,我们下面就来看看Petshop3.0的配置文件:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<!-- for information on setting the values for the connection strings see the configTool project -->
<add key="SQLConnString1" value="AQAAANCMnd8BFdERjHoAwE/Cl+sBAAAAbJmtxpOFZU2YjybuEjz+xQQAAAACAAAAAAADZgAAqAAAABAAAAD9vUnhT5iWzJSIWGx9sUoIAAAAAASAAACgAAAAEAAAACfL59nwhuC/ABFNOUVS2tRIAAAAtQfoW3y+WlFrK9MBc1HjbhkIH2Yt4vQv7CTCob2xkLsRSA8hI90pDGZd+kDLzldQ/AMJ0DGrvFf/I1fFxxiVir0yKb1KNHLVFAAAAC6KzriblPRM/iMqw/8+G8hnIU7s" />
<add key="SQLConnString2" value="AQAAANCMnd8BFdERjHoAwE/Cl+sBAAAAbJmtxpOFZU2YjybuEjz+xQQAAAACAAAAAAADZgAAqAAAABAAAAAxObyAdxn9WuE0sA 1f3B3gAAAAAASAAACgAAAAEAAAAPlv8Kk+7ftwoTCLb/WnOW9IAAAASB0DjNJRWJteiFe4oxb4HBDpo7T6lbzExEXrBmLQAQ5JCgt4bWTu6r3qSlx9k4XbsF4d3YEmXlcHw9srOLqAlHxe6R9kQn2cFAAAADgkn+eg8Z6iFbKOgTTaY5o2d0hN" />
<add key="SQLConnString3" value="AQAAANCMnd8BFdERjHoAwE/Cl+sBAAAAbJmtxpOFZU2YjybuEjz+xQQAAAACAAAAAAADZgAAqAAAABAAAABJ6O95MIIFNpkb3AJ1pKBYAAAAAASAAACgAAAAEAAAAFz6DD5dwwN8h3yL+eOdg/RQ_AAA0AriHmf0GykPtkrBES6nEN3+SR8/6KiO5s06rgnfaG7vr62FIayefc0AskT3p1ZQio/17gxx835S7bU6nOLfF3G2FZiTNczIZ3B0cMwEBR0UAAAAhCz5ohhCny8e3e8J+SVfS7wK9D0=" />
<add key="OraConnString1" value="" />
<add key="OraConnString2" value="" />
<add key="OraConnString3" value="" />
<add key="WebDAL" value="PetShop.SQLServerDAL" />
<add key="OrdersDAL" value="PetShop.SQLServerDAL" />
<add key="Event Log Source" value=".NET Pet Shop" />
</appSettings>
--------------------------------------------------------------------------------------------
“</appSettings>”节是一级数据节,可以放置用户定义的和应用程序专用的数据,我们看到在Petshop3.0中,它定义了几个sql、Oracle数据库的连接字符串,因为在安装的时候,我用的是sql数据库,所以Oracle数据库的连接字符串的第二个键值都为空,这样可以使应用程序进行以后的扩展使用,下面的几个键值对都是要在编程中使用的数据。把这些专有的数据键值对写入到.config文件中,确实给编程带来了巨大的好处,我们使用时只要引入System.Configuration命名空间,用ConfigurationSettings.AppSettings["SQLConnString1"]调用就行了
----------------------------------------------------------------------------------------------------------------------
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<qualifyAssembly partialName="PetShop.SQLServerDAL" fullName="PetShop.SQLServerDAL,version=3.2.1.0,publicKeyToken=a7987b61c51ca872,culture=neutral" />
</assemblyBinding>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<qualifyAssembly partialName="PetShop.OracleDAL" fullName="PetShop.OracleDAL,version=3.2.1.0,publicKeyToken=a7987b61c51ca872,culture=neutral" />
</assemblyBinding>
</runtime>
-----------------------------------------------------------------
在运行时中注册PetShop.SQLServerDAL和PetShop.OracleDAL程序集
----------------------------------------------------------------
<system.web>
<authentication mode="Forms">
<forms name="PetShopAuth" loginUrl="SignIn.aspx" protection="None" timeout="60" />
上面的这一节主要是定义了asp.net的身份验证模式为form模式,微软也提供了一个formauthenticaition的一个类,实现验证方面的任务很方便
-----------------------------------------------------------------
<compilation defaultLanguage="c#" debug="false" />
-----------------------------------------------------
编译为c#语言,编译时不进行调试