0
我刚刚将我的c#web应用程序部署到了Windows Azure。图片上传在我的本地机器上正常工作,但是现在网站已经部署了,图片上传不能和Azure存储一起使用。我刚收到一条错误消息,说Error. An error occurred while processing your request.
尝试上载图像时。图片上传无法在Azure存储上工作
任何帮助将不胜感激。
图片上传控制器
public ActionResult Create(UserprofileImage userprofileimage, HttpPostedFileBase file)
{
if (ModelState.IsValid)
{
if (file != null)
{
var manager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()));
var currentUser = manager.FindById(User.Identity.GetUserId());
file.SaveAs(HttpContext.Server.MapPath("~/Images/")
+ file.FileName);
userprofileimage.userImagePath = file.FileName;
userprofileimage.UserId = currentUser.Id;
userprofileimage.current = 1;
db.UserprofileImages.Add(userprofileimage);
db.SaveChanges();
var userimage = db.UserprofileImages.Where(u => u.UserId == currentUser.Id && u.Id != userprofileimage.Id).ToList();
foreach(var item in userimage)
{
item.Id = 0;
db.SaveChanges();
}
return RedirectToAction("Index", "Profile");
}
}
return View(userprofileimage);
}
**图片上传HTML **
@using (Html.BeginForm("Create", "UserprofileImage", null, FormMethod.Post,
new { enctype = "multipart/form-data" }))
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<hr />
@Html.ValidationSummary(true)
<div class="form-group">
<div class="control-label col-md-2">
Profile Image
</div>
<div class="col-md-10">
<input id="userImagePath" title="Upload a profile picture"
type="file" name="file" />
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</div>
</div>
}
请指出您是将这部署到Azure网站,Azure虚拟机还是Azure云服务。 – MikeWo
我正在部署到Azure云服务 – Dolaps
您是否有写入磁盘的权限?你不应该将这些文件存储在blob存储中吗? –