metropia
asked on
how to avoid errors when specifying a domain name in code and then changing it.
hello,
I have a piece of code that retrieves the network user name, the code looks from the domain name to the user name, before it just gets the user name.
recently we went through a rename of our domain name, and I had to change the hard coded domain name in several projects.
I would like to know how to modify the code to avoid this situation in the future.
This is the code I have been using:
Thank you!
I have a piece of code that retrieves the network user name, the code looks from the domain name to the user name, before it just gets the user name.
recently we went through a rename of our domain name, and I had to change the hard coded domain name in several projects.
I would like to know how to modify the code to avoid this situation in the future.
This is the code I have been using:
m_CurrentUser = HttpContext.Current.User.Identity.Name.ToString();
m_CurrentUser = m_CurrentUser.ToUpper().Replace("\\", "").Replace("CompanyDomain", "").ToLower();
Thank you!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I like CodeCruiser's suggestion, but I am not sure how to implement it with my code.
If I use it, do I still need this part:
m_CurrentUser = HttpContext.Current.User.I dentity.Na me.ToStrin g();
Thank you.
If I use it, do I still need this part:
m_CurrentUser = HttpContext.Current.User.I
Thank you.
ASKER
I have it like:
m_CurrentUser = HttpContext.Current.User.I dentity.Na me.ToStrin g();
m_CurrentUser = m_CurrentUser.split("\")(1 )
but I get a message: "new line in constant"
I am using C# on VS 2010
m_CurrentUser = HttpContext.Current.User.I
m_CurrentUser = m_CurrentUser.split("\")(1
but I get a message: "new line in constant"
I am using C# on VS 2010
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
awesome! thanks for your help experts!
ASKER
Thank you.