网站首页
网站导航
Ctrl+D收藏
首 页
代码段
源码包
文档库
工具箱
代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
CSharp
】
调用域账户登录窗体
作者:
lyhabc
/ 发布于
2015/2/28
/
539
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(); } } }
评论列表
本站所提供的代码,版权归原作者所有,若有侵犯作者版权,请与我们联系,我们将立即删除或修改。谢谢!
本站所有代码发布及提供者。
试试其它关键字
域账户
v
同语言下
.
文件IO 操作类库
.
Check图片类型[JPEG(.jpg 、.jpeg),TIF,GIF,BMP,PNG,P
.
机器名和IP取得(IPV4 IPV6)
.
Tiff转换Bitmap
.
linqHelper
.
MadieHelper.cs
.
RegHelper.cs
.
如果关闭一个窗体后激活另一个窗体的事件或方法
.
创建日志通用类
.
串口辅助开发类
可能有用的
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
.
实现对图片上传的接收
.
判断用户输入的是否为IP地址
lyhabc
贡献的其它代码
(
4
)
.
调用域账户登录窗体
.
在 SQL Server 2005 实例之间传输登录和密码
.
批量导出当前实例下的所有linkedserver
.
SQL2008查找某数据库中的列是否存在某个值
地图
本站
我们
服务
版权
联系
回馈
博客