【发布时间】:2015-08-29 03:49:44
【问题描述】:
我正在使用IIS 6.2,我的解决方案有一个file-upload 控件并尝试上传一堆images,但我收到了这个错误。我在互联网上搜索了很多解决方案,但没有一个工作。
我已应用 maxAllowedContentLength="1073741824" 但仍然遇到同样的错误。
protected void lnkbtnUpload_Click(object sender, EventArgs e)
{
try
{
foreach (HttpPostedFile objHttpPostedFile in fuUpload.PostedFiles)
{
string FileName = objHttpPostedFile.FileName;
string FileType = objHttpPostedFile.ContentType;
Stream fs = objHttpPostedFile.InputStream;
BinaryReader br = new BinaryReader(fs);
Byte[] bytes = br.ReadBytes((Int32)fs.Length);
using (SqlConnection con = new SqlConnection(ConnectionString))
{
con.Open();
SqlCommand cmd = new SqlCommand("uspInsertImage", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("Filename", SqlDbType.NVarChar).Value = FileName;
cmd.Parameters.Add("FileType", SqlDbType.NVarChar).Value = FileType;
cmd.Parameters.Add("ImageStream", SqlDbType.VarBinary).Value = bytes;
cmd.Parameters.Add("DateCreated", SqlDbType.DateTime).Value = DateTime.Now;
int i = cmd.ExecuteNonQuery();
con.Close();
}
BindImage();
}
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
}
我的 Web.Config 文件
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="4073741824" />
</requestFiltering>
</security>
【问题讨论】:
-
发布您的代码会有所帮助。
标签: c# asp.net visual-studio-2010 iis file-upload