Deploying an ASP.NET HttpHandler to SharePoint 2010
2011-11-17 17:16
633 查看
[http://blogs.msdn.com/b/kaevans/archive/2010/08/04/deploying-an-asp-net-httphandler-to-sharepoint-2010.aspx]
Got a cool question in email today… how to deploy an HttpHandler to SharePoint 2010 that uses code-behind. The answer is that you don’t really use code-behind like you would in an ASP.NET application where the code and assembly are in the same folder. With SharePoint, you need to deploy your code to the Global Assembly Cache (GAC).
You can create the code for an HttpHandler very easily in Visual Studio. I am going to steal borrow some code from Ted Pattison’s walkthrough, “Creating a Custom HttpHandler in Windows SharePoint Services 3.0” on MSDN (includes a video as well).
The question is how to call that code? When an HTTP request comes in, how do you map that request to this code?
The easiest way is to create a .ASHX file and deploy it to the LAYOUTS directory in the SharePoint root (aka “14 hive”). To do this, right-click your SharePoint project in Visual Studio 2010 and choose “Add SharePoint Layouts Mapped Folder”.
In that newly created folder, add a new file with a .ASHX extension with the following contents. The .ASHX file just points to the code in the GAC using the fully-qualified assembly name.
The solution looks like this in Visual Studio 2010.
When you build and deploy your solution from Visual Studio, the code is compiled into an assembly (a .DLL) and registered in the Global Assembly Cache. The output is:
Got a cool question in email today… how to deploy an HttpHandler to SharePoint 2010 that uses code-behind. The answer is that you don’t really use code-behind like you would in an ASP.NET application where the code and assembly are in the same folder. With SharePoint, you need to deploy your code to the Global Assembly Cache (GAC).
You can create the code for an HttpHandler very easily in Visual Studio. I am going to steal borrow some code from Ted Pattison’s walkthrough, “Creating a Custom HttpHandler in Windows SharePoint Services 3.0” on MSDN (includes a video as well).
using System; using System.Web; using Microsoft.SharePoint; namespace ASHXHandlerDemo { public class HelloHttpHandler : IHttpHandler { public bool IsReusable { get { return false; } } public void ProcessRequest(HttpContext context) { SPSite siteColl = SPContext.Current.Site; SPWeb site = SPContext.Current.Web; context.Response.ContentType = "text/plain"; context.Response.Write("Hello HttpHandler from the site " + site.Title + " at " + site.Url); } } }
The question is how to call that code? When an HTTP request comes in, how do you map that request to this code?
The easiest way is to create a .ASHX file and deploy it to the LAYOUTS directory in the SharePoint root (aka “14 hive”). To do this, right-click your SharePoint project in Visual Studio 2010 and choose “Add SharePoint Layouts Mapped Folder”.
In that newly created folder, add a new file with a .ASHX extension with the following contents. The .ASHX file just points to the code in the GAC using the fully-qualified assembly name.
<%@ Assembly Name="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Assembly Name="ASHXHandlerDemo, Version=1.0.0.0, Culture=neutral, PublicKeyToken=684a624f7b7a49ae" %> <%@ WebHandler Language="C#" class="ASHXHandlerDemo.HelloHttpHandler" %>
The solution looks like this in Visual Studio 2010.
When you build and deploy your solution from Visual Studio, the code is compiled into an assembly (a .DLL) and registered in the Global Assembly Cache. The output is:
相关文章推荐
- How to enable an ASP.Net application to run on a SharePoint virtual server
- How To Create an ASP.NET HTTP Handler by Using Visual C# .NET
- ASP.NET WebUserControl to SharePoint WebPart Best Practice (vs2008)
- ASP.NET Chart Controls in SharePoint 2010
- how to integrate ASP.NET codes inside SharePoint
- 【tomcat】启动报错:Failed to initialize end point associated with ProtocolHandler ["http-apr-8080"] java.lang.Exception: Socket bind failed 和java.net.BindException: Address already in use: JVM_Bind错误解决
- Loading an ASP.NET Page Class dynamically in an HttpHandler
- Creating a SharePoint BCS .NET Connectivity Assembly to Crawl RSS Data in Visual Studio 2010
- SharePoint Error - An unrecognized HTTP response was received when attempting to crawl this item
- MSDN: Using HTTP Modules and Handlers to Create Pluggable ASP.NET Components
- Web Parts: From SharePoint to ASP.NET 2.0
- How to put asp.net file to sharepoint
- IDEA错误:Failed to start end point associated with ProtocolHandler [http-nio-9999] java.net.BindException: Address already in use: bind
- [转]Migrating HTTP handlers and modules to ASP.NET Core middleware
- 电子书下载:Pro ASP.NET SharePoint 2010 Solutions: Techniques for Building SharePoint Functionality into ASP.NET Applications
- SharePoint Error - An unrecognized HTTP response was received when attempting to crawl this item
- Rapid Business Development: Lightswitch vs. Dynamics CRM vs. SharePoint 2010 vs. ASP.NET MVC 3
- How to Deploy Solution (WSP) from SharePoint 2010 Central Administration
- asp.net webconfig下的httphandler模块配置
- Windows SharePoint Services 虚拟服务器用于 ASP.NET 2.0 配置设置