VS 2005 Web Application Project 项目中Profile的使用方法(更新)

在VS2005 Web Site Projects项目中, 如果在Web.config文件中定义了Profile节,那么ASP.Net会自动为项目中的每个页面增加一个Profile的对象类型,这个对象类型完成了对定义在Web.config文件Profile节定义的所有属性进行强类型映射。开发员能够通过智能感知获得访问者的Profile信息,例如:
在编写程序的时候,开发人员可以这样写:
这种支持是使用VS2005 Web Site Project选项,动态建立和增加一个ProfileCommon类对象Profile到每一个Code-behind实例。
 
现在VS2005 Web Application Project 1.0英文版是不支持动态建立Profile对象,如果使用的项目是Web Applicaiton Project则不能发现Profile对象
解决的方法有两种
********************************************************************************
 一、自己Coding ProfileCommon类
    public class ProfileCommon : System.Web.Profile.ProfileBase
    {
        [SettingsAllowAnonymous(true)]
        public string TestString
        {
            get  { return base["TestString"] as string; }
            set  { base["TestString"] = value; }
        }
    }
在Web.config文件中要这样定义
< profile  defaultProvider ="SqlServers"  enabled ="true"  inherits ="ProfileCommon"   />
Code-Behind中
ProfileCommon profile = (ProfileCommon)HttpContext.Current.Profile;
profile.TestString ="Test";
********************************************************************************
********************************************************************************
二、使用第三方的Add-in  : ASP.Net WebProfile Generator 
什么是Asp.Net WebProfile Generator?
The Web Profile Generator is an add-in for Visual Studio 2005 that generates a strongly typed class for accessing the ASP.NET profile in Web Application
Projects. Because Web Application Projects compile the code behind files in advance of ASP.NET they do not have access to dynamically generated types like the Profile object.  
其实这个就是解决不能支持动态建立Profile对象的Add-in。
在使用时:
              1.安装 Asp.net WebProfile Generator Add-in.
              2.在工程中建议web.config并进行配置
< profile >< properties >
              3.右击web.config文件有一个option:Generator WebProfile ,生成WebProfile.cs
              4. Profile.MyProperty就可以调用在web.Config中配置中配置项。 * MyProperty指配置项目的Name
*如果了解Profile的其他特性以下有两个的Link:
    http://quickstarts.asp.net/QuickStartv20/aspnet/doc/profile/default.aspx
    http://msdn2.microsoft.com/en-us/library/ms379605(VS.80).aspx
    http://www.gotdotnet.com/Workspaces/Workspace.aspx?id=406eefba-2dd9-4d80-a48c-b4f135df4127 

 
ASP.Net WebProfile Generator 
Tim McBride has published a cool sample that will generate a WebProfile class for accessing the ASP.NET profile object from within the code behind files of a Web Application Project.

http://www.gotdotnet.com/Workspaces/Workspace.aspx?id=406eefba-2dd9-4d80-a48c-b4f135df4127

Because Web Application Projects compile the code behind files in advance of ASP.NET they do not have access to dynamically generated types like the Profile object.  This sample provided an add-in into VS that will generate a WebProfile proxy class that will fetch profile information from the real ASP.NET profile object at runtime.

Hope it helps,
Brad.


相关文章: VS 2005 Web Application Project 项目中Profile的使用方法[程序文档]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值