开发者

asp.net way to last URL from codebehind

开发者 https://www.devze.com 2023-01-31 21:04 出处:网络
is there a way from a asp.net-pa开发者_如何学Goge code behind with \"Request.Redirect()\" or another method to redirect to the last page (like Javascript history back)?You can check the Request.UrlRef

is there a way from a asp.net-pa开发者_如何学Goge code behind with "Request.Redirect()" or another method to redirect to the last page (like Javascript history back)?


You can check the Request.UrlReferrer property, which will be set if the user has navigated to the given page from another one. This is nothing more than the HTTP Referrer header that a browser will set. This will be null if the user navigates to your page directly.


HTTP is stateless, so theres no way of being able to read the browsers history (on the server) in the same way that Javascript can (its client side).

However there are a couple of tricks you can use:

  • Javascript could write the URL into a textbox which gets submitted to the server
  • The last URL visited could be stored in session - which can be retreived on a later visit

If using the URL in session method, you'll probably want to code this into a HTTP handler (not module) and this will fire automatically on every request.

Obviously these will only work if the user has previously visited a page, and not directly.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号