简体   繁体   中英

How can I get the URL of the aspx page from code behind?

How can I get the url of the active aspx page from the code behind so that I can assign it to a string variable?

Does it make a difference in what page-lifecycle stage I call this?

Thanks

if you're on a page:

Request.Url.ToString();

if you are a class library elsewhere

HttpContext.Current.Request.Url.ToString();

Doesn't matter about lifecycle

To Get the path

System.Web.HttpContext.Current.Request.Path

Or you can also do..

 Request.Url.AbsoluteUri

And it does not matter in page life cycle.

您是不是说Request.Url吗?

If you want to get

page.aspx from

http://localhost:2806/Pages/page.aspx

try this:

    Dim url_array() As String = Request.Url.AbsolutePath.Split("/")
    Response.Write(url_array(url_array.Length - 1))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM