简体   繁体   中英

get current page in C#

For instance if I have http://www.mywebsite.com/about.aspx . Store about.aspx (or whatever page we're on) in a variable. Also need this to work even if there is information after the page in the url such as a query string.

Ah - I suggest you read the ASP.NET documentation VERY carefully. The HttpRequest object, available as Request property contains all information that you can have about the request. This includes the path called, all parameters etc.

Weighing in a little late, but others may get here as I did.

You could try to use a combination of the Uri and Path objects. For example:

Uri test = new Uri("http://www.microsoft.com/default.aspx?id=7&em=958");            
Console.WriteLine(Path.GetFileName(test.AbsolutePath));

Not sure if this is the "proper" way but it works for me.

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