惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

H
Help Net Security
博客园 - Franky
GbyAI
GbyAI
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
爱范儿
爱范儿
IT之家
IT之家
酷 壳 – CoolShell
酷 壳 – CoolShell
aimingoo的专栏
aimingoo的专栏
博客园_首页
MongoDB | Blog
MongoDB | Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Recent Announcements
Recent Announcements
Scott Helme
Scott Helme
有赞技术团队
有赞技术团队
M
MIT News - Artificial intelligence
C
CERT Recently Published Vulnerability Notes
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Jina AI
Jina AI
F
Fortinet All Blogs
N
Netflix TechBlog - Medium
L
LangChain Blog
L
LINUX DO - 最新话题
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
H
Hacker News: Front Page
MyScale Blog
MyScale Blog
P
Palo Alto Networks Blog
G
Google Developers Blog
Google DeepMind News
Google DeepMind News
AI
AI
T
Troy Hunt's Blog
Microsoft Azure Blog
Microsoft Azure Blog
阮一峰的网络日志
阮一峰的网络日志
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Vercel News
Vercel News
Microsoft Security Blog
Microsoft Security Blog
罗磊的独立博客
S
Secure Thoughts
大猫的无限游戏
大猫的无限游戏
博客园 - 叶小钗
人人都是产品经理
人人都是产品经理
Blog — PlanetScale
Blog — PlanetScale
博客园 - 司徒正美
Apple Machine Learning Research
Apple Machine Learning Research
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 三生石上(FineUI控件)
S
Security @ Cisco Blogs
Cloudbric
Cloudbric
E
Exploit-DB.com RSS Feed
Attack and Defense Labs
Attack and Defense Labs

博客园 - loveabel

汉鼎咨询:创业板上市企业募投项目变更原因深度分析 [导入]球员各个位置的关键属性问题 好好学习JAVA和.Net hibernate的语法怎么搞 一些关于中文乱码问题的一些解决方案和经验 前台对象的事件一览 复制表结构的通用存储过程 什么是web.config C#中使用DES HMACSHA1 SHA1 RC2 MD5 进行字符串加密的例程 两台SqlServer数据同步解决方案 正则表达式 自认为以下文章比较经典,希望对初学者有用^_^ c#中对文件的操作小结 IT人士群聚喝酒的讲究 谁在呐喊软件蓝领,那是他们准备开培训学校,谁在呐喊自主版权,那是他希望民族主义帮助销售,谁在呐喊“核心技术”,这多半是准备骗政府投资。 日历 系统数据库 sql server中扩展存储过程随笔(几个有用的PROCEDURE小总结) 修改数据库(设置数据库选项)
webconfig身份验证票
loveabel · 2005-09-09 · via 博客园 - loveabel

一、问题描述:有两种用户,买方,卖方;在数据库中分别有两个用户表。要求:网站根目录下有两个目录假设为DW目录、GR目录。目录下都

有一个login.aspx文件,分别是dwlogin.aspx,grlogin.aspx,登录时分别用自己的login.aspx文件,登录后不能访问对方的目录。

二、总体思路:创建自定义的身份验证票据,将roles信息放在票据的userData中.

三、设置Web.config
<configuration>
<system.web>
<authentication mode="Forms">
<forms name=".ASPXAUTH"
loginUrl="login.aspx"//根目录中的,就是下面的第六条
protection="All"
path="/"/>
</authentication>
         </system.web>
<location path="DW">
<system.web>
<authorization>
<allow roles="DW"/>
<deny users="*" />//这里必须用*,用?达不到要求
</authorization>
</system.web>
</location>
<location path="GR">
<system.web>
<authorization>
<allow roles="GR"/>
<deny users="*" />
</authorization>
</system.web>
</location>
<location path="/DW/DWLogin.aspx">
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
<location path="GR/GRLogin.aspx">
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
四、DWLogin.aspx中

private void Button1_Click(object sender, System.EventArgs e)
{
HttpCookie objCookie;
string  strReturnURL;
if (IsValid)
{
switch (GetUser( Username.Text,Password.Text))// GetUser函数得到用户名和密码,正确返回0,密码错返回2

,用户名错返回1
{
case 0:
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
1,
Username.Text,
DateTime.Now,
DateTime.Now.AddMinutes(30),
false,
"DW");//我是直接写进去的,可能还有更好的方法
objCookie = new HttpCookie( =(".ASPXAUTH" );
objCookie.Value = FormsAuthentication.Encrypt( ticket );
Response.Cookies.Add( objCookie );
strReturnURL = Request.Params[ "ReturnURL" ];
if ( strReturnURL != null )
{
Response.Redirect( strReturnURL );//返回到原来访问的页面
}
else
{
Response.Redirect( "Default.aspx" );//这里也可以设置你想设置的页面
}
break;
case 1:
this.Page.RegisterStartupScript("Info","<script>alert('该用户不存在!!');</script>");
break;
case 2:
this.Page.RegisterStartupScript("Info","<script>alert('密码错误!!');</script>");
break;
}
}
}

个人的登录页面GRLogin.aspx中写法同上面

五、Global.asax中添加如下代码:

protected void Application_AuthenticateRequest(Object sender, EventArgs e)
{
if (HttpContext.Current.User != null)
{
if (HttpContext.Current.User.Identity.IsAuthenticated)
{
if (HttpContext.Current.User.Identity is FormsIdentity)
{
FormsIdentity id =(FormsIdentity)HttpContext.Current.User.Identity;
FormsAuthenticationTicket ticket = id.Ticket;
string userData = ticket.UserData;
string[] roles = userData.Split(',');
HttpContext.Current.User = new GenericPrincipal(id, roles);
}
}
}
}

六、根目录下建login.aspx,其中添加如下代码:(这个login.aspx没有用户名和密码输入框,主要是用来重定位各自的登录页面)

private void Page_Load(object sender, System.EventArgs e)
{
string ParamName = "ReturnUrl";
string ReturnUrl = Request.QueryString[ParamName];
if (ReturnUrl.ToLower().IndexOf("DW") >=0)
{
Response.Redirect("DW/DWLogin.aspx?" + ParamName  + "=" + ReturnUrl);
}
else if (ReturnUrl.ToLower().IndexOf("GR") >=0 )
{
Response.Redirect("GR/GRLogin.aspx?" + ParamName  + "=" + ReturnUrl);
}
else
{
//这里添加一些你的提示,指定页面也可以
}
}