【发布时间】:2012-05-05 11:04:16
【问题描述】:
我的问题是: 在用户创建站点后的 Sharepoint 2010 中,首先我需要将用户重定向到我的自定义页面,而不是将用户重定向到新站点的 url。
我为网络创建了事件接收器,并在使用 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 为空。
我在 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 不为空(我为 WebProvisioned 属性设置了 Synchronous)
<Synchronization>Synchronous</Synchronization>
但在这种情况下,我收到错误 “无法评估表达式,因为代码已优化或本机框架位于调用堆栈顶部”。
我还尝试了另一种重定向方式。 http://sharesilver.wordpress.com/2011/07/24/sharepoint-bugs-1-item-deleting-event-receiver/
但是在这种情况下也没有什么是行不通的。
如果有任何帮助,我将不胜感激!
【问题讨论】:
-
如果你能够正确获取上下文,那么你可以试试oContext.Response.Redirect("url", false),而不是使用SPUtility.Redirect,第二个参数(false)很重要
标签: asp.net sharepoint redirect sharepoint-2010 eventreceiver