Question

I'm developing a SP 2010 Visual Web Part that needs to load some data via AJAX.

I found this very helpful article but I'm having some doubts about it.

I have the Visual Web Part project, inside I have the Visual Web Part and some other files. The article says I need to create an .ashx file that will acts as an HTTP handler. So that's what I did, I created a "MyHandler.ashx" in the root of the project and put the WebHandler directive. But I'm not sure about the Assembly directive.

Then it says we need to create an implementation to the handler and point it to it. I believe I have that part ok.

Then I need to make the actual client call via jQuery. Here's the part I don't know how to do it because I don't know the url where the .ashx is being deployed (if it's even being deployed...).

I'm trying:

$.get('/_layouts/SomeNamespace/MyHandler.ashx', ...)

But it's not working... again, don't know the handler's url...

I'm pretty new at Sharepoint development, so please don't be harsh =)

Thanks!

Here are simplified versions of my handler's files.

MyHandler.ashx

<%@ WebHandler Language="C#" Class="SomeNamespace.MyHandler" CodeBehind="MyHandler.cs" %>

MyHandler.cs

namespace SomeNamespace
{
    public class MyHandler : IHttpHandler
    {
        public bool IsReusable { get { return false; } }


        public void ProcessRequest(HttpContext context)
        {
            context.Response.Write("From the handler at " + DateTime.Now);
        }

        // bunch of methods
     }
}
Was it helpful?

Solution

The <handlers> node in the web.config defines the location of the HTTP Handler. Have a read at Chris's article again, and look at the Web Config Modification he does.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top