从事件接收器重定向Sharepoint 2010(创建站点后)

问题描述 投票:1回答:2

我的问题是:在用户创建网站后的Sharepoint 2010中,首先我需要将用户重定向到我的自定义页面,而不是将用户重定向到新网站的网址。

我使用SPUtility.Redirect()创建了在我的页面上重定向后创建了web的事件接收器并尝试了网站:

public class MySiteEventReceiver : SPWebEventReceiver
{
    public override void WebProvisioned(SPWebEventProperties properties)
    {
        var web = properties.Web;
        base.WebProvisioned(properties);

        string url = web.Site.Url + "/_LAYOUTS/MyPage.aspx";
        SPUtility.Redirect(url, SPRedirectFlags.CheckUrl, HttpContext.Current);
    }
}

但总是HttpContext.Current为null。

我一直在寻找解决我的问题的方法在互联网上。我找到了它:qazxsw poi

我做的:

http://www.sharepointkings.com/2008/05/httpcontext-in-eventhandler.html

之后HttpContext不为null(我为WebProvisioned属性设置了Synchronous)

public class MySiteEventReceiver : SPWebEventReceiver
{
    private static HttpContext oContext;

    public SubSiteEventReceiver() : base()
    {
        if (oContext == null)
        {
            oContext = HttpContext.Current;
        }
    }
    public override void WebProvisioned(SPWebEventProperties properties)
    {
        var web = properties.Web;
        base.WebProvisioned(properties);

        string url = web.Site.Url + "/_LAYOUTS/MyPage.aspx";
        SPUtility.Redirect(url, SPRedirectFlags.CheckUrl, oContext);
    }
}

但在这种情况下,我得到错误“无法评估表达式,因为代码已优化或本机框架位于调用堆栈之上”。

我还试图采用另一种方式进行重定向。 <Synchronization>Synchronous</Synchronization>

但在这种情况下也没有什么不起作用。

我会很感激任何帮助的尝试!

asp.net sharepoint redirect sharepoint-2010 eventreceiver
2个回答
0
投票

您好,您可以尝试将其从事件接收器重定向到您的自定义页面

http://sharesilver.wordpress.com/2011/07/24/sharepoint-bugs-1-item-deleting-event-receiver/

有关详细信息,请查看此网址

properties.Status = SPEventReceiverStatus.CancelWithRedirectUrl; properties.RedirectUrl = "/_layouts/EventReceiver/CustomError.aspx";

如果工作,请告诉我。谢谢


0
投票

您需要添加构造函数来检索当前的httpcontext,否则您的上下文将始终为null。

请参阅以下示例:http://www.c-sharpcorner.com/uploadfile/anavijai/how-to-redirect-to-a-custom-page-for-event-receiver-in-sharepoint-2010/

© www.soinside.com 2019 - 2024. All rights reserved.