【发布时间】:2012-07-05 14:56:43
【问题描述】:
我遇到了一个 VS 2010 问题。
假设我在网站 MyWebSite 中有一个页面 MyPage.aspx,其虚拟路径为 MyWebSitePath。
当我将调用重定向到另一个页面 MyPage1.aspx 时,我的虚拟路径加倍,我得到 HTTP 错误 400 - 错误请求,这是有道理的,因为我得到的 Url 是 MyWebSite/MyWebSite/MyPage1.aspx。
我用Response.Redirect("~/MyPage1.aspx",true);
我已经尝试过使用重定向页面的字符串。不是这样的,我猜它可能是在某个地方的 SLN 文件中,但我真的不知道。
一个变味的代码示例:
/// <summary>
/// Play audio file using response.redirect, can throw
/// </summary>
/// <param name="response">used to redirect to the created file path</param>
/// <param name="filePath"></param>
/// <param name="fileName"></param>
public static void PlayAudioFile(Page page, string filePath, string fileName)
{
const string TempFolder ="tmp";
string newPath = page.Server.MapPath(TempFolder);
string newFileName = Guid.NewGuid().ToString() + fileName;
System.IO.File.Copy(filePath +"\\" + fileName, newPath+"\\" + newFileName,true);
page.Response.Redirect(TempFolder + "\\" + newFileName);
}
提前致谢, 尤瓦尔
【问题讨论】:
-
这就是你使用的全部代码?请显示实际代码,而不是伪代码,因为这肯定不是标准行为。
-
究竟是哪一行引发了这个错误?
-
来吧,不要害羞....给我们看代码....
-
不,你会取笑我的(这甚至不是我的代码!)。开玩笑,没什么可显示的。确实是这个 response.redirect 造成了麻烦。我将编辑一个以它为例的函数。
标签: asp.net http-error virtual-path