Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Can't get windows id of user

Posted on 2011-04-21
6
Medium Priority
?
250 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

0
Comment
Question by:gdspeare
  • 3
  • 2
6 Comments
 

Author Comment

by:gdspeare
ID: 35442729
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
0
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 35442748
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
0
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 35442755
Of course, if no user is active (or logged in) the service will still run and a null would just be expected (and correct).
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 37

Accepted Solution

by:
TommySzalapski earned 2000 total points
ID: 35442762
0
 
LVL 2

Expert Comment

by:roshnipatel
ID: 35442796
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.
0
 

Author Closing Comment

by:gdspeare
ID: 35460854
Thanks Tommy.  I am going to have to create a login page for the application.

...boo
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Screencast - Getting to Know the Pipeline
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…
Suggested Courses

576 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