1

我有一个图片调整大小和图片缩略图工作正常的代码,但它只支持 3MB 的最大文件大小。我想将文件大小限制增加到至少 10 到 12MB。任何人都可以为我做吗?谢谢

   using System;
   using System.Data;
   using System.Configuration;
   using System.Web;
   using System.Web.Security;
   using System.Web.UI;
   using System.Web.UI.WebControls;
   using System.Web.UI.WebControls.WebParts;
   using System.Web.UI.HtmlControls;

   public partial class _Default : System.Web.UI.Page 
   {
    protected void Page_Load(object sender, EventArgs e)
     {
   }


     protected void Upload_Click(object sender, EventArgs e)

    {

   if (FileUpload1.HasFile)

    {

        FileUpload1.SaveAs(MapPath("Image/" + FileUpload1.FileName));

        System.Drawing.Image img1 = System.Drawing.Image.FromFile(MapPath("image/") + FileUpload1.FileName);      

        System.Drawing.Image bmp1 = img1.GetThumbnailImage(50, 50, null, IntPtr.Zero);

        bmp1.Save(MapPath("thumbnail/S/") + FileUpload1.FileName);

        System.Drawing.Image bmp2 = img1.GetThumbnailImage(100, 100, null, IntPtr.Zero);

        bmp2.Save(MapPath("thumbnail/L/") + FileUpload1.FileName);

        NormalImage.ImageUrl = "Image/" + FileUpload1.FileName;
        ThumbnailImageS.ImageUrl = "thumbnail/S/" + FileUpload1.FileName;
        ThumbnailImageM.ImageUrl = "thumbnail/L/" + FileUpload1.FileName;
    }
}
4

2 回答 2

1

检查最大请求长度

指示 ASP.NET 支持的最大文件上传大小。此限制可用于防止因用户向服务器发布大文件而导致的拒绝服务攻击。指定的大小以千字节为单位。默认值为 4096 KB (4 MB)。

于 2012-10-19T11:12:46.943 回答
0

您可以从 web.config 文件中设置文件的最大长度。试试这个代码:

<configuration>
...
<system.web>

<httpRuntime maxRequestLength="102400" executionTimeout="3600" />
...
</system.web>
</configuration>
于 2012-10-19T11:20:16.163 回答