我有这个代码,它从数据库中读取数据,然后将web.config文件中的url分配给字符串。
bool isRequestCI = false;
if (context.Request.QueryString["RequestCI"] != null)
{
isRequestCI = Convert.ToBoolean(context.Request.QueryString["RequestCI"].ToString());
}
string GetFileInfo;
if (isRequestCI)
{
GetFileInfo = "select [FileName],FileExtension,MD5Hash from ElementCIBinaryAttachments where CIBinaryFileID = " + binaryFileID;
}
else
GetFileInfo = "select [FileName],FileExtension,MD5Hash from CaseFileBinaryAttachments where BinaryFileID = " + binaryFileID;
SqlCommand comGetFileInfo = new SqlCommand(GetFileInfo, cnGetFile);
SqlDataReader drFileInfo;
cnGetFile.Open();
drFileInfo = comGetFileInfo.ExecuteReader();
string fileName = "";
string fileExtension = "";
string MD5Hash = "";
while (drFileInfo.Read())
{
fileName = drFileInfo["FileName"].ToString().Trim();
fileExtension = drFileInfo["FileExtension"].ToString().Trim();
MD5Hash = drFileInfo["MD5Hash"].ToString().Trim();
}
drFileInfo.Close();
cnGetFile.Close();
string MD5PathRequestCI = ConfigurationManager.AppSettings["CIUploadedFiles"].ToString() + MD5Hash.Substring(0, 3) + @"\" + MD5Hash.Substring(3, 3) + @"\" + MD5Hash.Substring(6, 3) + @"\" + MD5Hash.Substring(9);
然而,它导致string MD5PathRequestCI
处的异常,说“引用未设置为对象的实例,我不知道为什么。我从来没有这样做过,或者我错过了什么?
答案 0 :(得分:2)
ConfigurationManager.AppSettings["CIUploadedFiles"]
返回null。确保配置文件中存在值“CIUploadedFiles”。
答案 1 :(得分:2)
检查web.config文件。确认您的配置部分中有一个带有“CIUploadedFiles”键的appSettings条目。该部分位于根元素内:
<configuration>
<appSettings>
<add key="CIUploadedFiles" value=""/>
</appSettings>
</configuration>