Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fetch Url Segments

I want to fetch the url segments of the current page. I was using Web Forms earlier. In Web Forms I was using Request.Url.Segments method to do that. But this method is not working in ASP.NET Core 2.2.

string[] urlSegments = Request.Url.Segments;
like image 704
Divesh Soni Avatar asked Feb 22 '26 12:02

Divesh Soni


1 Answers

Uri.Segments works with .net core . You can use :

string[] urlSegments = new Uri(Request.GetDisplayUrl()).Segments;

GetDisplayUrl() is an extension method from the following namespace : Microsoft.AspNetCore.Http.Extensions :

using Microsoft.AspNetCore.Http.Extensions;
like image 185
Nan Yu Avatar answered Feb 25 '26 03:02

Nan Yu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!