Impersonation in C# Windows Service

   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
Who is Participating?
swapneel_d14Connect With a Mentor Commented:

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.

Todd GerbertConnect With a Mentor IT ConsultantCommented:
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.."?
RyanAndresConnect With a Mentor Commented:
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."
Todd GerbertIT ConsultantCommented:

Do you mean a Windows service, or a web service?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.