简体   繁体   English

如何从后面的代码中获取aspx页面的URL?

[英]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? 如何从后面的代码中获取活动的aspx页面的网址,以便可以将其分配给字符串变量?

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 page.aspx来自

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))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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