【发布时间】:2014-09-22 19:02:01
【问题描述】:
我有一个小型 MVC 5 应用程序,关键是它在我的 localhost 中运行良好,但是当我将它发布到 Azure 时,某些部分无法运行。例如,我的观点是这样的:
<div class="form-group">
<div style="position:relative;">
<label>Image</label>
<a class="btn" href="javascript:;">
Choose a file...
<input type="file" name="Image" accept="image/jpeg, image/png"
style="position:absolute;z-index:2;top:0;left:0;filter: alpha(opacity=0); opacity:0;background-color:transparent;color:transparent;"
onchange='$("#upload-image-info").html($(this).val());' />
</a>
<span class="label label-info" id="upload-image-info"></span>
</div>
</div>
那么,在我的服务器端我有这样的东西:
public ActionResult ServiceRequest(RequestViewModel rvm, HttpPostedFileBase image = null, HttpPostedFileBase video = null)
{
tmpPicturePath = Server.MapPath("~/App_Data/Uploads/Images");
tmpVideoPath = Server.MapPath("~/App_Data/Uploads/Videos");
// I check for some properties, and then save the file
filename = Path.GetFileName(image.FileName);
imagePath = Path.Combine(tmpPicturePath, filename);
image.SaveAs(imagePath);
// Afterwards, I give the imagePath to SendGrid for attachment to a mail
message.AddAttachment(imagePath);
// And later in code, I send the mail
transportWeb.Deliver(message);
}
请注意,我省略了上面代码的某些部分,以便更清楚地说明我想要做什么。关键是,在我的本地主机中,它工作正常,我可以选择一个文件并在上传后通过电子邮件发送它。但是,当我在 Azure 上发布网站并尝试相同的操作时,当我按下按钮时,它似乎正在上传文件,但之后我收到一条错误消息:
错误。处理您的请求时出错。
我不知道它是否无法将文件存储在服务器上,或者之后无法读取它们作为附件,或者无法发送邮件。知道问题可能是什么吗?
【问题讨论】:
-
Azure 是一个云平台。当您部署到其中一台 azure 服务器时,您不能保证它会保留在同一台服务器上。如果文件不是您的发布包的一部分,例如用户将文件上传到您的站点,那么如果您的站点移动到另一台服务器,它可以/可能/将被删除。综上所述,您确实应该使用 Azure Blob 存储来保存上传到您网站的文件,因为本地存储不是永久性的。更多信息 - azure.microsoft.com/en-us/services/storage
标签: asp.net-mvc azure sendgrid