473,387 Members | 1,501 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Impersonate via code?

I know that you can do different things to enable different types of
impersonation using the config files (like set it up so the end user is the
one being impersonated, or set it up so the asp.net WP runs as a specific
domain user).

But, what I am wondering if it is possible to change the impersonation
account via code? For example, lets say that for 1 function you need to
access a remote file share to grab a file. Is there a way to, while that 1
function is running, use the privledges of a different user and then return
to the original privledges after the function has retreived the file?
Nov 19 '05 #1
4 1279
Hi,

Given the right permissions you can probably use the LogonUser API to logon
a specific user, but you would need username and password to logon.

Haven't tried this but it should work given that your Web Application has
permissions to call API routines.

Going back to the account that was running is more difficult. You can use
RevertToSelf() which will revert back to the underlyig machine account (ie.
NETWORK SERVICE most likely) or whatever account IIS (in IIS 5) or the
Application Pool (in IIS6) is running under.

+++ Rick ---

--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/weblog/
http://www.west-wind.com/wwThreads/
----------------------------------
Making waves on the Web
"cmay" <cm**@discussions.microsoft.com> wrote in message
news:E6**********************************@microsof t.com...
I know that you can do different things to enable different types of
impersonation using the config files (like set it up so the end user is the one being impersonated, or set it up so the asp.net WP runs as a specific
domain user).

But, what I am wondering if it is possible to change the impersonation
account via code? For example, lets say that for 1 function you need to
access a remote file share to grab a file. Is there a way to, while that 1 function is running, use the privledges of a different user and then return to the original privledges after the function has retreived the file?

Nov 19 '05 #2

I haven't checked this out in a while, so I tried it out and put up some
more info on this here:

http://west-wind.com/weblog/posts/1572.aspx

+++ Rick ---

--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/weblog/
http://www.west-wind.com/wwThreads/
----------------------------------
Making waves on the Web

--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/weblog/
http://www.west-wind.com/wwThreads/
----------------------------------
Making waves on the Web
"cmay" <cm**@discussions.microsoft.com> wrote in message
news:E6**********************************@microsof t.com...
I know that you can do different things to enable different types of
impersonation using the config files (like set it up so the end user is the one being impersonated, or set it up so the asp.net WP runs as a specific
domain user).

But, what I am wondering if it is possible to change the impersonation
account via code? For example, lets say that for 1 function you need to
access a remote file share to grab a file. Is there a way to, while that 1 function is running, use the privledges of a different user and then return to the original privledges after the function has retreived the file?

Nov 19 '05 #3

I put up some more info on this here:

http://west-wind.com/weblog/posts/1572.aspx

+++ Rick ---

--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/weblog/
http://www.west-wind.com/wwThreads/
----------------------------------
Making waves on the Web
"cmay" <cm**@discussions.microsoft.com> wrote in message
news:E6**********************************@microsof t.com...
I know that you can do different things to enable different types of
impersonation using the config files (like set it up so the end user is the one being impersonated, or set it up so the asp.net WP runs as a specific
domain user).

But, what I am wondering if it is possible to change the impersonation
account via code? For example, lets say that for 1 function you need to
access a remote file share to grab a file. Is there a way to, while that 1 function is running, use the privledges of a different user and then return to the original privledges after the function has retreived the file?

Nov 19 '05 #4
Rick,

Very cool writeup!

Thanks
Chris

Nov 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: moemeelaung | last post by:
Hi ASP/Windows experts out there I really need help with this Impersonate function. I have machine A and B. A hosts my ASP page which is to create a user account on the machine B. The...
14
by: Ian Frawley | last post by:
Anyone used the WindowsIdentity class with success? I find if I try to change the current identity to one that exists on another machine and then try to perform and action on that machine i.e....
8
by: BLiTZWiNG | last post by:
After playing with the code shown and utilising Willy Denyottes' help, I have come to the conclusion that there is some form of difference between the managed WindowsIdentity.Impersonate() over the...
2
by: Divya | last post by:
Hello, I am developing a simple move file utility to move files from one domain to another in the same internal network. My program runs fine when it reads the parameters (user, domain, password...
6
by: Erez Shor | last post by:
Hi, I need to build and asp page which access a remote windows server's registry and create a registry key. In order for the ASP page to be able to access the registry on the remote server I need...
6
by: Meena Desai | last post by:
Hi, What are the effects of using <identity impersonate="true"/> in web.config on windows auhtentication? Does it affect windows security? Thanx in advance, Meena.
8
by: RTT | last post by:
i'm writing a windows form but codebased a iwant to run the code as a different user. like in a webapplication you can impersonate a user so the website does not run on the standard ASP.NET...
0
by: bvasanth123 | last post by:
Hi, I am running the ASP.NET web application which is running under domain id USER1. My OS is XP. I had added the following location tag in machine.config to make my application run under USER1....
2
by: rockdale | last post by:
Hi, all: My asp.net application calles MS speech 5.1 and generate a wav file on server's path. Everything runs perfectly on my development machine. But when I move the appl to production server,...
4
by: =?Utf-8?B?QXZhRGV2?= | last post by:
ASP.Net 2. We are migrating to Windows 2008 64 bit Server with IIS 7 from Windows 2003 32 Bit with IIS 6. A few library classes we wrote uses impersonation in code like explained in this...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.