开发者

check if a url has anything after the domain name

im using asp.net c#.

开发者_Go百科

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

e.g if the current url

www.example.com/

or

www.example.com

i want to set a bool to true. if it has anything after i want to set it to false. e.g.

www.example.com/stuff

how can i do this?

should return false.


Something like:

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


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


You can use Regular expressions on that...

Use:

(((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}))?


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

Simply check for something like

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜