【问题标题】:Response.Redirect continues to go to old URLResponse.Redirect 继续转到旧 URL
【发布时间】:2013-09-10 16:58:15
【问题描述】:

我正在使用由其他人编写的现有 ASP.net C# webapp,我们必须更改主文件的位置。这是一个地址库,当他们点击一个名字时,它会将他们带到个人资料页面。

个人资料页面位置没有改变,但旧的 response.redirect 是使用虚拟路径编写的。 当我将虚拟路径更改为绝对路径时,webapp 不会确认更改并继续重定向到旧路径,从而导致 404 错误。

这是 .aspx 中的 LinkBut​​ton 代码

<ItemTemplate>
                            <asp:LinkButton ID="LinkButton1" CommandName="viewProfile" CommandArgument="<%# ((GridViewRow) Container).RowIndex %>"  runat="server"><%# (Eval("EmpName"))%> </asp:LinkButton>
                        </ItemTemplate>

这里是aspx.cs的块

 protected void gvFinder_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "viewProfile")
            {
                int index = Convert.ToInt32(e.CommandArgument);
                Session["EmployeeId"] = gvFinder.DataKeys[index].Value.ToString();

                string name = gvFinder.Rows[index].Cells[0].Text;

                string y = gvFinder.DataSourceID;

                Response.Redirect("Profile");
            }
        }

这是我将其更改为的,但没有导致更改。

 protected void gvFinder_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "viewProfile")
            {
                int index = Convert.ToInt32(e.CommandArgument);
                Session["EmployeeId"] = gvFinder.DataKeys[index].Value.ToString();

                string name = gvFinder.Rows[index].Cells[0].Text;

                string y = gvFinder.DataSourceID;

                Response.Redirect("http://www.ourwebsite.com/Profile");
            }
        }

有没有人熟悉如何让它真正转到旧网址?

【问题讨论】:

  • 您是否检查过其中是否涉及一些 http 处理程序,可能是他们正在重定向到旧路径。
  • 唯一的 http 处理程序是 IIS 在启动应用程序时自动生成的。
  • 可以安全地假设http://www.ourwebsite.com 与您调用它的网站不同吗?否则路径(Profile 部分)会让你回到你开始的地方。
  • 试试 "~/Profile" o "../Profile"
  • 我建议使用 Fiddler 检查正在发出的请求和响应。您也许可以在标题中嗅出一只老鼠。

标签: c# asp.net response.redirect


【解决方案1】:

有多种选择 1.http://www.ourwebsite.com/Profile不可用、离线或过期 2.如果你有源为什么不把profile.aspx放在你的项目根目录中,如果你想保存旧文件,你可以将它重命名为porfileold.aspx,在这种情况下你不需要更改url,只需重新部署就可以了

【讨论】:

    猜你喜欢
    • 2020-07-21
    • 2013-10-16
    • 2021-01-08
    • 1970-01-01
    • 1970-01-01
    • 2021-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多