有谁知道如何从Sitecore项目中删除渲染?
我想删除所有子布局,以便我可以用新的替换它们.我试过这个,但它似乎没有用.该项目没有任何变化.
我似乎能够像这样得到渲染:
RenderingReference[] renderings = item.Visualization.GetRenderings(Sitecore.Context.Device, true);
Run Code Online (Sandbox Code Playgroud)
但似乎没有办法设置它们.
我也可以得到这样的效果图(来自上面的链接):
LayoutDefinition layoutDefinition = LayoutDefinition.Parse(LayoutField.GetFieldValue(item.Fields[Sitecore.FieldIDs.LayoutField]));
DeviceDefinition device = layoutDefinition.GetDevice(Sitecore.Context.Device.ID.ToString());
if (device.Layout != null) device.Layout = null;
if (device.Renderings != null) device.Renderings = new ArrayList();
Run Code Online (Sandbox Code Playgroud)
但这又不起作用.从layoutDefinition中清除设备并设置修改后的设备导致了这个异常:No connection could be made because the target machine actively refused it
.我现在根本无法查看该项目!
我觉得我正在吠叫错误的树,任何想法?
使用Sitecore 6.4
更新回复:techphoria414
我试过的代码:
layoutDefinition.Devices.Clear();
layoutDefinition.Devices.Add(device);
Run Code Online (Sandbox Code Playgroud) 我想写一些在打开布局细节屏幕时触发的代码.是否有事件,某种API或某种方式来劫持Sitecore UI以允许我这样做?Sitecore.config事件中没有任何内容与帽子相关.
我想要做的是捕获我当前正在更新的项目的ID,以便稍后我可以在自定义控件中使用它.
我正在使用Sitecore 6.6.
我正在向 WebApi 方法发布一个对象。我是PostAsJsonAsync
用来做这个的。
public async Task<HttpResponseMessage> PostAsync(string token, ServiceCall call)
{
var client = new HttpClient();
client.SetBearerToken(token);
var response = await client.PostAsJsonAsync(Uri + "id/nestedcall", call);
return response;
}
Run Code Online (Sandbox Code Playgroud)
call
当我发布它时,我传递的对象不为空。
[HttpPost]
[Route("id/nestedcall")]
public async Task<IHttpActionResult> NestedCall([FromBody]ServiceCall call)
{
// call is null here
}
Run Code Online (Sandbox Code Playgroud)
但是,它在我的 API 方法中为 null。我似乎无法弄清楚为什么我遵循的所有示例都使用这种格式。
为什么调用对象没有被 web api 拾取?
编辑
这里是ServiceCall
对象。它位于一个单独的类库中,并且 Web 应用程序和 API 中都包含一个引用。
public class ServiceCall
{
public ServiceCall(Service service, string grantType)
{
ClientId = service.Id;
ClientSecret = service.Secret;
Uri = …
Run Code Online (Sandbox Code Playgroud) 使用此代码,我设法更改当前项目的渲染.然而,这在Sitecore中永久性地改变了(变化可以在CMS中看到),而不是像我预期的那样暂时改变.
void ReplaceLayout(Item item)
{
if (item == null)
return;
using (new SecurityDisabler())
{
// New item
LayoutField newLayoutField = new LayoutField(item.Fields[Sitecore.FieldIDs.LayoutField]);
LayoutDefinition newLayoutDefinition = LayoutDefinition.Parse(newLayoutField.Value);
DeviceDefinition newDeviceDefinition = newLayoutDefinition.GetDevice(Sitecore.Context.Device.ID.ToString());
// Current item
LayoutField layoutField = new LayoutField(Sitecore.Context.Item.Fields[Sitecore.FieldIDs.LayoutField]);
LayoutDefinition layoutDefinition = LayoutDefinition.Parse(layoutField.Value);
DeviceDefinition deviceDefinition = layoutDefinition.GetDevice(Sitecore.Context.Device.ID.ToString());
deviceDefinition.Layout = newDeviceDefinition.Layout;
deviceDefinition.Renderings = newDeviceDefinition.Renderings;
Sitecore.Context.Item.Editing.BeginEdit();
layoutField.Value = layoutDefinition.ToXml();
Sitecore.Context.Item.Editing.EndEdit();
}
}
Run Code Online (Sandbox Code Playgroud)
我不想对项目进行永久性更改,我只想在满足某些条件的情况下动态替换当前显示的项目渲染.有谁知道如何以这种方式改变项目的布局?
我正在Identity Server 3中实现AuthorizationCode流程.
当我登录时,我得到一个invalid_scope
例外.
这是我的客户:
new Client
{
Enabled = true,
ClientName = "Web Application",
ClientId = "webapplication",
Flow = Flows.AuthorizationCode,
ClientSecrets = new List<Secret>
{
new Secret("webappsecret".Sha256())
},
RedirectUris = new List<string>
{
UrlManager.WebApplication
},
PostLogoutRedirectUris = new List<string>
{
UrlManager.WebApplication
},
AllowedScopes = new List<string>
{
Constants.StandardScopes.OpenId,
Constants.StandardScopes.Profile,
Constants.StandardScopes.Email,
Constants.StandardScopes.Roles,
Constants.StandardScopes.OfflineAccess
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的创业公司:
app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
{
Authority = UrlManager.AuthenticationService + "identity",
ClientId = "webapplication",
Scope = "openid profile offline_access",
ResponseType = "code",
RedirectUri = UrlManager.WebApplication, …
Run Code Online (Sandbox Code Playgroud) 我有一个带有自定义成员资格提供者的Web应用 我想要使用的提供程序连接到Progress数据库.
我有一个页面使用一个完全不同的会员提供商.我已经尝试通过web.config设置它但无法使其正常工作.
所以我想知道我是否可以通过编程方式为此页面设置成员资格提供程序.我在这里看到它在某种程度上是可能的,虽然这看起来非常hacky.我希望有一种干净的方式来做这种或那种方式.SO或更广泛的网络上的其他所有内容似乎都走到了尽头.这告诉我,我正在尝试的是不可能的,但是无论如何都知道它会很好.
是否可以在运行时简单地切换MembershipProvider?