Rayz.com

Welcome to Rayz.com

WebConfig

Here is a chunk of an old web config file:

<?xml version=”1.0″?>
<!– eFormsAdmin 2.2.3 web.config –>
<configuration>
<appSettings>
<add key=”IsProductionServerYN” value=”N” />
<add key=”ReleaseDate” value=”01/03/2014″ />
<add key=”WebRoot” value=”http://avsaacokcd35/eformsAdmin/” />
</appSettings>

<connectionStrings configSource=”cs.config” />
<system.net>
<mailSettings>
<smtp>
<network host=”mailrelay.rayz.com” port=”25″ userName=”” password=”” defaultCredentials=”true” />
</smtp>
</mailSettings>
</system.net>
<system.web>
<customErrors mode=”RemoteOnly” defaultRedirect=”SystemError.aspx”></customErrors>
<authorization>
<allow users=”*” />
</authorization>
</system.web>
</configuration>

Here is the Connection string config file:

<connectionStrings>
<!– SQL connection strings –>
<add name=”DbConn” providerName=”System.Data.SqlClient” connectionString=”Data Source=SQLserver_Name; Database=Database_Name; user id=db_User; password=userPW; Connection Timeout=180;” />
</connectionStrings>

And now a chunk of my famous Apple Pie – oops… config.cs excerpt:

using System;
using System.Collections;
using System.Configuration;
using System.IO;
using System.Text;
using System.Reflection;
namespace name_space
{
[Serializable]
public class Config
{
#region private members
private static bool isValid = false;
private static bool hasBeenRead = false;
private static string dbConn = string.Empty;
private static string version = string.Empty;
private static string runtimeVer = string.Empty;
private static string releaseDate = string.Empty;
#endregion

#region constructor
static Config()
{
if(!hasBeenRead)
{
ReadConfigFile();
Assembly exe = Assembly.GetExecutingAssembly();
version = exe.FullName.Split(‘,’)[1].Replace(“=”,”: “);
runtimeVer = exe.ImageRuntimeVersion;
}
#endregion

#region private methods
private static void ReadConfigFile()
{
confFileValid=true;
try
{
releaseDate = ConfigurationManager.AppSettings.Get(“ReleaseDate”);
}
catch
{
confFileValid = false;
}

// WebRoot
try
{
webRoot = ConfigurationManager.AppSettings.Get(“WebRoot”); // .net 2.0

//webRoot = ConfigurationSettings.AppSettings.Get(“WebRoot”); // .net 1.1
}
catch
{
loc=1;
webRoot = string.Empty;
confFileValid=false;
}

try
{
string myYN = ConfigurationManager.AppSettings.Get(“FormManagerButton”);
formManagerButton = TF(myYN);
}
catch
{
formManagerButton = false;
}
dbConn = ConfigurationManager.ConnectionStrings[“DbConn”].ConnectionString;

//confFileValid=false;
// /////////////////////// //

hasBeenRead=true;
if(!confFileValid)
{
string msg = Global.url + “\n”+Global.webConfigPath +
“\neFormsAdmin: Problem found with config file – (” + loc.ToString() + “)”;
SendMail.ErrorLog(msg);
SendMail.Send(msg);
}
}

private static bool TF(string yn)
{
if (yn == null) { yn = “n”; }
yn = onOff(yn);
return !(“+yt1”.IndexOf(yn.ToLower().Substring(0, 1)) < 0); } #endregion #region properties #endregion } }