【问题标题】:fileupload control causing server error文件上传控制导致服务器错误
【发布时间】:2012-07-16 15:34:09
【问题描述】:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

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

}
protected void Button1_Click(object sender, EventArgs e)
{
    String fn = FileUpload1.FileName;
    string fp = Server.MapPath("images");
    if (fp.EndsWith("\\") == false)
    {
        fp = fp + "\\";
    }
    fp = fp + fn;
    FileUpload1.PostedFile.SaveAs(fp);
}
}

在运行此代码时,我收到以下错误:

“/WebSite11”应用程序中的服务器错误
HTTP 错误 400 - 错误请求。
版本信息: ASP.NET 开发服务器 10.0.0.0

【问题讨论】:

  • 在不同的浏览器上运行您的网站。

标签: c# asp.net http file-upload


【解决方案1】:

如果图像文件夹位于您网站的根目录,那么路径应该是这个

string fp = Server.MapPath(~"/images");

几天前我还尝试在不同的浏览器上运行该网站,但我看到了同样的问题,但是当他在不同的浏览器上运行代码时,它工作正常。

看下面的帖子 HTTP Error 400 - Bad Request due to FileUpload control in vb.net

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-07
    • 2014-12-14
    • 1970-01-01
    • 1970-01-01
    • 2015-09-17
    • 2012-06-06
    相关资源
    最近更新 更多