Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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
     }
}
share|improve this question

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer
    
Read again. He says there are 2 options to associate the handler to its implementaion. Either you do the WebHandler directive thing OR you go for the webconfig modification. I'd rather not touch the webconfig. –  emzero Aug 3 '11 at 21:19
    
Ahh, did you create a Layouts mapped folder in visual studio? If not, do that, it'll place the ashx in the SharePointRoot where it'll become accessable via the /_layouts path. –  James Love Aug 3 '11 at 21:28
    
Yeah, I just did that being almost sure it would work. But it didn't. I have an "Images" mapped folder and it works, I can access the images. But I created a "Layouts" mapped folder, placed the .ashx inside but still can access it. Do you know if I need to add it to the Package or the Feature to actually make it deployable? –  emzero Aug 3 '11 at 21:31
    
Forget it. It was already added to the Package when created the Layouts mapped folder. Wonder if it's something about the .ashx itself. Maybe I didn't define it well.. I do not have the Assembly directive, don't know what to put in it. –  emzero Aug 3 '11 at 21:33
    
1) Look into the file system itself (C:\program files\common files\microsoft shared\web server etensions\14\template\layouts) to see if the file is created. 2) The assembly directive should have the fully qualified name of your assembly -Visual Studio 2010 has a shortcut to this in the form of a token - $SharePoint.Project.AssemblyFullName$ - and you'll need to tell Visual Studio to parse the ASHX file to do the token replacement (here's how to do that, adding ashx instead of svc): scottcurrier.wordpress.com/2011/06/28/… –  James Love Aug 3 '11 at 21:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.