也许是一个简单的问题,但我真的不知道该怎么做。
当我通过表单提交文件时<asp:FileUpload>
,它在我的开发机器上完美运行。
当我在服务器上尝试同样的事情时,它给了我下面的错误。该错误根本没有帮助我,因为我的代码(CaptureCollection)中什至没有这个函数,而且我没有一个名为“i”的变量。所以现在,我真的不知道。
这是服务器上的权利问题吗(我不这么认为,因为我赋予了所有可能的权利并且错误仍然存在),它是否在我的代码上(但它在我的开发机器上工作......)。如果您需要,我可以显示更多代码!
错误:
“/”应用程序中的服务器错误。 -------------------------------------------------- ------------------------------ 指定的参数超出了有效值的范围。 参数名称:i 说明:执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。 异常详细信息:System.ArgumentOutOfRangeException:指定的参数超出了有效值的范围。 参数名称:i 源错误: 在执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪来识别有关异常起源和位置的信息。 堆栈跟踪: [ArgumentOutOfRangeException:指定的参数超出了有效值的范围。 参数名称:i] System.Text.RegularExpressions.CaptureCollection.GetCapture(Int32 i) +5227599 System.Text.RegularExpressions.CaptureCollection.get_Item(Int32 i) +4 CreatePost.btnFinish_Click(Object sender, EventArgs e) +143 System.EventHandler.Invoke(对象发送者,EventArgs e)+0 System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111 System.Web.UI.WebControls.Button.RaisePostBackEvent(字符串 eventArgument)+110 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(字符串 eventArgument)+10 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36 System.Web.UI.Page.ProcessRequestMain(布尔 includeStagesBeforeAsyncPoint,布尔 includeStagesAfterAsyncPoint)+1565
这是执行上传的代码。也许你对正则表达式是正确的。但是为什么它在 dev 而不是 prod 上工作?
protected void btnFinish_Click(object sender, EventArgs e)
{
string file = "";
string csFinalPath = "";
if (uploadPhoto.HasFile)
{
string filepath = uploadPhoto.PostedFile.FileName;
string pat = @"\\(?:.+)\\(.+)\.(.+)";
Regex r = new Regex(pat);
//run
Match m = r.Match(filepath);
string file_ext = m.Groups[2].Captures[0].ToString();
string filename = m.Groups[1].Captures[0].ToString();
file = filename + "." + file_ext;
//save the file to the server
uploadPhoto.PostedFile.SaveAs(Server.MapPath(".\\upload\\") + file);
ThumbnailGenerator thumbGenerator = new ThumbnailGenerator();
if (thumbGenerator.GetThumbnail(Server.MapPath(".\\upload\\") + file,
Server.MapPath(".\\upload\\thumb\\") + "Thumb" + file))
{
csFinalPath = "./upload/thumb/" + "Thumb" + file;
}
else
{
//TODO: Do an error message!!!
}
}
else
{
csFinalPath = "./images/no_image.gif";
}
m_database.InsertPost(Convert.ToInt32(Session["ID"].ToString()),
Convert.ToInt32(ddlCategory.SelectedValue),
m_nType,
txtLink.Text,
txtTitreFR.Text,
txtTitreEN.Text,
txtDescriptionFR.Text,
txtDescriptionEN.Text,
csFinalPath,
"",
"");
panelLink.Visible = false;
panelResult.Visible = true;
}