如何使用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 ...
随机推荐
- 高级渲染技巧和代码示例 GPU Pro 7
下载代码示例 移动设备正呈现着像素越来越高,屏幕尺寸越来越小的发展趋势. 由于像素着色的能耗非常大,因此 DPI 的增加以及移动设备固有的功耗受限环境为降低像素着色成本带来了巨大的压力. MSAA 有 ...
- spring boot1
spring boot 玩转spring boot--快速开始 开发环境: IED环境:Eclipse JDK版本:1.8 maven版本:3.3.9 一.创建一个spring boot的mcv ...
- java的poi技术读取Excel数据到MySQL
这篇blog是介绍java中的poi技术读取Excel数据,然后保存到MySQL数据中. 你也可以在 : java的poi技术读取和导入Excel了解到写入Excel的方法信息 使用JXL技术可以在 ...
- 我的MYSQL学习心得(十一) 视图
我的MYSQL学习心得(十一) 视图 我的MYSQL学习心得(一) 简单语法 我的MYSQL学习心得(二) 数据类型宽度 我的MYSQL学习心得(三) 查看字段长度 我的MYSQL学习心得(四) 数据 ...
- iOS开发系列--音频播放、录音、视频播放、拍照、视频录制
--iOS多媒体 概览 随着移动互联网的发展,如今的手机早已不是打电话.发短信那么简单了,播放音乐.视频.录音.拍照等都是很常用的功能.在iOS中对于多媒体的支持是非常强大的,无论是音视频播放.录制, ...
- 使用Maven+Nexus+Jenkins+Svn+Tomcat+Sonar搭建持续集成环境(二)
前言 上一篇随笔Maven+Nexus+Jenkins+Svn+Tomcat+Sonar搭建持续集成环境(一)介绍maven和nexus的环境搭建,以及如何使用maven和nexus统一管理库 ...
- 用java开发微信公众号:接收和被动回复普通消息(三)
上篇说完了如何接入微信公众号,本文说一下微信公众号的最基本功能:普通消息的接收和回复.说到普通消息,那么什么是微信公众号所定义的普通消息呢,微信开发者文档中提到的接收的普通消息包括如下几类: 1.文本 ...
- 基于虎书实现LALR(1)分析并生成GLSL编译器前端代码(C#)
基于虎书实现LALR(1)分析并生成GLSL编译器前端代码(C#) 为了完美解析GLSL源码,获取其中的信息(都有哪些in/out/uniform等),我决定做个GLSL编译器的前端(以后简称编译器或 ...
- EMC与电容(二)-电容参数意义、各电容的特点及应用
上次的问题,看到很多回答里都有关于X电容,Y电容,NPO之类,这些很奇怪的参数到底代表什么意义呢?以前很多次都在BOM表里看到这些参数,一直都无视过去,正好这次的EMC课程里也提到这方面的知识,正好跟 ...
- Objective-C中NSInvocation的使用
OC中调用方法某个对象的消息呦两种方式: #1. performanceSelector: withObject: #2. NSInvocation. 第一个PerformaceSelector比较常 ...