在同一站点上执行 Response.Redirect 从一个页面到另一个页面的正确方法 [英] Correct way to do a Response.Redirect from one page to another on the same site
问题描述
我确定这已经被问过一次又一次.是的,我已经搜索过了.但是,我无法找到一个示例来清楚地展示我想要实现的目标.
I'm sure this has been asked time and time again. And yes I've searched. However, I'm unable to find an example that clearly demonstrates what I'm looking to accomplish.
我目前在 mywebsite/test.aspx
,我想重定向到 mywebsite/testing.aspx
.但是,我希望此重定向在服务器上和 Visual Studio 的调试中都能正常工作.我试过了
I'm currently on mywebsite/test.aspx
, I want to Redirect to mywebsite/testing.aspx
. However I want this redirect to work both live on server and within debug of visual studio. I've tried
Response.Redirect(Request.RawUrl.Replace(Request.RawUrl,"testing.aspx"))
然而,这取代了整个事情.
However this replaces the whole thing.
希望这是有道理的 - mywebsite/test.aspx
应该重定向到 mywebsite/testing.aspx
Hope this makes sense - mywebsite/test.aspx
should redirect to mywebsite/testing.aspx
推荐答案
使用应用程序相对 url.~/
表示应用程序根路径,因此它适用于 /
和 /virtual-directory/
.
Use application relative urls. ~/
represents the application root path, so it will work for both /
and /virtual-directory/
.
Response.Redirect("~/testing.aspx");
这篇关于在同一站点上执行 Response.Redirect 从一个页面到另一个页面的正确方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!