FYI I spent about 30 minutes searching for the answer. If I missed it on stackoverflow, i'm sorry. This seems like an easy answer, however none of my colleagues know either.
I have am working with an existing library. I'm trying to maintain integration with a current system, while adding the ability to change some hard-coded values. I've refactored the code to utilize the ConfigurationManager so I can use parametrized web deployment.
My question is this.. Why, when I access Constants.CourseMillRegisterURL, I only get back part of the variable? The part that I get back is the piece read from web.config. I expect to get a complete URL containing both variables concat'd but I only get my web.config value "userlogin.jsp".
I've tried also coding it so that the values are concat'd in the privates, but it doesn't work that way either. I really want to stay with static because the whole library refers to this class using code like
string theUrl = Constants.CoursMillUrl + Constants.CourseMillRegisterUrl
Each variable returns the following:
Why are my values not
My code is below.
namespace STTI.CourseMill.Library
{
#region
using System.Configuration;
#endregion
public static class Constants
{
// prod
#region Static Fields
public static string CourseMillRegisterURL = CourseMillURL + courseMillRegisterURL;
public static string CourseMillURL = courseMillURL;
public static string CourseMillUserLoginURL = CourseMillURL + courseMillUserLoginURL;
#endregion
#region Properties
private static string courseMillRegisterURL
{
get
{
string output = ConfigurationManager.AppSettings["CourseMillRegisterUrl"];
if (output == null)
{
output = "sttilogin.jsp?d=t";
}
return output;
}
}
private static string courseMillURL
{
get
{
string output = ConfigurationManager.AppSettings["CourseMillURL"];
if (output == null)
{
output = "http://hardcodedvalue/cm6/cm0670";
}
if (!output.EndsWith("/"))
{
output += "/";
}
return output;
}
}
private static string courseMillUserLoginURL
{
get
{
string output = ConfigurationManager.AppSettings["CourseMillLoginUrl"];
if (output == null)
{
output = "sttilogin.jsp?d=t";
}
return output;
}
}
#endregion
}
}
Static strings are initialised in the order they appear in the file.
courseMillRegisterURL is initialised after CourseMillRegisterURL, for example.
That's why your strings are incomplete.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With