Impersonation in C# Windows Service

Posted on 2009-12-29
Medium Priority
Last Modified: 2012-05-08
   I neeed to implement authorization and impersonation for my C# windows service..

  It is same as doing ASP.NET or do you have a different process..

  i tried the below code.. it does not work..
   neither does it give error...

   It allows every one to access the code..

 <authentication mode="Windows"/>
      <deny users="*" />

   <identity impersonate="true"
          password="password" />

ofcourse, i used the relevant domain and user for my application
Question by:gautam_reddyc
  • 2

Accepted Solution

swapneel_d14 earned 668 total points
ID: 26139417

1] When u install your C# windows service under which account it connects to databse e.g. "Local system" or custom acount.

2] change service Log On as this account - your domain account  and try.

LVL 33

Assisted Solution

by:Todd Gerbert
Todd Gerbert earned 668 total points
ID: 26139422
You want the service to run as a different user, or just temporarily impersonate another user to do some work?

What do you mean by "It allows every one to access the code.."?

Assisted Solution

RyanAndres earned 664 total points
ID: 26140091
Use the following instead:
<deny users="?" />


"At run time, the authorization module iterates through the allow and deny elements, starting at the most local configuration file, until the authorization module finds the first access rule that fits a particular user account. Then, the authorization module grants or denies access to a URL resource depending on whether the first access rule found is an allow or a deny rule. The default authorization rule is <allow users="*"/>. Thus, by default, access is allowed unless configured otherwise."

"A question mark (?) denies anonymous users and an asterisk (*) indicates that all user accounts are denied access."
LVL 33

Expert Comment

by:Todd Gerbert
ID: 26140161

Do you mean a Windows service, or a web service?

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

840 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