Running a function as a specific user account.

Posted on 2005-04-14
Last Modified: 2010-04-07
I suspect the answer to this problem is no, however here it is.

Is there any way to run a specific function of code under a specified user account? I have an asp application (intranet) that uses the Integrated security method. ie if MyDomain\UserA is the owner of the browser, then MyDomain\UserA is the account that runs the code.

I have a page that need to use the current user for most of the code, however one function on that page needs to use a specific user account to get the job done.  I need to know how to run the page under integrated security, and yet run the one function as Mydomain\Superuser.

A web config file in folder wont do it, as it changes the security method for the entire page. So I am looking for a line(s) of code that can be contained within my function to swap the user

I need something like:-


{execute code that needs new security access}

CurrentUser.Name= {Integrated user etc}

{rest of code that needs current user permissions now runs}
Can this be done?
Question by:CaptainRantflaps
    1 Comment
    LVL 20

    Accepted Solution

    Yes, impersonation is the answer. However, depends on operating system on where your code is running; you'd need to set some security settings. This is best sample code I've seen so far:

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
    Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now