Impersonation in C# Windows Service

Posted on 2009-12-29
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
    LVL 2

    Accepted Solution


    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
    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.."?
    LVL 8

    Assisted Solution

    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

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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
    We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    779 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

    11 Experts available now in Live!

    Get 1:1 Help Now