如何在asp.net c#中使用response.redirect()重定向到上一页

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17339346/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 09:13:42  来源:igfitidea点击:

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

c#htmlasp.net

提问by Master Yoda

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

现在我有一个文件夹,里面有另一个文件夹。这两个文件夹名称分别称为“pc details”和“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"?

在“pchardwaredetails”中的页面上时,我想使用按钮和 response.redirect() 返回“pc 详细信息”中的页面,但文件路径对我来说太复杂了。从“pchardwaredetails”中名为“Details”的页面到“pc details”中名为“viewMore”的页面,文件路径可能是什么?

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

也请随时解释路径如何工作,以便我知道未来

thanks

谢谢

采纳答案by Lloyd

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

通常Referrer页面的(HTTP 标头)会告诉您来自哪个页面,因此返回您应该能够执行以下操作:

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

That's assuming you camefrom PC Details. However if you landon PC Hardware Detailsfrom some other page then that won't work, you would have to hard code the back feature.

那是假设你came来自PC Details. 但是,如果您从其他页面land打开PC Hardware Details,那么这将不起作用,您将不得不对返回功能进行硬编码。

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

您可以简化 ASP.NET 路径并使用~,例如:

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