Can't get windows id of user

Posted on 2011-04-21
Last Modified: 2012-05-11
I'm have an application that i recently switched to run on a service account.  The application pool runs under the service account and executes all the stored procedures.  Before i made this change i was able to grab the windows id of the logged in user and pass it into a stored procedure variable.  Now, though


is returning a null value.
protected void GetObjects_Specific(Object sender, EventArgs e)
        //Remove the session state variable if it exists
        txt_PWReason.Text = "";
        // set the session state variable
        Session["int_ObjectID"] = ddl_AllObjects.Text.ToString();

        DataView dvw_SpecificObject = (DataView)usp_SpecificObject_SELECT.Select(DataSourceSelectArguments.Empty);
        foreach (DataRowView dvw_DataRowView in dvw_SpecificObject)
            string str_ddlAllObjects = Session["int_ObjectID"].ToString();
            lbl_ShortDescr.Text = dvw_DataRowView["vch_ObjectDetail"].ToString();

        if (string.IsNullOrEmpty(System.Web.HttpContext.Current.User.Identity.Name.ToString()))
            txt_CurrentUser.Text = "it's null, get over it";
            txt_CurrentUser.Text = System.Web.HttpContext.Current.User.Identity.Name.ToString();

Open in new window

Question by:gdspeare

    Author Comment

    Some progress.  

      txt_CurrentUser.Text = WindowsIdentity.GetCurrent().Name;

    will at least return my service account.  

    So now I need to figure out how to get the true login id of the computer and not the account running the application
    LVL 37

    Expert Comment

    It's running as a service so the user is the service account (which apparently comes back null). Multiple people can be logged on at the same time, so who's to say which user to use? I suppose you want the ID of the active user. This really isn't usually done since services aren't supposed to be 'snooping' on users. The standard way to do it would be to have it communicate with a user application that the user starts or that automatically starts.
    See here:
    LVL 37

    Expert Comment

    Of course, if no user is active (or logged in) the service will still run and a null would just be expected (and correct).
    LVL 37

    Accepted Solution

    LVL 2

    Expert Comment

    Are you using Windows Authication?
    IIS7+ - Under IIS -> [Application] -> Authentication
    IIS6  - Under IIS -> Virtual Directory -> right-click -> Manage -> Directory Security tab
          Under Anonymous access and auth. -> click Edit

    Make sure that Integrated Windows Auth is enabled or checked.

    Author Closing Comment

    Thanks Tommy.  I am going to have to create a login page for the application.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    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…
    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…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    734 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

    18 Experts available now in Live!

    Get 1:1 Help Now