如何使用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

ASP.NETSHAREPOINTTECHNOLOGY

by ADAM TOTH on OCTOBER 15, 2010

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>
时间: 2024-08-25 18:30:30

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

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

在HTML中插入swf文件(转) 在网页里面插入swf,再平常不过了,一般会想到如下代码: Html代码 <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="200"

在网页中插入pdf文件

由于要做的个人主页的需求,突然想在网页中可不可以插入pdf文件来阅读呢?于是开始查资料, 一种说用<embed>标签,但是没能实行成功 <embed width="800" height="600" src="test_pdf.pdf"> </embed> 通过的浏览器:360.Firefox.IE.Chrome 一种说可以用<object>标签,这种方法经检验可行 这段代码可以在网页中查看pdf文

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

昨天新入职目前所在的公司,在原公司一直都是直接使用Outlook设置用户名和密码后,然后将*.pst邮件的数据文件保存在其他盘符,以防止在更新操作系统时出现邮件丢失的情况:但是目前公司使用的是Exchange,在Outlook2013中配置用户名后不支持对数据文件*.ost路径的修改,文件默认路径如下: 不是使用exchange的邮箱如下: 可以对数据文件的路径进行更改:但是使用了exchange的邮箱如下图,不能进行修改: 在度娘中搜了几个方法后,根据描述的内容也没能配置成功(请容许我2一下)

如何在 网站页面中插入pdf文件,使用插件,Native pdf 支持,chrome,Edge,Firefox,

1 1 Edge: 2 3 4 xxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

在浏览器中播放音频文件的兼容性问题

来源:http://blog.sina.com.cn/s/blog_96ae64bd0100zk9r.html 下面谈谈本人在html中插入音频文件,经过我的本地测试总结的一些问题(播放mp3文件): 1.<embed type="audio/mp3" src="" autostart=true  loop=false></embed>    问题:IE8上正常(通过media player插件来播放)但在IE6和IE7上不会播放      

在网页中插入百度地图(实例)

步骤 1 2 3 如何在网页中插入百度地图呢? 2.切换城市,搜索需标注位置.(如下图 方法/步骤 1.进入:http://api.map.baidu.com/lbsapi/creatmap/(创建地图-百度地图API所见即所得工具,百度官方地址,大家放心使用) 切换城市,搜索需标注位置.(如下图:) 设置地图:大家可以对网站显示地图的宽高进行设置,其余选项不动. 添加标注:点击第一个图标后,在右侧找到自己的位置,单击鼠标左键可定位.标记图标处可更换图标形状,名称和备注填入位置相关信息.(如下图

SharePoint 2013 中代码创建列表查阅项字段

1.首先,打开VS创建两个List Definition,分别是Address和City,如下图: 2.City列表里修改Title为City Name,其实内部名称还是Title,注意一下: 3.给City的列表实例,添加几个值,用来测试使用,如下: 4.在Address列表里添加几个字段,分别是CityName(LookUp类型)和HomeAddress(Single Line of Text),如下: 5.查看Address列表的Schema.Xml,尤其是Fields节点,也就是字段,如

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

本文讲述如何在 在SharePoint 2013/2010 解决方案中添加 ashx (HttpHandler). 一般处理程序(HttpHandler)是·NET众多web组件的一种,ashx是其扩展名.一个httpHandler接受并处理一个http请求,类比于Java中的servlet.类比于在Java中需要继承HttpServlet类,在.net中需要实现IHttpHandler接口,这个接口有一个IsReusable成员,一个待实现的方法ProcessRequest(HttpConte

Qt 向word中插入文字(使用QAxWidget和QAxObject)

pro 文件中要加入 CONFIG += qaxcontainer 2. main.cpp [cpp] view plain copy #include <QApplication> #include <QAxWidget> #include <QAxObject> int main(int argc, char* argv[]) { QApplication app(argc, argv); QAxWidget *word=new QAxWidget("Wo