Correct way to do a Response.Redirect from one page to another on the same site

前端 未结 3 546
清歌不尽
清歌不尽 2020-12-31 22:04

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 accomplis

相关标签:
3条回答
  • 2020-12-31 22:09

    If your page is on the same directory level you can just use:

    Response.Redirect("testing.aspx", false);
    

    If your page is on application root you can use following command:

    Response.Redirect("~/testing.aspx", false);
    

    And finally, if you page is inside sub directory from current page you can use:

    Response.Redirect("MyFolder/testing.aspx", false);
    
    0 讨论(0)
  • 2020-12-31 22:18

    You can use url relative to web site root. These urls always start with / which means 'root'

    For Response.Redirect and any other url you know will be processed by server (like url specified in server control) it's better to start url with ~/ as root, this will help with virtual directories mess.

    0 讨论(0)
  • 2020-12-31 22:26

    Use application relative urls. ~/ represents the application root path, so it will work for both / and /virtual-directory/.

    Response.Redirect("~/testing.aspx");
    
    0 讨论(0)
提交回复
热议问题