ASP.NET - redirecting responses to different folders

I am trying to redirect gridview to a selection. However, I am oversaturated when the page I'm trying to redirect is in a different folder.

The grid view is located in a folder named HR. I am trying to redirect this to a file called "Personnel" in the "Personnel" folder. How can I redirect to another folder?

If e.CommandName = "Select" Then 'Add to session variable; translate the index of clicked to Primary Key Session.Add("DetailsKey", GridView1.DataKeys(e.CommandArgument).Value.ToString) Response.Redirect("staff\staff.aspx") End If 
+4
source share
3 answers
 Response.Redirect("~/staff/staff.aspx") 
+11
source

The main thing is to use / rather than \ . You are not redirected to the folder on the server, but to the path on the website (the fact that this means that the folder on your server is just an implementation detail).

You can use all forms that you can use with relative links. Therefore, "staff/staff.aspx" goes to a file called staff.aspx in a folder called staff, which is in the current folder (assuming that your system is based on a folder and a file). "../staff/staff.aspx" goes up the folder, and then to staff, then to staff.aspx. "../../staff/staff.aspx" goes up the first two. "/staff/staff.aspx" goes to the root of the domain at ( http://mysite.com/staff/staff.aspx , etc.).

Like all of them, "~/staff/staff.aspx" goes to the root of the application, and then to the staff inside it, and then to staff.aspx. This is useful if you work on the site in such a way that it is at http://localhost/currentProject/staff/staff.aspx , because the project is located at http://localhost/currentProject/ , but deployed to http://mysite.com/staff/staff.aspx since the site is located at http://mysite.com/ . Thus, the same code works in both directions.

+6
source

That should do the trick

 Response.Redirect("~/staff/staff.aspx"); 
+3
source

Source: https://habr.com/ru/post/1386177/


All Articles