gpt4 book ai didi

SharePoint 2010 : feature receiver code executed from UI, 不是来自 PowerShell 或 stdadm

转载 作者:行者123 更新时间:2023-12-03 10:03:26 25 4
gpt4 key购买 nike

我有一个包含 Web 范围功能的 WSP,代码如下:

using System;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Security;

namespace Macaw.DualLayout.Samples.Features.DualLayoutSampleEmpty_Web
{
[Guid("8b558382-5566-43a4-85fa-ca86845b04b0")]
public class DualLayoutSampleEmpty_WebEventReceiver : SPFeatureReceiver
{
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
using (SPWeb web = (SPWeb)properties.Feature.Parent)
{
using (SPSite site = (SPSite)web.Site)
{
Uri uri = new Uri(site.Url + "/_catalogs/masterpage/DLSampleEmpty.master");
web.CustomMasterUrl = uri.AbsolutePath; // Master for all publishing pages
web.Update();
}
}
}

public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
{
using (SPWeb web = (SPWeb)properties.Feature.Parent)
{
using (SPSite site = (SPSite)web.Site)
{
Uri uri = new Uri(site.Url + "/_catalogs/masterpage/v4.master");
web.CustomMasterUrl = uri.AbsolutePath; // Master for all publishing pages
web.Update();
}
}
}
}
}

我从 Visual Studio 2010 进行 F5 部署。
当我从 UI 激活该功能时,我进入了功能代码中的断点,该功能代码将被执行。
当我从 PowerShell 激活该功能时:
Enable-SPFeature -Url http://myserver/sites/publishing/empty -Identity MyFeatureName -force -verbose

或使用 STSADM:
stsadm -o activatefeature -name MyFeatureName -url http://myserver/sites/Publishing/Empty -force

我看到该功能已激活(在 UI 中),但我没有达到断点,并且未执行功能接收器代码。

有任何想法吗?

最佳答案

如果您使用 powershell 或 stsadm,该功能将不会在 IIS 工作进程的上下文中运行。调试时将 VS Studio 附加到什么?

在调试 stsadm 任务时,我通常添加:
System.Diagnostics.Debugger.Launch();
到代码,当命令运行时,系统会提示您附加调试器。粗暴但容易。 (不要忘记删除)

关于SharePoint 2010 : feature receiver code executed from UI, 不是来自 PowerShell 或 stdadm,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3793780/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com