My issue is: In Sharepoint 2010 after user create site, at first I need to redirect user to my custom page and not to redirect user to url of new site.
I created event reciever for web and tried site after creating to redirect on my page with using 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);
}
}
But always HttpContext.Current is null.
I was looking for the solution of my problem in the intrnet. And I found it: http://www.sharepointkings.com/2008/05/httpcontext-in-eventhandler.html
I did it:
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);
}
}
After that HttpContext was not null ( I set for WebProvisioned properties Synchronous)
<Synchronization>Synchronous</Synchronization>
But in this case I get error "Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack".
I also tried to go another way for redirect. http://sharesilver.wordpress.com/2011/07/24/sharepoint-bugs-1-item-deleting-event-receiver/
But in this case also nothing doesn't work.
I would be grateful for any attempt to help!