We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Can't get windows id of user

gdspeare
gdspeare asked
on
Medium Priority
261 Views
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

System.Web.HttpContext.Current.User.Identity.Name.ToString();

is returning a null value.
protected void GetObjects_Specific(Object sender, EventArgs e)
    {
        //Remove the session state variable if it exists
        //Session.Remove{"int_ObjectID");   
        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";
        }
        else
        {
            txt_CurrentUser.Text = System.Web.HttpContext.Current.User.Identity.Name.ToString();
        }
    }

Open in new window

Comment
Watch Question

Author

Commented:
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
CERTIFIED EXPERT
Awarded 2010
Top Expert 2013

Commented:
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: http://stackoverflow.com/questions/418119/c-run-windows-form-application-from-service-and-in-vista
CERTIFIED EXPERT
Awarded 2010
Top Expert 2013

Commented:
Of course, if no user is active (or logged in) the service will still run and a null would just be expected (and correct).
CERTIFIED EXPERT
Awarded 2010
Top Expert 2013
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
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

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

...boo
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.