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 2010 Visual Studio Project

 

Generic Handlers (.ashx files) deployed to the _layouts directory are not directly supported by Visual Studio 2010 SharePoint projects like custom .aspx application pages are. This post will 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) are not directly supported by Visual Studio 2010 or 2012 SharePoint projects.

IMPORTANT UPDATE 4/30/2013!

I contributed an ASHX ItemTemplate to the CKSDEV team that is now included in the 2010 and 2012 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 an 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 2010 SharePoint project, you won’t find Generic Handler anywhere.

You’ll find ASP.NET Handler, but this will 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 for your file, with an .ashx extension.
  • Open the .ashx file, delete the contents and replace with the following, changing your Class=attribute with 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 will need to add an @ Assembly directive for each DLL.

  • Open the ashx.cs file.
    • Add a using statement for System.Web.
    • You probably don’t need the using statement for Microsoft.SharePoint.WebControls, so remove it.
    • Change your namespace if necessary.
    • Change the class to inherit from IHttpHandler.
    • Implement the IHttpHandler interface. Your code should now look something like this:
      using Microsoft.SharePoint;
      using System.Web; namespace MyNamespace
      {
      public partial class MyGenericHandler : IHttpHandler
      {
      #region IHttpHandler Members public bool IsReusable
      {
      get { throw new NotImplementedException(); }
      } public void ProcessRequest(HttpContext context)
      {
      throw new NotImplementedException();
      } #endregion
      }
      }
  • In the Solution Explorer, delete the ashx.designer.cs file, it is not needed.
  • In the Solution Explorer, click the .ashx file, and in the Properties pane, set the Build Action to Content.
  • In the Solution Explorer, click the .ashx.cs file, and in the Properties pane, set the Build Action to Compile.
  • Make sure to enable Token replacement for .ashx extensions. This will replace the$SharePoint.Project.AssemblyFullName$ token with the full strong name of your assembly, enabling you to reference other classes in your compiled assembly from the ashx code-behind.You can read more about token replacement here. To enable this for 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>

如何使用VS在SharePont 2013中插入ashx文件的更多相关文章

  1. 【转载】在HTML中插入swf文件(转)

    在HTML中插入swf文件(转) 在网页里面插入swf,再平常不过了,一般会想到如下代码: Html代码 <object classid="clsid:D27CDB6E-AE6D-11 ...

  2. Visual C++ 2010项目在Visual Studio 2013中打开.rc文件提示"undefined keyword or key name: SS_REALSIZECONTROL"解决方法

    1.以方式打开.rc文件. 2.删除其中包含SS_REALSIZECONTROL定义的内容. 3.在资源编辑器中打开.rc文件,重新设置Real Size Control的属性(不能在代码编辑器里重新 ...

  3. vs中打开ashx文件没有提示,没有高亮标记解决方法

    在VS菜单中 工具 --- 选项 --- 文本编辑器 --- 文件扩展名,在右侧添加 ashx ,选中Microsoft Visual C# 保存后,再打开就行了 ashx文件头部报错后,删除 < ...

  4. 更改Outlook 2013中Exchange数据文件存放路径

    昨天新入职目前所在的公司,在原公司一直都是直接使用Outlook设置用户名和密码后,然后将*.pst邮件的数据文件保存在其他盘符,以防止在更新操作系统时出现邮件丢失的情况:但是目前公司使用的是Exch ...

  5. latex中插入eps文件

    \documentclass{article} \usepackage{graphicx}\usepackage{epstopdf} \begin{document}\begin{figure}  \ ...

  6. 如何在Visio 中插入各种数学公式?

    在Visio 2007老版本中,插入公式可以直接在插入图片中选择,但是在后来的Visio2013中却无法直接通过插入图片的方法插入,那么该如何在visio 2013中插入公式呢? 具体的操作步骤如下: ...

  7. asp.net中.ashx文件接参

    如果是在解决方案中的Web项目中创建.ashx文件,没有文件头,不能直接读取到html页面传来的参数值. 用context.Request["参数名"]来获取参数值. 用conte ...

  8. 如何在 在SharePoint 2013/2010 解决方案中添加 ashx (HttpHandler)

    本文讲述如何在 在SharePoint 2013/2010 解决方案中添加 ashx (HttpHandler). 一般处理程序(HttpHandler)是·NET众多web组件的一种,ashx是其扩 ...

  9. 在 SharePoint 2013 中针对地理位置字段创建地图视图

    在 SharePoint 2013 中针对地理位置字段创建地图视图 了解如何通过在 SharePoint 2013 列表中使用地图视图来显示位置信息.您可以通过 SharePoint 用户界面 (UI ...

随机推荐

  1. 二叉树的递归实现(java)

    这里演示的二叉树为3层. 递归实现,先构造出一个root节点,先判断左子节点是否为空,为空则构造左子节点,否则进入下一步判断右子节点是否为空,为空则构造右子节点. 利用层数控制迭代次数. 依次递归第二 ...

  2. Hyper-V上运行的Linux虚拟机验证是否安装了集成服务

    Hyper-V上运行的Linux虚拟机验证是否安装了集成服务 ps aux|grep "hv"root       311  0.0  0.0      0     0 ?     ...

  3. 在Linux和Windows平台上操作MemoryMappedFile(简称MMF)

    操作系统很早就开始使用内存映射文件(Memory Mapped File)来作为进程间的共享存储区,这是一种非常高效的进程通讯手段..NET 4.0新增加了一个System.IO. MemoryMap ...

  4. React-Native 动画优化

    前言 动画对于客户端来说是非常重要的一部分,直接影响到应用的用户体验.前端对于动画优化通常使用CSS3样式来实现动画,以利用GPU加速特性.而React-Native由于渲染模式的不同,无法使用CSS ...

  5. C#的泛型的类型参数可以有带参数的构造函数的约束方式吗?

    Review后看到标题让我十分羞愧自己语文功底太差,估计...请见谅......我还特地把这句写回开头了...... 问题 前天遇到的一个问题,所以在MSDN发了个问,刚也丰富了下问题,关于泛型的. ...

  6. MySQL基础之视图

    关于视图 视图是虚表,其中并不存在数据,只是多个表的组成 使用视图的优势 视图可以代替复杂的查询SQL语句,可以事先将不同表的多个数据组织起来 提高权限控制管理,能够将权限限制为行级管理,更具有安全性 ...

  7. git 常见命令解析

    转载自http://www.rainkong.net/post/git-image.html 之前用的都是svn ,git还是要了解的,万一哪天要用了呢

  8. iOS-----程序异常处理----- 断言NSAssert()和NSParameterAssert区别和用处

    NSAssert和assert是断言,主要的差别是assert在断言失败的时候只是简单的终止程序,而NSAssert会报告出错误信息并且打印出来.所以尽管的使用NSAssert,可以不去使用asser ...

  9. 从E.E到S.E

    title: 从E.E到S.E date: 2014-12-18 16:49:19 categories: [杂念] tags: [想法,生涯] --- 我在本科学的是Electric Enginee ...

  10. Json概述以及python对json的相关操作

    JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.易于人阅读和编写.同时也易于机器解析和生成.它基于JavaScript Programming Langu ...