开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜