如何使用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 ...
随机推荐
- 如何用 MEF 扩展应用程序
最近在写一篇关于如何扩展 Visual Studio 编辑器的文章时,用到了 MEF,因此打算写一篇文章提一下这个技术点.本篇文章并不打算详细介绍 MEF,只是一个最简单的入门,相信您在阅读本篇文章后 ...
- 快速Android开发系列网络篇之Retrofit
Retrofit是一个不错的网络请求库,用官方自己的介绍就是: A type-safe REST client for Android and Java 看官网的介绍用起来很省事,不过如果不了解它是怎 ...
- ios 常见问题解决
一,libxml/HTMLparser.h file not find 第一种方法: 点击左边项目的根目录,再点击右边的Build Settings,手工输入文字:“Header search pat ...
- ASP.net 页面生命周期
ASP.NET 页面生命周期 Page_Preinit(); 在页初始化开始时发生 Page_Init(); 在所有控件初始化且应用外观设置后引发 Page_InitComplete(); 在页初始化 ...
- iOS中数据库应用基础
iOS 数据库入门 一.数据库简介 1.什么是数据库? 数据库(Database) 是按照数据结构来组织,存储和管理数据的仓库 数据库可以分为2大种类 关系型数据库(主流) PC端 Oracle My ...
- 从Fiddler抓包到Jmeter接口测试(简单的思路)
备注:本文为博主的同事总结的文章,未经博主允许不得转载. Fiddler下载和配置安装 从网上下载fiddler的安装包即可,直接默认,一直点击下一步,直至安装完成. 安装完成后直接打开Fiddler ...
- 游戏服务器菜鸟之C#初探二游戏服务
经过短时间的折腾,为了解决上述问题,我对游戏进行一些简单的重构,以便能解决当前的瓶颈 添加了缓存服务器进行处理一些及时数据和配置数据,来缓解数据库的压力和IO的压力: 只能说解决当前的暂时性问题,但是 ...
- JavaScript权威设计--跨域,XMLHttpRequest(简要学习笔记十九)
1.跨域指的是什么? URL 说明 是否允许通信 http://www.a.com/a.jshttp://www.a.com/b.js 同一域名下 允许 http://www.a.com/lab/a. ...
- JavaScript权威设计--JavaScript对象(简要学习笔记八)
1.属性的特性 一个属性包含一个名字和4个特性.4个特性:值,可写性,可枚举性,可配置性 2.对象的三个属性 一:原型属性 要想检测一个对象是否是另一个对象的原型,使用isPrototypeOf( ...
- 通过IEnumerable和IDisposable实现可暂停和取消的任务队列
一般来说,软件中总会有一些长时间的操作,这类操作包括下载文件,转储数据库,或者处理复杂的运算. 一种处理做法是,在主界面上提示正在操作中,有进度条,其他部分不可用.这里带来很大的问题, 使用者不知道到 ...