我有一个用于批量电子邮件服务的Web应用程序。现在,某些表格可以访问我的其他文件夹,其中包含用于发送电子邮件的图像。根文件夹mail1.aspx可以从Web peoject文件夹图像访问图像。我的app_code文件夹为何无法访问此图像文件,但出现对象引用错误。
这是我的app_code文件代码:
if (fbody.Contains("src='cid:"))
{
var htmlView = AlternateView.CreateAlternateViewFromString(msg.Body, null, "text/html");
do
{
int src = fbody.IndexOf("src='cid:");
if (src != -1)
{
fbody = fbody.Remove(0, src + 9);
var dot = Regex.Match(fbody, @"\.(jpg|jpeg|gif|png)");
if (dot.Success)
{
int comma = fbody.IndexOf("'");
if (comma != -1)
{
if (!string.IsNullOrEmpty(fbody.Substring(0, comma)))
{
string imageSource = (HttpContext.Current.Server.MapPath("~/EmailImages/") + fbody.Substring(0, comma));
var leftImageLink = (dynamic)null;
switch (Path.GetExtension(imageSource).ToLower())
{
case ".jpg":
leftImageLink = new LinkedResource(imageSource, "image/jpg")
{
ContentId = fbody.Substring(0, comma),
TransferEncoding = System.Net.Mime.TransferEncoding.Base64
};
break;
case ".jpeg":
leftImageLink = new LinkedResource(imageSource, "image/jpeg")
{
ContentId = fbody.Substring(0, comma),
TransferEncoding = System.Net.Mime.TransferEncoding.Base64
};
break;
case ".gif":
leftImageLink = new LinkedResource(imageSource, "image/gif")
{
ContentId = fbody.Substring(0, comma),
TransferEncoding = System.Net.Mime.TransferEncoding.Base64
};
break;
case ".png":
leftImageLink = new LinkedResource(imageSource, "image/png")
{
ContentId = fbody.Substring(0, comma),
TransferEncoding = System.Net.Mime.TransferEncoding.Base64
};
break;
}
htmlView.LinkedResources.Add(leftImageLink);
}
}
}
}
}
while (fbody.Contains("src='cid:"));
msg.AlternateViews.Add(htmlView);
此处imagesource无法访问其他Web应用程序文件夹图像。这里出了什么问题..