【问题标题】:Virtual path duplicated in Response.Redirect in ASP.NET under Visual Studio 2010Visual Studio 2010 下 ASP.NET 中的 Response.Redirect 中重复的虚拟路径
【发布时间】: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


【解决方案1】:

花了很长时间,但我终于弄清楚了问题所在。 问题是这个小虫子(明白吗?虫子?):

 asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"          
 EnableScriptGlobalization="true"
        EnableScriptLocalization="true"
 /asp:ToolkitScriptManager>

当我将它切换到标准时,一切都开始工作了。 不幸的是,我忽略了说这个项目是建立在一个旧项目之上的,该项目是从 VS2008 迁移到 VS2010 的,以及它的所有二进制文件。我没有彻底研究过,但这似乎是由于使用了不合适的 Ajax Control Toolkit 版本造成的。我的项目是.Net 4.0,工具包是3.5。

感谢您的所有时间, 尤瓦尔。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-06
    相关资源
    最近更新 更多