正确的方法来执行Response.Redirect从一页重定向到同一站点上的另一页 [英] Correct way to do a Response.Redirect from one page to another on the same site

查看:107
本文介绍了正确的方法来执行Response.Redirect从一页重定向到同一站点上的另一页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我确定这是一次又一次地被问到.是的,我已经搜索过.但是,我找不到能清楚说明我要完成的目标的例子.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆