ASP如何限制登录。。。。

zhuxiao17 2009-04-20 04:34:52
要求使用Application和Session对象统计登录人数
要求在Web.config中配置允许Admin和PowerUser角色,拒绝Customers角色和其他匿名用户访问

我如何写呢??高手写下~
...全文
161 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
gzw13999 2009-04-20
  • 打赏
  • 举报
回复
ASP???? IF 判断了.``
newty_won 2009-04-20
  • 打赏
  • 举报
回复
 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();
}
newty_won 2009-04-20
  • 打赏
  • 举报
回复
    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);
}
}
newty_won 2009-04-20
  • 打赏
  • 举报
回复
用cookie

62,267

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧