Link to home
Start Free TrialLog in
Avatar of ICantSee
ICantSeeFlag for United States of America

asked on

Access windows login info in a asp.net page

We have an app for users to submit support requests. Currently they have to select their site, then their username and their email address populates automatically. We would like the page to "know" who is accessing it so that all of the fields are filled in for them.

This app is running on our intranet, and only users with domain credentials can access it.

User generated image
Avatar of Craig Wagner
Craig Wagner
Flag of United States of America image

Switch the IIS security so it uses Windows Authentication. Then in your application code you can get the user information from the user principal.
Avatar of ICantSee

ASKER

it already uses windows authentication. I just don't know how to program against it.
Is it ASP.NET WebForms or ASP.NET MVC?
User.Identity.Name
Asp.net web forms..

user.identity.name looks promising... what do I do  with it?
The base page class has a property called User which has an Identity property that is of type IIdentity. The IIdentity contains information about the current user. Here's the documentation on the interface.

http://msdn.microsoft.com/en-us/library/system.security.principal.iidentity(v=vs.110).aspx

The IIdentity Name property contains the name of the current authenticated user in the form "domain\username".

I'm not sure what you mean by "what do I do with it." Do whatever you want/need to do with it, it's the username.
Thank you for the information.

What I mean by saying what do I do with it is simply that. Knowing what it can do is great, but not very helpful unless I know the VB code to go with it.

I simply want a couple of labels or textboxes to populate with a user's username and email address when they open the page.

I am not a trained programmer. My expertise is Network Administration.  Experts Exchange has helped me fill the programming void by tapping into programming experts knowledge. That is what I am trying to accomplish here.
Regardless of whether you're trained as a programmer, you are doing programming, and part of programming is trial-and-error. In your original post you stated,

Currently they have to select their site, then their username and their email address populates automatically. We would like the page to "know" who is accessing it so that all of the fields are filled in for them.

This implies to me that the code is currently setting a field/label/textbox to the username and email address. So change the code to use the username from User.Identity.Name. It's just a string, like you're already dealing with. If you have a TextBox on the page, just set its Text property to the username.

txtUserName.Text = User.Identity.Name

Open in new window


Asking for us to write the code for you and wrap it up in a neat little bow is unrealistic. We don't know the names/types of your controls/variables. We don't know how you're getting the email address. From what you've said you already have code that gets that information and presumably puts it into variables, just make a few tweaks, run it, see what happens, and try again. Honestly, even with trial-and-error you'll arrive at a working solution more quickly than waiting 24 hours for an answer on EE.

Bottom line, most of us are happy to help and point you in the right direction, but at some point you have to take the ball and run it over the finish line.
ASKER CERTIFIED SOLUTION
Avatar of kumar754
kumar754
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thank you for your responses. sincerely.

I do not know your situation nor do you know mine. The very reason I am on EE is because I juggle multiple projects and while I am waiting for an answer on one I am working on another. Wondering aimlessly through google. and youtube ( yes I have used both extensively) pales in the success that I have had with EE.

The username is a dropdown list that is bound to a SQL database. I have a piece of code than another expert happily gave me that is pulling the email address. I simply was hoping to eliminate another step for our users.

I do not know your situation, but I can tell you that you have both been the least friendly experts to answer my questions. Please do not reply anymore if it is beneath you to share your abilities and knowledge.