Strange problem with newdocset(Document set) with SPContext.Current.Web while using HttpModule
-
07-12-2019 - |
Domanda
newdocset doesnot seems to work with SPContext.Current.Web I have a HttpModule below is a sample code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using System.Web;
namespace mynamespace
{
class DemoHttpModule : System.Web.IHttpModule
{
public void Dispose()
{
throw new NotImplementedException();
}
public void Init(System.Web.HttpApplication application)
{
application.BeginRequest += new EventHandler(Application_BeginRequest);
application.AcquireRequestState += new EventHandler(this.Application_AcquireRequestState);
application.ReleaseRequestState += new EventHandler(this.Application_ReleaseRequestState);
//To Handel page.PreRender
application.PreRequestHandlerExecute += new EventHandler(this.Application_PreRequestHandlerExecute);
}
private void Application_BeginRequest(object sender, EventArgs e)
{
HttpApplication curApp = sender as HttpApplication;
//SPWeb oWeb = SPContext.Current.Web;
}
private void Application_AcquireRequestState(object sender, EventArgs e)
{
HttpApplication curApp = sender as HttpApplication;
if (curApp.Request.Url.ToString().Contains("advsetng.aspx"))
{
return;
}
using (SPSite oSPsite = new SPSite(Convert.ToString(curApp.Request.Url)))
{
using (SPWeb oSPWeb = oSPsite.OpenWeb())
{
}
}
}
private void Application_ReleaseRequestState(object sender, EventArgs e)
{
HttpApplication curApp = sender as HttpApplication;
SPWeb oWeb = SPContext.Current.Web;
}
private void Application_PreRequestHandlerExecute(object sender, EventArgs e)
{
HttpApplication curApp = sender as HttpApplication;
SPWeb oWeb = SPContext.Current.Web;
}
}
}
in Application_AcquireRequestState if i am using
using (SPSite oSPsite = new SPSite(SPContext.Current.Web.ID)
{
Then although it is not generating any exception but shows an error message while creating a newdocset stating "This action cannot be completed"
if i am using
using (SPSite oSPsite = new SPSite(Convert.ToString(curApp.Request.Url)))
{
then it is working fine, but the problem with curApp.Request is it will always return the root level web object So are there any alternatives to SPContext.Current.Web.ID
in this link the answer suggested by spunkyvt tells something about a similar problem but i cant use the solution suggested by him simillar problem link
Any suggestions
Thanks Mac
Soluzione 2
Fixes the issue with the following code
if (Convert.ToString(curApp.Request.Url).ToLower().Contains("newdocset.aspx"))
{
using (SPSite oSPsite = new SPSite(curApp.Context.Request.Url.ToString()))
{
using (SPWeb oSPWeb = oSPsite.OpenWeb())
{
// doing my stuff here
}
}
}
Altri suggerimenti
First of all, you are trying to create and SPSite with the ID of an SPWeb. That's is never going to work. Try the following instead.
using (SPSite oSPsite = new SPSite(SPContext.Current.Site.ID))
{
}
Out of curiosity, why are you using an HttpModule? Can't you do it with an invisible custom control injected in the masterpage using the AdditionalPageHead DelegateControl? That way you simplify things a lot more and you should have access to all the context you need from within your control.
I only write custom HttpModules if I can't think of any other solution that works.