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
You can try System.Uri.PathAndQuery to test this. PathAndQuery should be empty / null for your first case.
0
a source to share
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 to share