我使用ASP.NET的Form验证
<anonymousIdentification enabled="true"/>
<authentication mode="Forms" >
<forms name="yourAuthCookie" loginUrl="/Profile/SignIn.aspx" protection="All" path="/Profile" />
</authentication>
<authorization>
<deny users="?"/>
</authorization>//Profile设置
<profile automaticSaveEnabled="false">
<providers>
<add name="MyProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ConnectionString"/>
</providers>
<properties>
<add name="FirstName" allowAnonymous="true"/>
</properties>
</profile>登陆没有使用Membership,而是自定义的
protected void SignIn_Click(object sender, EventArgs e) {
if(txtUserName.Text.Trim() == "myname" && txtPWD.Text.Trim() == "mypwd"){
addCookie();
Response.Redirect("default.aspx");
}
} private void addCookie() {
FormsAuthenticationTicket t = new FormsAuthenticationTicket("test", false, 30);
string s = FormsAuthentication.Encrypt(t);
HttpCookie hc = new HttpCookie(FormsAuthentication.FormsCookieName, s);
Response.Cookies.Add(hc);
}Global.asax中添加了匿名迁移函数
void Profile_MigrateAnonymous(Object sender, ProfileMigrateEventArgs e) {
//这只是测试数据,为的是匿名迁移时,我们知道它触发了
string testStr = Convert.ToString(Application["test"]);
Application["test"] = testStr + "1";
testStr = Convert.ToString(Application["test"]);
HttpContext.Current.Response.Write(testStr +"<br/>");
}
刚点击登陆按钮时会执行Global.asax中的Profile_MigrateAnonymous函数,即在default.aspx中输出1,但是随后的每一次操作都会执行Profile_MigrateAnonymous函数(可以看出输出的字符串在增加),包括每一个新打开的页面,在页面上的刷新操作都会执行Profile_MigrateAnonymous函数,
不明白为什么登陆后每次都执行Profile_MigrateAnonymous函数?该怎样解决这个问题?谢谢!
<anonymousIdentification enabled="true"/>
<authentication mode="Forms" >
<forms name="yourAuthCookie" loginUrl="/Profile/SignIn.aspx" protection="All" path="/Profile" />
</authentication>
<authorization>
<deny users="?"/>
</authorization>//Profile设置
<profile automaticSaveEnabled="false">
<providers>
<add name="MyProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ConnectionString"/>
</providers>
<properties>
<add name="FirstName" allowAnonymous="true"/>
</properties>
</profile>登陆没有使用Membership,而是自定义的
protected void SignIn_Click(object sender, EventArgs e) {
if(txtUserName.Text.Trim() == "myname" && txtPWD.Text.Trim() == "mypwd"){
addCookie();
Response.Redirect("default.aspx");
}
} private void addCookie() {
FormsAuthenticationTicket t = new FormsAuthenticationTicket("test", false, 30);
string s = FormsAuthentication.Encrypt(t);
HttpCookie hc = new HttpCookie(FormsAuthentication.FormsCookieName, s);
Response.Cookies.Add(hc);
}Global.asax中添加了匿名迁移函数
void Profile_MigrateAnonymous(Object sender, ProfileMigrateEventArgs e) {
//这只是测试数据,为的是匿名迁移时,我们知道它触发了
string testStr = Convert.ToString(Application["test"]);
Application["test"] = testStr + "1";
testStr = Convert.ToString(Application["test"]);
HttpContext.Current.Response.Write(testStr +"<br/>");
}
刚点击登陆按钮时会执行Global.asax中的Profile_MigrateAnonymous函数,即在default.aspx中输出1,但是随后的每一次操作都会执行Profile_MigrateAnonymous函数(可以看出输出的字符串在增加),包括每一个新打开的页面,在页面上的刷新操作都会执行Profile_MigrateAnonymous函数,
不明白为什么登陆后每次都执行Profile_MigrateAnonymous函数?该怎样解决这个问题?谢谢!
好建议