Impersonation in C# Windows Service

Hey,
   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"/>
    <authorization>
     
      <deny users="*" />
    </authorization>

   <identity impersonate="true"
          userName="domain\user"
          password="password" />

ofcourse, i used the relevant domain and user for my application
gautam_reddycAsked:
Who is Participating?
 
swapneel_d14Connect With a Mentor Commented:
Hi

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.

0
 
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.."?
0
 
RyanAndresConnect With a Mentor Commented:
Use the following instead:
<deny users="?" />

http://msdn.microsoft.com/en-us/library/8aeskccd.aspx

"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."
0
 
Todd GerbertIT ConsultantCommented:
gautam_reddyc:

Do you mean a Windows service, or a web service?
0
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.