我的问题是重定向: 2010年SharePoint用户后创建网站,首先我需要用户重定向到我的自定义网页,而不是用户重定向到新的网站网址。SharePoint 2010中从事件接收器(创建网站后)
我创建的事件reciever网页和创建到我的网页上重定向使用SPUtility.Redirect()后试图网站:
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。
我一直在寻找我的问题在intrnet的解决方案。而且我发现它:http://www.sharepointkings.com/2008/05/httpcontext-in-eventhandler.html
我做到了:
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);
}
}
之后的HttpContext是不是空
<Synchronization>Synchronous</Synchronization>
(我的WebProvisioned性能同步设置),但在这种情况下,我得到错误“无法评估表达式,因为代码已经优化或者本机框架位于调用堆栈之上”。
我也试图去重定向的另一种方式。 http://sharesilver.wordpress.com/2011/07/24/sharepoint-bugs-1-item-deleting-event-receiver/
但在这种情况下也没有什么不工作。
我将是任何试图帮助感激不尽!
如果你能正确地获取上下文,然后,而不是使用SPUtility.Redirect的,你可以尝试oContext.Response.Redirect(“URL”,假的),第二个参数(假)很重要 – Mac