Link to home
Start Free TrialLog in
Avatar of metropia
metropiaFlag for United States of America

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:

m_CurrentUser = HttpContext.Current.User.Identity.Name.ToString();
m_CurrentUser = m_CurrentUser.ToUpper().Replace("\\", "").Replace("CompanyDomain", "").ToLower();

Open in new window



Thank you!
ASKER CERTIFIED SOLUTION
Avatar of PaulHews
PaulHews
Flag of Canada 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
SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland 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
Avatar of metropia

ASKER

Is it possible to make the changes using some of the code I have, or do I have to change all that?

Thank you.
SOLUTION
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
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.Identity.Name.ToString();

Thank you.
I have it like:

m_CurrentUser = HttpContext.Current.User.Identity.Name.ToString();
            m_CurrentUser = m_CurrentUser.split("\")(1)

but I get a message: "new line in constant"

I am using C# on VS 2010
SOLUTION
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
awesome! thanks for your help experts!