如何使用VS在SharePont 2013中插入ashx文件
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文件的更多相关文章
- 【转载】在HTML中插入swf文件(转)
在HTML中插入swf文件(转) 在网页里面插入swf,再平常不过了,一般会想到如下代码: Html代码 <object classid="clsid:D27CDB6E-AE6D-11 ...
- Visual C++ 2010项目在Visual Studio 2013中打开.rc文件提示"undefined keyword or key name: SS_REALSIZECONTROL"解决方法
1.以方式打开.rc文件. 2.删除其中包含SS_REALSIZECONTROL定义的内容. 3.在资源编辑器中打开.rc文件,重新设置Real Size Control的属性(不能在代码编辑器里重新 ...
- vs中打开ashx文件没有提示,没有高亮标记解决方法
在VS菜单中 工具 --- 选项 --- 文本编辑器 --- 文件扩展名,在右侧添加 ashx ,选中Microsoft Visual C# 保存后,再打开就行了 ashx文件头部报错后,删除 < ...
- 更改Outlook 2013中Exchange数据文件存放路径
昨天新入职目前所在的公司,在原公司一直都是直接使用Outlook设置用户名和密码后,然后将*.pst邮件的数据文件保存在其他盘符,以防止在更新操作系统时出现邮件丢失的情况:但是目前公司使用的是Exch ...
- latex中插入eps文件
\documentclass{article} \usepackage{graphicx}\usepackage{epstopdf} \begin{document}\begin{figure} \ ...
- 如何在Visio 中插入各种数学公式?
在Visio 2007老版本中,插入公式可以直接在插入图片中选择,但是在后来的Visio2013中却无法直接通过插入图片的方法插入,那么该如何在visio 2013中插入公式呢? 具体的操作步骤如下: ...
- asp.net中.ashx文件接参
如果是在解决方案中的Web项目中创建.ashx文件,没有文件头,不能直接读取到html页面传来的参数值. 用context.Request["参数名"]来获取参数值. 用conte ...
- 如何在 在SharePoint 2013/2010 解决方案中添加 ashx (HttpHandler)
本文讲述如何在 在SharePoint 2013/2010 解决方案中添加 ashx (HttpHandler). 一般处理程序(HttpHandler)是·NET众多web组件的一种,ashx是其扩 ...
- 在 SharePoint 2013 中针对地理位置字段创建地图视图
在 SharePoint 2013 中针对地理位置字段创建地图视图 了解如何通过在 SharePoint 2013 列表中使用地图视图来显示位置信息.您可以通过 SharePoint 用户界面 (UI ...
随机推荐
- jsp
-----------------
- 微软开放.NET框架源代码和Mono
微软一直在朝着更加开放的方向努力.例如,公司首席执行官萨特亚纳德拉(Satya Nadella)在Windows 10预览发布会上声称微软喜欢Linux,这并不出人意料,但是对于一家将Linux视作威 ...
- 如何使用RobotFramework编写好的测试用例
如何使用Robot Framework编写优秀的测试用例 概述 命名 测试套件命名 测试用例命名 关键字命名 setup和teardown的命名 文档 测试套件文档 测试用例文档 用户关键字文档 测试 ...
- es6之变量的解构赋值
es5中通常我们声明变量都是以下的方式: var a = 10; var b = 20; var c = 30; //或者 var a = 10,b = 20,c = 30; //或者 var arr ...
- 解析大型.NET ERP系统 高质量.NET代码设计模式
1 缓存 Cache 系统中大量的用到缓存设计模式,对系统登入之后不变的数据进行缓存,不从数据库中直接读取.耗费一些内存,相比从SQL Server中再次读取数据要划算得多.缓存的基本设计模式参考下面 ...
- 偶遇this之坑
前言 在写一个懒加载插件时,遇到一个坑,就是this的指向问题,我想这种情况大部分人都会遇到,就写下来,新手也有个参考. 事件 有些页面图片比较多,但用户还不一定会全看,这样的话,全部去加载这些图片, ...
- Bootstrap3系列:输入框组
1. 基本实例 通过在文本输入框 <input> 前面.后面或是两边加上文字或按钮,实现对表单控件的扩展. .input-group包含.input-group-addon给 .form- ...
- Redis数据结构详解之Zset(五)
序言 Zset跟Set之间可以有并集运算,因为他们存储的数据字符串集合,不能有一样的成员出现在一个zset中,但是为什么有了set还要有zset呢?zset叫做有序集合,而set是无序的,zset怎么 ...
- Redis数据结构详解之Set(三)
序言 在Redis中,Set和list都是字符串序列,非常相似,不同之处在于Set是用哈希表来保持字符串的唯一性,没有先后顺序,不像list一样,可以在首尾增删数据.但是set也有自己的相应处理命令来 ...
- ASP.NET MVC5+EF6+EasyUI 后台管理系统(40)-精准在线人数统计实现-【过滤器+Cache】
系列目录 上次的探讨没有任何结果,我浏览了大量的文章和个别系统的参考!决定用Cache来做,这可能有点难以接受但是配合mvc过滤器来做效果非常好! 由于之前的过滤器我们用过了OnActionExecu ...