http://www.lifeonplanetgroove.com/adding-and-deploying-generic-handlers-ashx-to-a-sharepoint-2010-visual-studio-project/
Adding and deploying Generic handlers (. ASHX) to A SharePoint in Visual Studio projectasp.net, SharePoint, Technology by ADAM TOTH on October
Generic handlers (. ashx files) deployed to the _layouts directory is not directly supported by Visual Studio Sharepo int projects like custom. aspx application pages is. This post would cover how to add them to your Visual Studio project and deploy them properly to the ISAPI folder.
Overview
Visual Studio Item Templates for Generic handlers (. ashx files) is not directly supported by Visual Studio Harepoint projects.
IMPORTANT UPDATE 4/30/2013! I contributed an ASHX ItemTemplate to the Cksdev team that's now included in the the and the versions of the extensions (see http://www.lifeonplanetgroove.com/2013/04/30/ashx-generic-handlers-and-sharepoint-now-in-cksdev/). The manual approach below is still a option, but the cksdev approach makes it much more seamless. Special thanks to Wes Hackett for merging the contribution.
If you try to Add New Item ... and select the Web or SharePoint categories in a VS. SharePoint project, you won ' T find Generic Handler anywhere.
You'll find ASP. Handler, but this would require you to create entries in Web. config to make your Handler work. In order to add a new. ASHX generic handler and get it to deploy properly, you can use the following steps:
- Right-click the project, and select Add New Item ...
- Choose the application Page template.
- In the Name box, enter a name of your file, with a . ashx extension.
- Open the . ashx file, delete the contents and replace with the following, changing your class= attribute W ith your desired namespace and class name:
<%@ Assembly name= "$SharePoint. project.assemblyfullname$"%><%@ Assembly name= "Microsoft.SharePoint, version=14.0.0.0, Culture=neutral, publickeytoken=71e9bce111e9429c "%><%@ WebHandler Language=" C # "class=" Mynamespace.mygenerichandler "%>
NOTE
If you want to reference other SharePoint assemblies in your code-behind, you'll need to add a @ Assembly directive for Each DLL.
- Open theAshx.csFile.
- In the solution Explorer, delete the ashx.designer.cs file, it's not needed.
- In the solution Explorer, click the . ashx file, and in the Properties pane, set the Build A Ction to Content.
- In the solution Explorer, click the . Ashx.cs file, and in the Properties pane, set the Bui LD Action to Compile.
- Make sure to enable Token replacement for . ASHX extensions. This would replace
$SharePoint.Project.AssemblyFullName$
the token with the full strong name of your assembly, enabling-to-reference other classes in Yo Ur compiled assembly from the Ashx Code-behind. You can read more about tokens replacement here. To enable the your project, Unload your project, Edit the. csproj file and add the following text to a PropertyGroup, and Reload your project:<propertygroup><tokenreplacementfileextensions>ashx</tokenreplacementfileextensions></ Propertygroup>
How to use VS to insert a ashx file in Sharepont 2013