سؤال

أريد أن أقوم بما يلي.إذا كان المستخدم يأتي إلى مجموعة مواقع خاصة، فسيتم إعادة توجيهه إلى موقع فرعي.إذا كانت الفرعية غير موجودة فسيتم إنشاؤها.

أعلم أن هذا خلق في GetRequest واختبرت كل شيء بالفعل من InnSunSaFeUpdates إلى ValidateFormDigest ولكن لا شيء سيخلق الموقع بالنسبة لي.يجب أن أكون شيئا مثل mysitehost.

هل لديك فكرة عن كيفية القيام بذلك؟

هل كانت مفيدة؟

المحلول

Create a custom 404 page for your site collection, then either add code behind to it with your own logic as when you want to create a subsite and when not..

OR in SharePoint 2013 create a custom error page, add a content editor webpart to it, and some javscript code which will create a subsite for you, but there is a lot of things that you will require to set e.g. subsite name, url etc...

نصائح أخرى

I've stolen from the mysitehost. There the mysite is create with this mechanic:

 if (Page.IsPostBack)
 {
   SPLongOperation operation = new SPLongOperation(this.Page);
   operation.LeadingHTML = "Meeting wird erstellt";
   operation.Begin();
   SPUtility.ValidateFormDigest();

   Do site creation ...

   operation.End(currentMeeting.Url);
 }

 // This code sets an reloadAsPostBack on the site to begin site creation
 SPPageContentManager.RegisterClientScriptBlock(this.Page, base.GetType(), 
                      "CreateMySiteRepost", "document.forms[0].submit();");

When the page is loaded with GET Request then it will be posted by client code. Then you have a POST Request.

You can try setting the current HTTPContext as null, this way sharepoint does not recognise that it is a GET Request. Please see the below code, which worked for me:

using (SPSite site = new SPSite(SPContext.Current.Site.Url))
                {
                    using (SPWeb web = site.OpenWeb())
                    {
                        HttpContext tempContext = HttpContext.Current;//create back up of context.
                       HttpContext.Current = null;//Set current context as null
                        try
                        {

                            web.AllowUnsafeUpdates = true;
                            SPWeb newWeb = web.Webs.Add("sitename", "sitename", "description", (uint)1033, "STS#0", false, false);
                            web.Update();
                        }
                        catch (Exception Ex)
                        {
                            lblMessge.Text = Ex.Message;
                        }
                        finally
                        {
                            web.AllowUnsafeUpdates = false;
                            HttpContext.Current = tempContext;//Restore the context

                        }
                    }
                }
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى sharepoint.stackexchange
scroll top