C#调用域账户登录窗体代码
来源:互联网 发布:vivo网络销售授权 编辑:程序博客网 时间:2024/05/19 06:50
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace SureKAM.SPM.Portal.WebSite
{
public partial class AccessDenied : System.Web.UI.Page
{
private int _authenticationAttempts = 0;
public int AuthenticationAttempts
{
get
{
if (!string.IsNullOrEmpty(string.Format("{0}", Session["AuthenticationAttempts"])))
{
int.TryParse(Session["AuthenticationAttempts"].ToString(), out _authenticationAttempts);
}
return _authenticationAttempts;
}
set
{
_authenticationAttempts = value;
Session["AuthenticationAttempts"] = _authenticationAttempts;
}
}
private string _currentUser = string.Empty;
public string CurrentUser
{
get
{
_currentUser = Request.LogonUserIdentity.Name;
Session["CurrentUser"] = _currentUser;
return _currentUser;
}
set
{
_currentUser = value;
Session["CurrentUser"] = _currentUser;
}
}
private string _previousUser = string.Empty;
public string PreviousUser
{
get
{
_previousUser = string.Format("{0}", Session["PreviousUser"]);
return _previousUser;
}
set
{
_previousUser = value;
Session["PreviousUser"] = _previousUser;
}
}
/// <summary>
/// This event fires on every page load
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
// Make sure the browser does not cache this page
this.DisablePageCaching();
// Increase authentication attempts
this.AuthenticationAttempts = this.AuthenticationAttempts + 1;
if (this.AuthenticationAttempts == 1)
{
// Change previous user to current user
this.PreviousUser = this.CurrentUser;
// Send the first 401 response
this.Send401();
}
else
{
// When a browser is set to "automaticaly sign in with current credentials", we have to send two 401 responses to let the browser re-authenticate itself.
// I don't know how to determine if a browser is set to "automaticaly sign in with current credentials", so two 401 responses are always send when the user
// does not switch accounts. In Micrososft Office sharepoint the user has to supply the credentials 3 times, when the user does not switch accounts,
// so it think this is not a problem.
if (this.AuthenticationAttempts == 2 && this.CurrentUser.Equals(this.PreviousUser))
{
// Send the second 401 response
this.Send401();
}
else
{
// Clear the session of the current user. This will clear all sessions objects including the "AuthenticationAttempts"
Session.Abandon();
Session.Clear();
// Redirect back to the main page
Response.Redirect("~/Default.aspx");
}
}
}
/// <summary>
/// Make sure the browser does not cache this page
/// </summary>
public void DisablePageCaching()
{
Response.Expires = 0;
Response.Cache.SetNoStore();
Response.AppendHeader("Pragma", "no-cache");
}
/// <summary>
/// Send a 401 response
/// </summary>
public void Send401()
{
// Create a 401 response, the browser will show the log-in dialogbox, asking the user to supply new credentials, // if browser is not set to "automaticaly sign in with current credentials"
Response.Buffer = true;
Response.StatusCode = 401;
Response.StatusDescription = "Unauthorized";
// A authentication header must be supplied. This header can be changed to Negotiate when using keberos authentication
Response.AddHeader("WWW-Authenticate", "NTLM");
// Send the 401 response
Response.End();
}
}
}
- C#调用域账户登录窗体代码
- C# 登录窗体 窗体调用
- C# 登录窗体 窗体调用
- C#登录窗体代码设计
- C#模拟windows账户登录,并复制文件代码
- C#登录窗体
- C# 操作域 用管理员登录修改选定账户密码
- C# 窗体间调用
- C#窗体调用
- C# 窗体间调用
- C#关闭登录窗体,显示主窗体
- C#登录窗体与主窗体
- C#窗体渐显代码
- WinForm之登录窗体代码
- C# 域账户验证
- C#调用存储过程返回值 (登录代码)
- C#中调用SQL存储过程实现登录认证代码
- C#之一窗体调用另一窗体属性
- 修改Linux操作系统下ssh端口
- 揭开正则表达式的神秘面纱
- Oracle 数据库监听配置
- 产品设计之扮演用户
- Hadoop Gridmix基准测试
- C#调用域账户登录窗体代码
- html中16进制的代码对应颜色表
- 用触发器同步2个实例之间的表
- NAND和NOR flash的区别(转载)
- 在Apache下配置PHP5
- H323笔记
- Oracle 数据库管理脚本 命名规范
- 平面设计LOGO输出十大陷阱
- 矩阵类型和内存寻址