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

Mas*_*oda 10 html c# asp.net

现在我有一个文件夹,里面有另一个文件夹.这两个文件夹名称称为"pc details"和"pchardwaredetails"

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

另外,请随时解释路径是如何工作的,所以我知道将来

谢谢

Llo*_*oyd 22

通常Referrer页面(HTTP标题)告诉你你来自哪个页面,所以回去你应该能够:

Response.Redirect(Request.UrlReferrer.ToString());
Run Code Online (Sandbox Code Playgroud)

这是假设你came来自PC Details.但是,如果您从某个其他页面land开启PC Hardware Details然后无效,则必须对后端功能进行硬编码.

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

Response.Redirect("~/some/path/pc_details.aspx");
Run Code Online (Sandbox Code Playgroud)

  • @ user2500842是的,如果你来自其他页面,那将无效,你必须硬编码后面的功能才能转到你想要的页面. (2认同)