![](/img/trans.png)
[英]Download a file from a Claims auth based SharePoint 2010 site programmatically
[英]Sharepoint 2010 redirect from event receiver (after creating site)
我的问题是:在用户创建站点后的 Sharepoint 2010 中,首先我需要将用户重定向到我的自定义页面,而不是将用户重定向到新站点的 url。
我为 web 创建了事件接收器,并在使用 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 为空。
我在互联网上寻找我的问题的解决方案。 我找到了: 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 属性设置了同步)
<Synchronization>Synchronous</Synchronization>
但在这种情况下,我收到错误“无法评估表达式,因为代码已优化或本机框架位于调用堆栈的顶部”。
我还尝试采用另一种方式进行重定向。 http://sharesilver.wordpress.com/2011/07/24/sharepoint-bugs-1-item-deleting-event-receiver/
但在这种情况下,也没有什么不起作用。
如果您有任何帮助,我将不胜感激!
嗨,你可以试试这个从事件接收器重定向到你的自定义页面
properties.Status = SPEventReceiverStatus.CancelWithRedirectUrl;
properties.RedirectUrl = "/_layouts/EventReceiver/CustomError.aspx";
有关更多详细信息,请查看此网址
让我知道是否工作。 谢谢
您需要添加一个构造函数来检索当前的 httpcontext,否则您的上下文将始终为 null。
请参见以下示例: http : //social.technet.microsoft.com/Forums/en-US/sharepoint2010programming/thread/8cfcb299-9a55-4139-86ec-0b53b2922a54/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.