默认,在用vs2013开发SharePoint项目时,vs没有提供一般应用程序(.ashx)的项目模板,本文解决此问题。
效果:
<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Assembly Name="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ WebHandler Class="$SharePoint.Type.be94b0d0-ca37-4783-b8e9-06ba0477a22f.FullName$" %>
using System;
using System.Web;
using System.Runtime.InteropServices;
namespace SharePointProject2.Layouts.SharePointProject2
{
[Guid("be94b0d0-ca37-4783-b8e9-06ba0477a22f")]
public partial class ApplicationPage1 : IHttpHandler
{
#region IHttpHandler Members
public bool IsReusable
{
get { throw new NotImplementedException(); }
}
public void ProcessRequest(HttpContext context)
{
//throw new NotImplementedException();
context.Response.Write("123");
}
#endregion
}
}
在PropertyGroup节点下面,添加如下:
十一.右击项目"SharePointProject2",选择"重新加载项目",注意要关闭我们打开的SharePointProject2.csproj文件。
十二.右击项目"SharePointProject2",选择"部署"。打开浏览器就可以浏览了。
关于GUID的生成,请在vs里,选择"工具"----"创建GUID"
关于上面的"六","七"步,如果不想使用GUID的形式,也可以使用如下方式(去掉红星划掉的部分):
如遇报错,请
右击"ApplicationPage1.ashx"选择"属性",然后把"生成操作"改为"内容"。
右击"ApplicationPage1.ashx.cs" 选择"属性",然后把"生成操作"改为"编译"。
关于如何在Visual Studio 2010的SharePoint项目中添加一般应用程序(.ashx),建议安装vs2010插件cks(http://cksdev.codeplex.com/).
当然也可以按上面的方法进行,执行把"六"中的前两行代码改为:
<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Assembly Name="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
参考:
https://cann0nf0dder.wordpress.com/2013/05/22/creating-generic-httphandler-in-sharepoint/
http://www.lifeonplanetgroove.com/adding-and-deploying-generic-handlers-ashx-to-a-sharepoint-2010-visual-studio-project/
https://peakfinders.blogspot.jp/2015/03/adding-and-deploying-generic-handlers.html
http://blog.csdn.net/abrahamcheng/article/details/20490757#