locked
Return value of VirtualPathUtility.ToAbsolute() RRS feed

  • Question

  • User853290399 posted

    Hi,

    What'd be the return value of VirtualPathUtility.ToAbsolute("~/")  if there's no virtual directory in file path?

    I don't have environment to test it.

    Thanks

    Wednesday, June 19, 2013 5:28 AM

Answers

  • User853290399 posted

    So in a case like below it won't generate any error even if there's no virtual directory, right?

    Request.Url.GetLeftPart(UriPartial.Authority) + VirtualPathUtility.ToAbsolute("~/") + "PaymentFailed.aspx";

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, June 19, 2013 6:00 AM
  • User-166373564 posted

    Hi

    Please refer the usage of  VirtualPathUtility.ToAbsolute Method( string virtualPath ),

    If virtualPath is:

    •Absolute, the ToAbsolute method returns the virtual path unchanged.

    •Application relative, the ToAbsolute method appends the current application virtual directory path to the beginning of the virtualPath. For example, the current application virtual directory path can be accessed from the AppDomainAppVirtualPath property.

    •Not rooted, the ToAbsolute method raises an ArgumentOutOfRangeException exception,

    Regards

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, June 25, 2013 4:59 AM

All replies

  • User-1716253493 posted

    in IIS site the result is "\"

    in local(VS) the result is "/mysite/"

    Wednesday, June 19, 2013 5:42 AM
  • User853290399 posted

    So in a case like below it won't generate any error even if there's no virtual directory, right?

    Request.Url.GetLeftPart(UriPartial.Authority) + VirtualPathUtility.ToAbsolute("~/") + "PaymentFailed.aspx";

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, June 19, 2013 6:00 AM
  • User465171450 posted

    Keep in mind, VirtualPathUtility has  absolutely nothing to do with a Virtual Directory. You can have a virtual path with absolutely no virtual directories whatsoever in an application or IIS installation.

    Wednesday, June 19, 2013 10:21 AM
  • User-166373564 posted

    Hi

    Please refer the usage of  VirtualPathUtility.ToAbsolute Method( string virtualPath ),

    If virtualPath is:

    •Absolute, the ToAbsolute method returns the virtual path unchanged.

    •Application relative, the ToAbsolute method appends the current application virtual directory path to the beginning of the virtualPath. For example, the current application virtual directory path can be accessed from the AppDomainAppVirtualPath property.

    •Not rooted, the ToAbsolute method raises an ArgumentOutOfRangeException exception,

    Regards

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, June 25, 2013 4:59 AM