【发布时间】:2013-09-10 16:58:15
【问题描述】:
我正在使用由其他人编写的现有 ASP.net C# webapp,我们必须更改主文件的位置。这是一个地址库,当他们点击一个名字时,它会将他们带到个人资料页面。
个人资料页面位置没有改变,但旧的 response.redirect 是使用虚拟路径编写的。 当我将虚拟路径更改为绝对路径时,webapp 不会确认更改并继续重定向到旧路径,从而导致 404 错误。
这是 .aspx 中的 LinkButton 代码
<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