Call ResolveClientUrl in a static web method (ASPNet Web Forms)

I am currently having trouble finding a way to call ResolveClientUrl in the context of a static web method inside an ASP.Net web form page.

I use jQuery Ajax calls to interact with WebForms as described here: http://encosia.com/using-jquery-to-directly-call-aspnet-ajax-page-methods/ , so WebMethod should be static. The problem is that in WebMethod I need to create a URL and add a query string to it, and I would like to play it safe and pass it through ResolveClientUrl before adding the query string.

Is there any way around this or making .Net an alternative static method that does more or less the same thing?

+5
source share
2 answers

This is possible if called from a web page using:

public static void DoThis () {Page Page = HttpContext.Current.Handler as Page; }

However, if you use the web method, this will not be the page as a handler; its handler for the web request. I used this approach from JavaScript and it really worked:

http://iridescence.no/post/Resolving-relative-URLe28099s-from-JavaScript.aspx

NTN.

+2
source

from ... ASP.Net C # ResolveClientUrl inside class

Instead of calling ResolveClientUrlon the Page object (or any controls) you can also use Web.VirtualPathUtility.ToAbsolute("~/home.aspx");that will give you the same result as the callResolveUrl("~/home.aspx");

+10

All Articles