473,811 Members | 2,843 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Get UserName

Hello,

I know that only authenticated users has a UserName. In Anonymous
users there is an ID.

If I am not wrong when getting a profile of a user, if the user is
authenticated the UserName is used. If it is anonymous it is used its
ID that is also stored on a cookie.

What is the correct way to get the UserName or Anonymous user ID of
the current user?

I am using:

HttpContext.Cur rent.Profile.Us erName

Is this the correct way?

Thanks,

Miguel
Nov 15 '08 #1
2 4701
it depends on usage. Profile.UserNam e is the username of the profile
(should match the authenticated username if not anonymous). if you are
using the username for security, don't use profile, use:

HttpContext.Cur rent.User.Ident ity.Name

-- bruce (sqlwork.com)

shapper wrote:
Hello,

I know that only authenticated users has a UserName. In Anonymous
users there is an ID.

If I am not wrong when getting a profile of a user, if the user is
authenticated the UserName is used. If it is anonymous it is used its
ID that is also stored on a cookie.

What is the correct way to get the UserName or Anonymous user ID of
the current user?

I am using:

HttpContext.Cur rent.Profile.Us erName

Is this the correct way?

Thanks,

Miguel
Nov 15 '08 #2
On Nov 15, 6:40*pm, bruce barker <nos...@nospam. comwrote:
it depends on usage. Profile.UserNam e is the username of the profile
(should match the authenticated username if not anonymous). if you are
using the username for security, don't use profile, use:

* * * * HttpContext.Cur rent.User.Ident ity.Name

-- bruce (sqlwork.com)

shapper wrote:
Hello,
I know that only authenticated users has a UserName. In Anonymous
users there is an ID.
If I am not wrong when getting a profile of a user, if the user is
authenticated the UserName is used. If it is anonymous it is used its
ID that is also stored on a cookie.
What is the correct way to get the UserName or Anonymous user ID of
the current user?
I am using:
HttpContext.Cur rent.Profile.Us erName
Is this the correct way?
Thanks,
Miguel
Basically, I have a class that ihnerits from ProfileBase and creates a
custom Profile provider. To get the current user profile I have at the
moment the following:

public static ProfileHelper GetProfile() {
return Create(HttpCont ext.Current.Pro file.UserName) as
ProfileHelper;
}

This is working. If the user is authenticated
HttpContext.Cur rent.Profile.Us erName returns the username. If it is
anonymous it returns the AnonymousID.

Would you do it differently?

I tested the following:

In MVC Controller:

// I get the username if authenticated and the id if anonymous
string a = HttpContext.Pro file.UserName;
// I get always the id either authenticated or anonymous
string b = HttpContext.Req uest.AnonymousI D;
// I get the username if authenticated or "" if anonymous
string c = HttpContext.Use r.Identity.Name ;
// I get the user if authenticated or null if anonymous
MembershipUser u = Membership.GetU ser();

In Class:

// I get the username if authenticated and the id if anonymous
string a = HttpContext.Cur rent.Profile.Us erName;
// I get always the id either authenticated or anonymous
string b = HttpContext.Cur rent.Request.An onymousID;
// I get the username if authenticated or "" if anonymous
string c = HttpContext.Cur rent.User.Ident ity.Name;
// I get the user if authenticated or null if anonymous
MembershipUser u = Membership.GetU ser();

What I am using is working ... I am just not sure if it is the best
way so I am testing other options.

Thanks,
Miguel
Nov 15 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
2800
by: Candice | last post by:
Please somebody help! I've deleted my admin username and password which was initially set at test. Now I can't log into my website as the administrator. How do I put Username and Password back so that I can set my own password and username again, log in to my website and edit it. Which file do I have to edit, and where do I re-set the Username and Password? --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system...
11
4883
by: Ghazan Haider | last post by:
I am posting this for the lack of a better newsgroup, and for the knowledge of people here, and because its only partially OT. We have a bunch of users with their computers at work. There are reports that the users need, which could be in html, php, asp, jsp, whatever. Now I am trying to eliminate the login window entirely. In an html request, the client (firefox, ie, etc) sends the clients hostname, IP, a bunch of other stuff, but...
14
2555
by: Brent Burkart | last post by:
I am trying to capture the Windows Authenticated username, but I want to be able to capture the login name that exists in IIS, not Windows. In order to enter my company's intranet through the internet, they have to login. I want to be able to capture that login versus their Windows login because I need to know who they are from any computer rather than only their computer. Any ideas? Thanks
8
6753
by: Philip Wagenaar | last post by:
I need to send printjobs to a printqueue under diffrent usernames. The printsoftware on the queue is not very 'secure' so I can create a user on 1 system and send a printjob under it's name to the printqueue. This is why I created a program that picks the username out for the .PRN file, creates a local user, copies the PRN file the network printer and deletes the user. I cannot get it to work. I tried first copying a normal text file...
0
1892
by: Sid DeLuca | last post by:
I'm modifying the WSE2 HOL sample to develop my web service. I'm able to get the client application's username token encrypted on the way out (outputTrace.webinfo), but not on receipt from the server (inputTrace.webinfo). The HOL manual mentions adding the wse:UsernameToken() to the policyCache.config on the client, but not on the server. I have tried adding this to the <confidentiality> section on the server but it still shows the...
5
3781
by: libra786 | last post by:
I have created a blog and have added a login box which prompts the user for login and id before posting- The username and password have been stored in the database, however when i enter the username and pasword it does not seem to compare the values entered with anything. It jus keeps giving the prompt box to enter details. But if i click cancel, then it tels me the incorrect credentials ave been entered i have tried many ways to solve this...
0
8335
by: roamnet | last post by:
hi i created database file with .mdf extention ,sql server as a source and use grid view to display data there're no problem in data retrieve and display,but i want to edit it or insert new records there is an error "Incorrect syntax near '-'. Must declare the scalar variable "@UserName". I worked out in design view,code is automatically generated.Iam not able fix the error. Iam working with Visual Web Developer-2005 Express Edition
4
2033
nathj
by: nathj | last post by:
Hi, I'm working on a registration form and one of the checks I need to perform as the form is used is on the username. I need to ensure that it is not already in use. I am getting a little stuck. Here's the code involved (sorry there's quite a bit) and then I'll explain the problem. HTML (relevant sample) <div class="row"> <span class="label" id="usernamelabel"> <span class="warninglabel">Username:</span> </span>
24
2994
by: runway27 | last post by:
i have used the following code to validate the username it is working fineif( $username == "" || !preg_match("/^+(?:_+)?$/i", $username) ) { $error.="User name cannot be blank or has special characters"; } it does not accept UNDERSCORE at the beginning or end however while i was testing with different special characters except for # the validation works fine for all other special characters. for example if i enter the user name as =...
0
9727
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9605
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10647
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
7669
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6889
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5554
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4339
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3865
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3017
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.