This is Sitecore 9.3 and I'm trying to build an admin page to create a package programmatically.
The aspx page location is \wwwroot\mysite\sitecore\admin\minions\package.aspx

The method is triggered on a button click. It works fine when it is a postback. But if it is an ajax call , it throws an error when setting the active site.

Request is not available in this context

using (PackageWriter writer = new PackageWriter(fileNameWithPath))
                using (new SecurityDisabler())
                    Sitecore.Context.SetActiveSite("shell"); //error here
                    PackageGenerator.GeneratePackage(packageProject, writer);

Stack Trace:

at System.Web.UI.Page.get_Request() at Sitecore.UIUtil.IsWebkit()
at Sitecore.UIUtil.SupportsInlineEditing() at Sitecore.Sites.SiteContext.SetDisableWebEditEditing(String value)
at Sitecore.Sites.SiteContext..ctor(SiteInfo siteInfo, Boolean processQueryString) at Sitecore.Sites.DefaultSiteContextFactory.GetSiteContext(String name)
at Sitecore.Context.SetActiveSite(String siteName) at SitecoreCustomTools.sitecore.admin.minions.generatepackage.GeneratePackage(GeneratePackageDataModel generatePackageDataModel, String& statusMessage) at SitecoreCustomTools.sitecore.admin.minions.generatepackage.GenerateSitecorePackage(GeneratePackageDataModel generatePackageDataModel)

  • What is the full error? – Marek Musielak Mar 9 '20 at 8:49
  • @MarekMusielak, That is the full error message. Anyways, I have updated the stack trace. Could you please check. – Qwerty Mar 9 '20 at 9:16
  • I cannot think of any reason why request would not be available in the ajax call. Do you run any background job or try to execute some of the code async? – Marek Musielak Mar 9 '20 at 16:06
  • @MarekMusielak. No. If it is postback, the site is "shell" already & it works. But in ajax call, the site is "admin". And now, setting it to "shell" throws the error. – Qwerty Mar 10 '20 at 3:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.