Using generic Handlers in SharePoint 2013/2010 Solutions

Source: Internet
Author: User

This article describes how to add ashx (HttpHandler) in SharePoint 2013/2010 Solutions.

The general handler (HttpHandler) is · NET is one of many Web components, and ashx is its extension. A HttpHandler accepts and processes an HTTP request, analogous to a servlet in Java. Analogy to the need to inherit the HttpServlet class in Java, you need to implement the IHttpHandler interface in. NET, this interface has a isreusable member, a method to implement ProcessRequest (HTTPCONTEXTCTX). The program handles the received HTTP request in the ProcessRequest method. The member isreusable Specifies whether an instance of this ihttphnadler can be used to handle multiple requests: The ASHX program is suitable for producing data formats that are processed by the browser that do not require postback processing, such as for generating dynamic pictures, dynamic text, and so on. The following article describes how to add ashx (HttpHandler) to a SharePoint 2013/2010 solution:

1. Create a New Farm solution

2. Mapping SharePoint's Layout folder

3. Add a new project

4, select Application page (Application page)

5. Modify the TEST.ASHX code to SharePoint 2013 (note replacing class name)

<%@ Assembly name= "$SharePoint. project.assemblyfullname$"%> <%@ Assembly name= "Microsoft.SharePoint, version=15.0.0.0, Culture=neutral, publickeytoken=71e9bce111e9429c "%> <%@ webhandler Language=" C # "Class=" Testashx.test "%>

SharePoint 2010 (Note replacing class name):

6. Test.ashx.cs Code

usingSystem;usingMicrosoft.SharePoint;usingMicrosoft.SharePoint.WebControls;usingsystem.web;namespacetestashx{ Public Partial classTest:ihttphandler { Public BOOLisreusable {Get{return true; } }     Public voidProcessRequest (HttpContext context) {System.Web.Script.Serialization.JavaScriptSerializer Jsonserializer =NewSystem.Web.Script.Serialization.JavaScriptSerializer (); Context. Response.ContentType="Application/json"; varJsonresult = Jsonserializer.serialize (NewJosnresult () {name="Abraham Cheng", age= in});//return what wantcontext.    Response.Write (Jsonresult); }       }  classJosnresult { Public  stringName {Get;Set;}  Public intAge {Get;Set;} }}

7. UnLoad the project, edit the project project file, insert it in the PropertyGroup node:

<TokenReplacementFileExtensions>ashx</TokenReplacementFileExtensions>

8. Reload Project, deploy solution

9. Verify that A. SharePoint 2013 authentication address is:

.../_layouts/15/xxx/text.ashx

B. The SharePoint 2010 authentication address is:

.../_layouts/xxx/text.ashx

Open the above address to return a JSON object

In the actual application can use the AJAX request TEXT.ASHX to obtain the data, unfolds in the foreground, achieves does not refresh the page to update the data the purpose.

Using generic Handlers in SharePoint 2013/2010 Solutions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.