如何将管理员凭据传递给Windows身份 [英] How to pass Admin credentials to windows identity

查看:118
本文介绍了如何将管理员凭据传递给Windows身份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我想以编程方式传递管理员用户凭据(VB.net).

有我的Web应用程序,我以简单用户身份登录了应用程序,但是当我访问计划的任务时,当时我想要应用程序应以编程方式获取凭据,然后将其硬编码为代码.

当前代码如下:

Hi All,

I want to pass admin user credentials programatically(VB.net).

there is my web application, i logged-in application as simple user but when i access scheduled tasks that time i want to application should take credentials programatically which i will hard coded into the code.

present code is as below:

Dim wi As WindowsIdentity = HttpContext.Current.User.Identity
Dim wic As WindowsImpersonationContext = wi.Impersonate()


此处wi对象应包含管理员凭据.
有可能吗?

感谢您的帮助.


here at wi object should contains admin credentials.
is it possible?

Your help is appreciated.

推荐答案

看看这篇文章,它为您提供了模仿者"类

用于模仿用户的小型C#类 [ ^ ]

您可以包装在using块中,以清楚地了解在特权提升下正在执行哪部分代码.这是非常好的.
Have a look at this article, which gives you an ''Impersonator'' class

A small C# Class for impersonating a User[^]

It''s quite nice that you can wrap in a using block for obvious clarity about which section of code is executing under elevated priviliges.


这篇关于如何将管理员凭据传递给Windows身份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆