how to be redirected to the previous page using response.redirect() in asp.net c#

Right now i have a folder with another folder inside of it. The two folder names are called “pc details” and “pchardwaredetails”

When on a page in “pchardwaredetails” i want to return to a page in “pc details” using a button and response.redirect() but the file paths are just getting too complicated for me. What might the file path be from a page called “Details” in “pchardwaredetails” to a page called “viewMore” in “pc details”?

Also please feel free to explain how paths work so i know for future

thanks

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Usually the Referrer of the page (a HTTP header), tells you what page you’ve come from so to go back you should just be able to do:

Response.Redirect(Request.UrlReferrer.ToString());

That’s assuming you came from PC Details. However if you land on PC Hardware Details from some other page then that won’t work, you would have to hard code the back feature.

You can simplify ASP.NET paths and use ~, for example:

Response.Redirect("~/some/path/pc_details.aspx");


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x