开发者

What's the proper way to determine whether a certain URL sits within a certain directory?

I have a directory in my project that I want all calls to web pages within it and any sub directories to be diverted to another web site.

Eg.

If the directory is http://localhost/MyProject/MyDirectory, I want all URLs such as http://localhost/MyProject/MyDirectory/MyFile.aspx to be diverted to another web site.

I do not want to use IIS for this as there are some additional business rules relating to dates and stuff. There I was thinking of doing it in either my master page or in my global.cs file.

How though do I know whether the request is a开发者_Go百科ctually in the directory.

I was going to just go

if(Request.Url.AbsoluteUri.contains("http://localhost/MyProject/MyDirectory) { Response.Redirect("...") }

But I feel that's not that good of a solution since may be in different domain names etc.


You could use Request.Url.AbsolutePath to get the path after the domain name.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜