在ASP.NET应用程序中使用身份模拟(Impersonation)
- ASP.NET中的身份模拟
- 模拟IIS认证帐号
- 在某个ASP.NET应用程序中模拟指定的用户帐号
- 在代码中模拟IIS认证帐号
- 在代码中模拟指定的用户帐号
- 更多信息
- 模拟IIS认证帐号
- 在某个ASP.NET应用程序中模拟指定的用户帐号
- 在代码中模拟IIS认证帐号
- 在代码中模拟指定的用户帐号
<identity impersonate="true" />
<identity impersonate="true" userName="accountname" password="password" />
System.Security.Principal.WindowsImpersonationContext impersonationContext; impersonationContext = ((System.Security.Principal.WindowsIdentity)User.Identity).Impersonate(); //Insert your code that runs under the security context of the authenticating user here. impersonationContext.Undo();
<%@ Page Language="C#"%> <%@ Import Namespace = "System.Web" %> <%@ Import Namespace = "System.Web.Security" %> <%@ Import Namespace = "System.Security.Principal" %> <%@ Import Namespace = "System.Runtime.InteropServices" %> <script runat=server> public const int LOGON32_LOGON_INTERACTIVE = 2; public const int LOGON32_PROVIDER_DEFAULT = 0; WindowsImpersonationContext impersonationContext; [DllImport("advapi32.dll", CharSet=CharSet.Auto)] public static extern int LogonUser(String lpszUserName, String lpszDomain, String lpszPassword, int dwLogonType, int dwLogonProvider, ref IntPtr phToken); [DllImport("advapi32.dll", CharSet=System.Runtime.InteropServices.CharSet.Auto, SetLastError=true)] public extern static int DuplicateToken(IntPtr hToken, int impersonationLevel, ref IntPtr hNewToken); public void Page_Load(Object s, EventArgs e) { if(impersonateValidUser("username", "domain", "password")) { //Insert your code that runs under the security context of a specific user here. undoImpersonation(); } else { //Your impersonation failed. Therefore, include a fail-safe mechanism here. } } private bool impersonateValidUser(String userName, String domain, String password) { WindowsIdentity tempWindowsIdentity; IntPtr token = IntPtr.Zero; IntPtr tokenDuplicate = IntPtr.Zero; if(LogonUser(userName, domain, password, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, ref token) != 0) { if(DuplicateToken(token, 2, ref tokenDuplicate) != 0) { tempWindowsIdentity = new WindowsIdentity(tokenDuplicate); impersonationContext = tempWindowsIdentity.Impersonate(); if (impersonationContext != null) return true; else return false; } else return false; } else return false; } private void undoImpersonation() { impersonationContext.Undo(); } </script>
bool a = File.Exists("D://Share//test.txt");
<identity impersonate="true" userName="FileExist" password="password" />
在ASP.NET应用程序中使用身份模拟(Impersonation)相关推荐
- 在ASP.NET应用程序中捕捉身份验证状态的变化
前年我写过一篇随笔抱怨Microsoft在ASP.NET架构中Session_End事件上处理,说来惭愧,其实当年我对ASP.NET运行时的复杂性理解不足.实话说,捕捉通过身份验证和注销身份验证对我来 ...
- 在Asp.net应用程序中构建基于WCF Web.Api的服务
WCF Web API Preview 5 发布了,你可以官方网站下载或通过Nuget安装它. 下面让我们在Asp.net applicatoin中来实现一个非常简单的web api service. ...
- 【EntityFramework系列教程三,翻译】在ASP.NET MVC程序中使用EntityFramework对数据进行排序、过滤筛选以及实现分页...
上一章中您已经为Students实体集实现了不同页面的增删改查的功能,本章中您将为Index页面给Students增加分页.过滤以及排序功能.你将创建一个实现简单分组功能的页面. 以下就是即将你要看到 ...
- [原创] ASP.NET 应用程序中使用定时器
作用: 可以用来定时发送邮件,定时发送窗口提示. 能不能人工参与的事都可以用这个 Ajax的Timer 需要 在网页中才有效果,因为它是用setTimeout()实现的. System.Timers. ...
- 【EntityFramework系列教程五,翻译】在ASP.NET MVC程序中借助EntityFramework读取相关数据...
在前一章中你完成了复杂的学校数据模型,在本章节中你将读取并且展示这些相关数据--也就是EntityFramework加载到导航属性中的那些数据. 以下截图展示你要完成的效果: [慢模式.饥饿模式以及显 ...
- [转载]保护 ASP.NET 应用程序的安全
查看全部的安全性指导主题 Microsoft Corporation 本单元概要 保护 ASP.NET Web 应用程序依赖于完全受到保护的网络.主机和平台基础结构.如果果真如此,攻击者将试图利用 W ...
- 保护 ASP.NET 应用程序的安全
本单元概要 保护 ASP.NET Web 应用程序依赖于完全受到保护的网络.主机和平台基础结构.如果果真如此,攻击者将试图利用 Web 应用程序和 Web 服务(它们通常侦听端口 80)中的漏洞.如果 ...
- 在ASP.NET MVC应用程序中实现Server.Transfer()类似的功能
在ASP.NET MVC应用程序中,如果使用Server.Transfer()方法希望将请求转发到其它路径或者Http处理程序进行处理,都会引发"为xxx执行子请求时出错"的Htt ...
- ASP.NET实现身份模拟
使用模拟时,ASP.NET 应用程序可以选择以这些应用程序当前正为之操作的客户的身份执行.通常这样做的原因是为了避免在 ASP.NET 应用程序代码中处理身份验证和授权问题.而您依赖于 Microso ...
- ASP.NET 应用程序生命周期概述
本主题概述应用程序生命周期,列出重要的生命周期事件,并描述如何编写适合应用程序生命周期的代码.在 ASP.NET 中,若要对 ASP.NET 应用程序进行初始化并使它处理请求,必须执行一些处理步骤.此 ...
最新文章
- Python——pyiso8601
- 成功解决ImportError: cannot import name 'pywrap_tensorflow'
- 【C++拾遗】 从内存布局看C++虚继承的实现原理
- 05-xpath爬虫数据解析
- mysql1231错误_Mysql学习---Python操作Mysql 1231
- 户外lisp导向牌如何安装_聚焦热点、难点,持续开展户外广告(招牌)专项整治...
- android上传图片被旋转,input上传照片旋转解决办法
- 67 SD配置-交货凭证配置-分配 SD 查找过程/激活检查
- 初学者python笔记(类的装饰器、property方法、元类)
- 卸载 Visual Studio 2005步骤
- 【Gym-100085 E】Eve【模拟题】
- 变色龙引导安装mac
- 点击复选框添加或删除value值到input输入框中
- BeanUtils.copyProperties 和 fastjson 性能对比
- 基于Java开发证券交易撮合系统的尝试
- Python爬虫:搜狗(微信,知乎)公众号内容
- actionbar左上角的返回小图标
- 照片模糊怎么办?教你简单三步瞬间修复照片清晰度!
- LDMFA,LDMFD,STMFA,STMFD,LDMEA,LDMED,STMEA,STMED
- Polkit权限提升漏洞(CVE-2021-4034)利用及修复
热门文章
- 创建dqn的深度神经网络_深度Q网络(DQN)-I
- 软件测试前景会被ai取代吗_软件测试人员可能很快会被AI程序取代
- java重置radiobutton的选项_动态添加试题选项按钮 radioButton(一)
- wordpress php 模板修改,教你如何修改wordpress模版技巧分享
- vue-cli mock
- activity启动模式之standard
- “约女生图书馆一起自习”总结
- Android 打开WIFI并快速获取WIFI的信息
- VNC服务的使用和使用qemu-img工具创建更多格式的磁盘映像文件
- Gxemul 运行原理简述