开发者

VirtualPathUtility.IsAbsolute(path) throws exception when path contains parameters

开发者 https://www.devze.com 2023-03-17 16:15 出处:网络
Why is it that in ASP.NET VirtualPathUtility.IsAbsolute(\"/~abc\") works fine. but VirtualPathUtility.IsAbsolute(\"/~abc?n=1) throws exception:

Why is it that in ASP.NET

VirtualPathUtility.IsAbsolute("/~abc") works fine.

but VirtualPathUtility.IsAbsolute("/~abc?n=1) throws exception:

System.Web.HttpException: '~/abc?n=1' is not a valid virtual path?

UPDATE:

I've just checked that there's a difference in behaviour between .NET 3.5 and .NET 4.0. VirtualPathUtility.IsAbsolute("/~abc?n=1) works fin开发者_高级运维e in 4.0 but not in 3.5. Do any of you know why they've changed that?


Because /~abc?n=1 is not a path, it includes the querystring part of the URL too (/~abc is the path, n=1 is the query string)


What you're trying to pass is url with query params, not path. Use path. Btw IsAbsolute returns true if the string starts with "/" character, so you don't need to use the method - just check it on your own.

0

精彩评论

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

关注公众号