Pregunta

Estoy tratando de implementar Ihttphandler en SharePoint 2010 y para referencia a la que estoy usando esto: http://blogs.msdn.com/b/kaevans/archive/2010/08/04/DEPLYING-AN-AP-NET-HTTPHANDER-TE-SharePoint-2010.aspx

Pero estoy recibiendo SPCONTEXT.CURRENT es "NULL" y no puede recuperar el sitio del contexto.

La URL es como:

http://spsvr/sitecoll/subsite/_layouts/myfolder/myhandler.ashx?param1=paramvalue

¿Fue útil?

Solución

Estoy respondiendo a mis preguntas.
Después de revisar a @simondoy comentar que "eso es extraño" y se dio cuenta de que realmente estoy cometiendo un error y luego nos damos cuenta.

cometí error, estaba corriendo con un permiso elevado y dentro de eso, estaba referendo a SPCONTEXT.CURRENT.

El código de error

public void ProcessRequest(HttpContext context)
{
    SPSecurity.RunWithElevatedPrivileges(delegate
    {
       // 'SPContext.Current' null reference error
        using (var site = new SPSite(SPContext.Current.Site.ID))
        {
            using (var web = site.OpenWeb(SPContext.Current.Web.ID))
            {
               // codes goes here
            }
        }
    });

}

El código fijo

public void ProcessRequest(HttpContext context)
{
    var curSite = SPContext.Current.Site;
    var curWeb = SPContext.Current.Web;
    SPSecurity.RunWithElevatedPrivileges(delegate
    {
        using (var site = new SPSite(curSite.ID))             {
            using (var web = site.OpenWeb(curWeb.ID))
            {
                // code goes here
            }
        }
    });

}

Licenciado bajo: CC-BY-SA con atribución
scroll top