Check if url has anything after domain name

im using asp.net c #.

I want to check if the current url has anything after the domain name.

for example if the current url

www.example.com/

or

www.example.com

I want to set bool to true. if it has something after I want to set it to false. eg.

www.example.com/stuff

How can i do this?

should return false.

+2


a source to share


4 answers


Sort of:



bool isRoot = new Uri("http://www.example.com").AbsolutePath == "/";

      

+2


a source


You can try System.Uri.PathAndQuery to test this. PathAndQuery should be empty / null for your first case.



0


a source


You can use regular expressions for this ...

Using:

(((HTTP | HTTPS): .//) | (WWW)) +. (([A-Za-Z0-9 ._-] + [A-Za-Z] {2.6}) |? (... [0-9] {1.3} [0-9] { 1,3} [0-9] {1,3} [0-9] {1,3}))

0


a source


I could be wrong, but I believe that even if you hit the domain directly at www.example.com ASP.NET will detect the URL including the default page, which is usually default.aspx.

Just check something like

string defaultPage = "/default.aspx";
return Request.Url.PathAndQuery == defaultPage;

      

0


a source







All Articles