views:

120

answers:

2

I have gotten mixed up in the past with regards to file paths (relative, physical, etc.). With my following project structure:

Solution MySolution
- MyProject
   -MiniApp Folder
     -MiniApp.aspx
   -Default.aspx
   -Default2.aspx

Please provide examples on redirection (ex. Response.Redirect("~/Default.aspx")) navigation from:

  1. Default.aspx to MiniApp.aspx
  2. MiniApp.aspx to Default.aspx
  3. Default.aspx to Default2.aspx

using:

  1. Physical Path
  2. Relative Path
  3. Any additional paths that I've omitted

Thanks!

+3  A: 

you should NOT use physical path to redirect.

~ will resolve to the root of YOUR APPLICATION /MyProject

the code below will redirect to those pages from ANY PAGE

Response.Redirect("~/Default.aspx");
Response.Redirect("~/Default2.aspx");
Response.Redirect("~/MiniApp/MiniApp.aspx");
roman m
A: 

as rm said, never ever use Physcal path for redirect, it is just wrong, you should use it for File I.O operations, any way here is examples of dealing with paths in ASP.net

you can also use Server.MapPath("~/Your RelativePath); to convert to physical path.