简体   繁体   中英

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 actually 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.

您可以使用Request.Url.AbsolutePath获取域名后的路径。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM