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

推荐订阅源

S
Secure Thoughts
Security Latest
Security Latest
Simon Willison's Weblog
Simon Willison's Weblog
O
OpenAI News
GbyAI
GbyAI
L
LINUX DO - 最新话题
A
Arctic Wolf
T
Tor Project blog
G
GRAHAM CLULEY
I
InfoQ
博客园_首页
IT之家
IT之家
The Register - Security
The Register - Security
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Proofpoint News Feed
The GitHub Blog
The GitHub Blog
Blog — PlanetScale
Blog — PlanetScale
N
Netflix TechBlog - Medium
K
Kaspersky official blog
博客园 - 三生石上(FineUI控件)
S
SegmentFault 最新的问题
U
Unit 42
PCI Perspectives
PCI Perspectives
量子位
P
Palo Alto Networks Blog
S
Securelist
T
Troy Hunt's Blog
博客园 - 【当耐特】
Recorded Future
Recorded Future
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
S
Security Affairs
Engineering at Meta
Engineering at Meta
T
The Blog of Author Tim Ferriss
博客园 - 聂微东
罗磊的独立博客
N
News and Events Feed by Topic
人人都是产品经理
人人都是产品经理
B
Blog RSS Feed
NISL@THU
NISL@THU
C
Cisco Blogs
T
Threatpost
有赞技术团队
有赞技术团队
Forbes - Security
Forbes - Security
Hugging Face - Blog
Hugging Face - Blog
Last Week in AI
Last Week in AI
T
The Exploit Database - CXSecurity.com
Cloudbric
Cloudbric
Cyberwarzone
Cyberwarzone
Google DeepMind News
Google DeepMind News
C
Cyber Attacks, Cyber Crime and Cyber Security

博客园 - 磊

淘宝店铺开业送优惠券 报表统计查询 Word 发布测试 【原创】hibernate中delete的一点见解 关于23种设计模式的有趣见解[转] 用Visual C#调用Windows API函数 DataGrid,GridView和DetailsView中添加删除确认提示 2.0新控件 Localize ASP.NET直接下载一个文件 - 磊 - 博客园 dFastlog.dll错误和数据库连接错误的解决办法 "Automation 服务器不能创建对象" 的解决方法 - 磊 "FSO"的禁用与启用 如何做最简单的url跳转 我的主页 更换SQL对象属主的方法 如何在WinXP中批量修改文件名? Nokia 中的暂停功能 Froms验证 改版网站真麻烦
利用Forms实现两种不同验证系统
· 2005-09-03 · via 博客园 - 磊

经常看到的Forms验证都是在一个应用程序下实现一种验证登陆系统。而我要做的项目,要在一个应用程序下实现两种不同的登陆验证方式(前台登陆和后台登陆)。费了一些功夫终于做出来了。其实实现方法很简单,我把主要代码贴出来希望大虾们不要笑话。

与别的Forms验证相同的部分我不再写了,可参照我的上一篇:

Froms验证  或到网上艘 到处都是。

<authentication mode="Forms">
            
<forms name=".ASPXFORMSDEMO" loginUrl="LoginRedirect.aspx" protection="All" path="/"
                timeout
="30" />
        
</authentication>

注意loginUrl并不是真正的登陆页面而是一个重定向页面,由他判断是跳转到哪一个登陆页面。代码如下:

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace TestForms
{
    
/// <summary>
    
/// LoginRedrirect 的摘要说明。
    
/// </summary>

    public class LoginRedirect : System.Web.UI.Page
    
{
        
private void Page_Load(object sender, System.EventArgs e)
        
{
            
// 在此处放置用户代码以初始化页面

            
string url=Request.QueryString["ReturnUrl"];
            
if(url != null )
            
{    
                
if(Request.ApplicationPath !="/")
                
{
                    url
=url.Replace(Request.ApplicationPath,"");
                }

                
                
if(!url.StartsWith("/"))
                    url
="/"+url;

                
string path=url.Split('/')[1].ToLower();
                
switch (path)
                
{
                    
case "admin":
                        Response.Redirect(
"admin/AdminLogin.aspx?ReturnUrl="+Server.HtmlDecode(Request.QueryString["ReturnUrl"]),false);
                        
break;
                    
case "user":
                        Response.Redirect(
"user/UserLogin.aspx?ReturnUrl="+Request.QueryString["ReturnUrl"],false);
                        
break;
                    
default :                            
                        Response.Redirect(
"#");
                        
break;
                }

            }

            
else
                Response.Redirect(
"#");
        }


        
#region Web 窗体设计器生成的代码
        
override protected void OnInit(EventArgs e)
        
{
            
//
            
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
            
//
            InitializeComponent();
            
base.OnInit(e);
        }

        
        
/// <summary>
        
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
        
/// 此方法的内容。
        
/// </summary>

        private void InitializeComponent()
        
{    
            
this.Load += new System.EventHandler(this.Page_Load);

        }

        
#endregion

    }

}

在Web.config中添加

    <location path="user">
        
<system.web>
            
<authorization>
                
<allow roles="user"></allow>
                
<deny users="*" /> <!-- 只允许验证用户访问 -->
            
</authorization>
        
</system.web>
    
</location>
    
<location path="admin">
        
<system.web>
            
<authorization>
            
<allow roles="Admin"></allow>
                
<deny users="*" /> <!-- 只允许验证用户访问 -->
            
</authorization>
        
</system.web>
    
</location>
    
<location path="admin/AdminLogin.aspx">
        
<system.web>
            
<authorization>
                
<allow users="*" />
            
</authorization>
        
</system.web>
    
</location>
    
<location path="user/UserLogin.aspx">
        
<system.web>
            
<authorization>
                
<allow users="*" />
            
</authorization>
        
</system.web>
    
</location>

注意:在登陆的时候还要添加组 (Admin 或 user)并且管理文件都在Admin目录中前待续验证文件都在user中

以此类推可在一个应用程序下实现多种验证登陆系统