0

它不断将图像保存到本地目录或根本不保存。它没有给我任何错误。据我所知,我的本地驱动器和主机之间没有关系。我所有的页面都在主机上,它们工作正常。但在创建此页面之前,我将 bin 目录文件(AjaxControlToolkit.dll、Site.dll、site.pdb)从本地主机导入到 Web 服务器。

源文件:

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolderIcerik" runat="server">
  <asp:ToolkitScriptManager runat="server"></asp:ToolkitScriptManager>

  <asp:AjaxFileUpload ID="AjaxFileUploadResimEkle" runat="server"  
    AllowedFileTypes="jpg,jpeg" 
    onuploadcomplete="AjaxFileUploadResimEkle_UploadComplete" />
</asp:Content

>

代码隐藏:

    protected void AjaxFileUploadResimEkle_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
        {
          int PostID = Convert.ToInt32(Request.QueryString["PostID"]);
          var makale = (from p in db.Posts
                        where p.PostID == PostID
                        select new { p.PostID, p.Title }).Single();

          string uzanti = Path.GetExtension(e.FileName);
          if (e.ContentType.Contains("image"))
          {
            if (e.FileSize <41943040)
            {
              Guid benzersiz = Guid.NewGuid();

              string filePath =string.Format("~/images/blog/large_image/{0}_{1}{2}", makale.Title, benzersiz,uzanti);

              AjaxFileUploadResimEkle.SaveAs(Server.MapPath(filePath));

              System.Drawing.Image degisecekResim = System.Drawing.Image.FromFile(filePath));

              Bitmap kucukResim = ResimKucult(degisecekResim);
              string kucukResimYolu = string.Format("~/images/blog/medium_image/{0}_{1}{2}", makale.Title, benzersiz,uzanti);
              kucukResim.Save(Server.MapPath(kucukResimYolu));

              Resimler resim = new Resimler();

              resim.PostID = PostID;
              resim.FileName = filePath;
              resim.SmallFileName = kucukResimYolu;
              resim.IsActive = true;
              db.Resimlers.AddObject(resim);
              db.SaveChanges();

            }
          }
        }

    Bitmap ResimKucult(System.Drawing.Image resim)
    {
      int x = 225;
      int y = 165;

      Bitmap bmpOrji = new Bitmap(resim);
      if (bmpOrji.Width > bmpOrji.Height)
      {
        y = bmpOrji.Height * x / bmpOrji.Width;
      }
      else if (bmpOrji.Height > bmpOrji.Width)
      {
        x = bmpOrji.Width * y / bmpOrji.Height;
      }

      Bitmap yeniBmp = new Bitmap(bmpOrji, x, y);

      return yeniBmp;
    }

  }
4

1 回答 1

0

问题出在域主机的文件夹选项上。当我授予文件夹写入权限时,问题就解决了。

我不知道我的主机有那种文件夹选项系统,默认情况下所有文件夹都是只读的。

在像我一样弄乱你的 asp 页面之前,最好先检查主机。

于 2013-02-01T23:27:49.633 回答