有人能告诉我这段代码有什么问题吗?我正在尝试使用这段代码上传一个mp3,当我尝试这样做时,我得到一个“Internet Explorer无法显示网页”
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="upload" runat="server" Text="GO" OnClick="btn_Click" /><br /><br />
<asp:Label ID="Label1" runat="server"></asp:Label>
<script runat="server">
protected void btn_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
string fileExt =
System.IO.Path.GetExtension(FileUpload1.FileName);
if (fileExt == ".mp3")
{
try
{
FileUpload1.SaveAs(Server.MapPath("~/Uploads/" +
FileUpload1.FileName));
Label1.Text = "File name: " +
FileUpload1.PostedFile.FileName + "<br>" +
FileUpload1.PostedFile.ContentLength + " kb<br>" +
"Content type: " +
FileUpload1.PostedFile.ContentType;
}
catch (Exception ex)
{
Label1.Text = "ERROR: " + ex.Message.ToString();
}
}
else
{
Label1.Text = "Only .mp3 files allowed!";
}
}
else
{
Label1.Text = "You have not specified a file.";
}
}
</script>
答案 0 :(得分:6)
使用web.config中的以下内容增加http maxRequestLength - 它应该可以正常工作。默认情况下它限制在4mb。
<system.web>
<httpRuntime executionTimeout="240" maxRequestLength="20480" />
</system.web>