using server.mappath() in an generic handler (.ashx)

Working on a project over the weekend that used a generic handler for some AJAX calls.  In one of the calls I need to map to a local file to great a T4 template file.

In an MVC file you can get away with:

Server.MapPath("~/"), @"App_Data\SomeT4File.txt")

For a generic handler you need to simply change it to the following

HttpContext.Current.Server.MapPath("~/"), @"App_Data\SomeT4File.txt")


This entry was posted in Web and tagged , . Bookmark the permalink.