문제

내 솔루션을 테스트하는 동안 기능 활성화에 오류가 발생합니다.

이전에 닫힌 SPWEB 객체에 대한 SPREQUEST 사용을 감지했습니다.그들로부터 얻은 모든 물체로 완료되면 spweb 객체를 닫으십시오.

이것은 내가 spweb를 얻는 방식입니다 :

public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
    using (SPWeb web = properties.Feature.Parent as SPWeb)
    {
        ClassOfMine.doYourStuff(web);
    }
}
.

무엇을 잘못하고 있습니까?

도움이 되었습니까?

해결책

어때요;

경고 : 해당 기능을 웹으로 범위 지정해야합니다.)

public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
  // No need to dispose the web istance, as indicated in the "Do not dispose" guidance
  SPWeb web = (SPWeb) properties.Feature.Parent; // added semicolon            

  ClassOfMine.doYourStuff(web);

}
.


사용하지 않는 기능 :

그렇지 않은 경우 spContext를 사용하여 루트 웹을 얻는 경우

SPContext.Current.Site.RootWeb
.

또는 - 현재 웹의 경우

SPContext.Current.Web
.

또는 - 특정 웹 URL

SPContext.Current.Site.OpenWeb("Website_URL"))
.


위의 기능을 사용하여 속성을 사용해야합니다.

특성을 사용하여 사이트를 얻으려면 rootweb

SPSite site = properties.Feature.Parent as SPSite;
using (SPWeb web = site.RootWeb)
{

}
.

또는 - 현재 웹의 경우

SPWeb web = properties.Feature.Parent as SPWeb;
.

또는 - 특정 웹 URL

SPSite site = properties.Feature.Parent as SPSite;
using (SPWeb web = site.OpenWeb("Website_URL"))
{

}
.

다른 팁

켜져 있습니다.기능의 범위 만 웹 여야합니다."상위"속성은 항상 기능 범위의 객체입니다.

또한 객체를 사용할 수 있습니다.

SPContext의 유일한 문제는 HTTP 컨텍스트가 없으므로 PowerShell에서 기능을 활성화 할 수 없다는 것입니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 sharepoint.stackexchange
scroll top