ASP如何限制登录。。。。 要求使用Application和Session对象统计登录人数要求在Web.config中配置允许Admin和PowerUser角色,拒绝Customers角色和其他匿名用户访问我如何写呢??高手写下~ 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 protected void Button1_Click(object sender, EventArgs e) { string name = this.txtName.Text.Trim(); string pwd = this.txtPwd.Text.Trim(); //if (name == "admin" && pwd == "123" || name == "fubing" && pwd == "123") //{ // //验证通过,立即产生一个身份认证票据(该票据的主要内容就是一个身份认证Cookie) // //然后跳转到刚请求的页面 // FormsAuthentication.RedirectFromLoginPage(name,false); //} //验证配置文件中的用户名和密码 if (FormsAuthentication.Authenticate(name, pwd) == true) { FormsAuthentication.RedirectFromLoginPage(name, false); } } protected void Page_Load(object sender, EventArgs e) { /*HttpContext.Current.User代表当前用户的信息(包括匿名用户) * HttpContext.Current.User.Identity.AuthenticationType返回该用户的登陆方式 * HttpContext.Current.User.Identity.IsAuthenticated返回当前用户是否经过验证 * HttpContext.Current.User.Identity.Name返回经过认证的用户的用户名 */ this.lblUserName.Text = HttpContext.Current.User.Identity.Name; } protected void Button1_Click(object sender, EventArgs e) { string mima = this.TextBox1.Text; //FormsAuthentication.HashPasswordForStoringInConfigFile的作用是用指定的加密算法加密字符串,返回加密后得到的字符串 string aftermima = FormsAuthentication.HashPasswordForStoringInConfigFile(mima, "sha1"); Response.Write(aftermima); } protected void LinkButton1_Click(object sender, EventArgs e) { //FormsAuthentication.SignOut()方法会删除身份认证Cookie(它的作用相当于Session.Abandon()),一般用来注销当前登录用户 FormsAuthentication.SignOut(); //FormsAuthentication.RedirectToLoginPage()的作用是跳转到登陆页面去 FormsAuthentication.RedirectToLoginPage(); } 图片刷新问题 如何试用Lodop打印控件 时间字段的问题 关于乱码问题,麻烦高手帮助 请问在asp.net中如何控制网页中的对象(例如:asp.net中的一个按钮点击后停止网页Flash的播放)?谢谢。 关于利用XML实现通用WEB报表打印的问题,急! 如果想做一个在网上卖东西的电子商务网站,用ASP.NET做怎么样?有没有其他更合适的工具 给分了 大家来帮忙 窗体程序调用dll,出错。 用VS2010做的网上投票系统更新用户信息室出现错误,求大神帮忙!!! 统计登录问题 为什么win2003 iis6,isapi筛选器里asp.net的优先级:未知??
{
string name = this.txtName.Text.Trim();
string pwd = this.txtPwd.Text.Trim();
//if (name == "admin" && pwd == "123" || name == "fubing" && pwd == "123")
//{
// //验证通过,立即产生一个身份认证票据(该票据的主要内容就是一个身份认证Cookie)
// //然后跳转到刚请求的页面
// FormsAuthentication.RedirectFromLoginPage(name,false);
//} //验证配置文件中的用户名和密码
if (FormsAuthentication.Authenticate(name, pwd) == true)
{
FormsAuthentication.RedirectFromLoginPage(name, false);
}
}
{
/*HttpContext.Current.User代表当前用户的信息(包括匿名用户)
* HttpContext.Current.User.Identity.AuthenticationType返回该用户的登陆方式
* HttpContext.Current.User.Identity.IsAuthenticated返回当前用户是否经过验证
* HttpContext.Current.User.Identity.Name返回经过认证的用户的用户名
*/
this.lblUserName.Text = HttpContext.Current.User.Identity.Name;
}
protected void Button1_Click(object sender, EventArgs e)
{
string mima = this.TextBox1.Text;
//FormsAuthentication.HashPasswordForStoringInConfigFile的作用是用指定的加密算法加密字符串,返回加密后得到的字符串
string aftermima = FormsAuthentication.HashPasswordForStoringInConfigFile(mima, "sha1");
Response.Write(aftermima);
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
//FormsAuthentication.SignOut()方法会删除身份认证Cookie(它的作用相当于Session.Abandon()),一般用来注销当前登录用户
FormsAuthentication.SignOut();
//FormsAuthentication.RedirectToLoginPage()的作用是跳转到登陆页面去
FormsAuthentication.RedirectToLoginPage();
}