ASP.net 2.0 学习用户配置文件(二)
默认情况下,匿名用户不能修改profile属性,问题在于ASP.NET Framewor没有办法关联Profile数据和特定的用户,除非用户是经过身份验证的。
如果希望匿名用户修改profile的属性,必须启用ASP.NET Framework的匿名认证(Anonymous Identification)的功能。当开启这个功能时,一个标识(一个GUID)被分配给匿名用户,并保存在持久化的浏览器cookie中。并且必须启用allowAnonymous标识所有希望匿名用户可以修改的profile属性。
Web配置文件示例代码:<打印机>
<authentication mode="Forms"/>
<anonymousIdentification enabled="true"/>
<profile>
<properties>
<add name="numberOfVisits" type="Int32" allowAnonymous="true"/>
</properties>
</profile>
如此一来便可以匿名访问与赋值了。
推荐链接:复印机/长宸办公
相关文档:
1.关闭不必要的Session
<%@ Page EnableSessionState="flase"%>
2.关闭不必要的ViewState
<asp:DataGrid EnableViewState="false" runat="server">
如果页面级
<%@ Page EnableViewState="false"%>
3.不要使用Exception控制程序流程
Exception是很耗资源的
4.禁用VB和JScript动态数 ......
出现错误发送Email
可以在Global.asax的void Application_Error(Object sender,EventArgs e)
{
//用到了Ssytem.Net.Mail
MailMessage mail=new MailMessage();
mail.from=new MailAddress("automated@contoso.com");
mail.Subject="SIte Error at" +DateTime.Now;
mail.Body="E ......
ASP.NET生成随机密码
在开发需要用户注册后才能使用提供的各项功能的应用程序时,在新用户提交注册信息后,较常见的做法是由程序生成随机密码,然后发送密码到用户注册时填写的电子信箱,用户再用收到的密码来激活其帐户。
实现ASP.NET生成随机密码功能是很容易的,下面的代码给出了完整的实现方法:
publicstatic ......
此处提供的代码用来实现当asp.net页面中的某个Button被点击后disable掉该页面中所有的Button,从而防止提交延时导致的多次提交。基于之前的onceclickbutton脚本.
//ASP.NET中防止页面多次提交的代码:javascript< script language="javascript"> < !-- function disableOtherSubmit() {
var obj = event.s ......
假定有一个Product表,字段有(Id,Name,Quantity,...)将Quantity列用textbox格式来显示:
首先在Gridview中,Quantity列以TemplateField显示,其他的列属性设为只读,把显示格式设为TextBox
<asp:TemplateField HeaderText="Quantity">
<ItemTemplate>
&nbs ......