Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1050533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:47:04+00:00 2026-05-16T16:47:04+00:00

I modified the ASP.NET login control to also allow specifying UserRole (‘Employee’ or ‘Volunteer’).

  • 0

I modified the ASP.NET login control to also allow specifying UserRole (‘Employee’ or ‘Volunteer’). Users are authenticated via a call to a webservice written by our client, which accepts username/password/role and returns true or false.

  • If role is ‘Employee’ it represents an active directory user. The application should impersonate the user with the given username/password.
  • If role is ‘Volunteer’ the application should run under a set Windows account whose username/password are known in advance (i.e. hard-coded in web.config file).

The server runs on Windows Server 2003. I am confused by the myriad of configuration choices and trying to understand my options;

Is it possible to have multiple scenarios as described?

Should I specify the impersonation programmatically or can it be done through the config file? If so, is it required to use LogonUser or WindowsIdentity?

What config file setup should I use? (i.e. Forms authentication, impersonate=true, etc..)

Thank you in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T16:47:04+00:00Added an answer on May 16, 2026 at 4:47 pm

    Because the decision about which identity to impersonate is based on run-time data, you’ll likely have to deal with impersonation programmatically.

    I use a combination of interop and WindowsIdentity to handle impersonation. The steps I follow are:

    1. Log on using the interop LogonUserA(), which fills a handle to an IntPtr (token).
    2. Duplicate the token with the interop DuplicateToken().
    3. Create a new windows identity, a la: var identity = new WindowsIdentity(tokenDuplicate);.
    4. Create an impersonation context via: var context = identity.Impersonate();
    5. Close both tokens with the interop CloseHandle()
    6. When finished impersonating, undo the impersonation context via: context.Undo();

    I keep a disposable class around to handle the details. Steps 1-5 occur in a constructor, and step 6 occurs in the dispose routine. This helps ensure that I properly revert even in the face of an exception.

    With this approach, since you are passing credentials via a service method, the web.config authentication scheme is not entirely forced. If, however, you are using integrated Windows auth, you could programmatically impersonate the current user from HttpContext.Current.User.Identity.Impersonate(), without passing credentials in a service method.

    On an aside, and you may already know, PInvoke.net is a valuable resource for configuring signatures for interop methods.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using DotNetOpenAuth in my ASP.Net Website. I have modified it to work
To start off, I'm using Asp.Net MVC 4, and I've modified my solution to
We have an ASP.NET application that uses Forms Auth. When users log in, a
we've modified our customErrors section to protect against the recent ASP.NET vulnerability. Our problem
I am working on an ASP.net Ajax custom control, I have tried to derive
Can mod_mono's AutoHosting be modified to support ASP.NET? ATM it doesn't really work: Link
in ASP.NET, I've bound a listbox control to a List of custom class (consisting
I am trying to create a login form on my ASP.NET website. Currently, there's
I just downloaded C# SDK and ASP.NET MVC sample, modified it to work with
In ASP.NET web forms when a control is rendered on the page, the ID

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.