匿名用户开启个性化设置

    默认情况,ASP.NET2.0没有开启匿名用户个性化设置,通过Web.config设置,可以实现对匿名用户的支持。
    Web.config设置

None.gif <? xml version="1.0" ?>
None.gif
< configuration  xmlns ="http://schemas.microsoft.com/.NetConfiguration/v2.0" >
None.gif  
< appSettings />
None.gif  
< connectionStrings />
None.gif  
< system .web >
None.gif    
< anonymousIdentification  enabled ="true" />
None.gif    
< profile >
None.gif      
< properties >
None.gif        
< add  name ="Name"  allowAnonymous ="true"   />
None.gif        
< add  name ="LastSubmit"  type ="System.DateTime"  allowAnonymous ="true" />
None.gif        
< group  name ="Address" >
None.gif          
< add  name ="City"   allowAnonymous ="true" />
None.gif          
< add  name ="ZipCode"   allowAnonymous ="true" />
None.gif        
</ group >
None.gif      
</ properties >
None.gif    
</ profile >
None.gif    
< compilation  debug ="true" />
None.gif    
< authentication  mode ="Windows" />
None.gif  
</ system.web >
None.gif
</ configuration >

    anonymousIdentification:针对应用程序授权配置匿名标识。这是在需要授权时,对没有经过身份验证的实体进行标识所必需的。
    allowAnonymous必须设置为"True"。

   
ContractedBlock.gif ExpandedBlockStart.gif Default.aspx.cs
None.gifusing System;
None.gif
using System.Data;
None.gif
using System.Configuration;
None.gif
using System.Web;
None.gif
using System.Web.Security;
None.gif
using System.Web.UI;
None.gif
using System.Web.UI.WebControls;
None.gif
using System.Web.UI.WebControls.WebParts;
None.gif
using System.Web.UI.HtmlControls;
None.gif
None.gif
public partial class _Default : System.Web.UI.Page
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
InBlock.gif    
protected void Page_Load(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
if (!Page.IsPostBack)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//显示用户配置信息
InBlock.gif
            DisplayProfileInfo();
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

InBlock.gif    
protected void btnSubmit_Click(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
//保存用户配置信息到Profile属性中
InBlock.gif
        Profile.Name = txtName.Text;
InBlock.gif        Profile.Address.City 
= txtCity.Text;
InBlock.gif        Profile.Address.ZipCode 
= txtPostalCode.Text;
InBlock.gif        Profile.LastSubmit 
= DateTime.Now;
InBlock.gif        
//显示用户配置信息
InBlock.gif
        DisplayProfileInfo();
ExpandedSubBlockEnd.gif    }

InBlock.gif    
private void DisplayProfileInfo()
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
//从Profile属性中获取数据并赋值给服务器控件            
InBlock.gif
        txtName.Text = Profile.Name;
InBlock.gif        txtCity.Text 
= Profile.Address.City;
InBlock.gif        txtPostalCode.Text 
= Profile.Address.ZipCode;
InBlock.gif        DateTime time 
= Profile.LastSubmit;
InBlock.gif        
//如果未获取值则显示空,否则显示获取的值
InBlock.gif
        if (time.Year == 1)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            labLastSubmit.Text 
= "";
ExpandedSubBlockEnd.gif        }

InBlock.gif        
else
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            labLastSubmit.Text 
= time.ToString();
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

    以上代码出于《asp.net2.0开发指南》。

转载于:https://www.cnblogs.com/hide0511/archive/2006/10/25/539203.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值