1

I got stuck into some weird situation related to path for generic handler (.ashx).

Ajax post is being made to handler. (Note: i have not applied / before Handler)

ajaxCallUrl: "Handler/RequestHandler.ashx"

After hosting on virtual directory in iis, url need to get changed like

ajaxCallUrl: "App/Handler/RequestHandler.ashx"

I trying using VirtualPathUtility.ToAbsolute("~/Handler/RequestHandler.ashx")

Also i have seeing the solution here (related to mine) showing getting url from Action Link but how in case of Handler?

Pls suggest any solution

Community
  • 1
  • 1
ArjunArora
  • 986
  • 3
  • 12
  • 27
  • take a look at this: http://stackoverflow.com/questions/3359816/can-asp-net-routing-be-used-to-create-clean-urls-for-ashx-ihttphander-handl – Alex Art. Jan 27 '16 at 07:00

1 Answers1

2

If you want to get the right path, regardsless of the virtual directory you are currently in, you can use the UrlHelper.Content helper method to get the right path:

"@Url.Content("~/Handler/RequestHandler.ashx")"

The ~/ in the path will make it a path relative to the application.

Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325