小编Jon*_*Jon的帖子

以编程方式删除Sitecore中的子布局

有谁知道如何从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)

.net c# sitecore sitecore6

3
推荐指数
1
解决办法
2273
查看次数

打开布局详细信息屏幕时是否会触发事件?

我想写一些在打开布局细节屏幕时触发的代码.是否有事件,某种API或某种方式来劫持Sitecore UI以允许我这样做?Sitecore.config事件中没有任何内容与帽子相关.

我想要做的是捕获我当前正在更新的项目的ID,以便稍后我可以在自定义控件中使用它.

我正在使用Sitecore 6.6.

c# asp.net sitecore sitecore6

2
推荐指数
2
解决办法
180
查看次数

PostAsJsonAsync 后 WebApi 方法中的对象为 null

我正在向 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)

c# asp.net-mvc http-post asp.net-web-api asp.net-web-api2

2
推荐指数
1
解决办法
6730
查看次数

暂时更改Sitecore项目的布局

使用此代码,我设法更改当前项目的渲染.然而,这在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)

我不想对项目进行永久性更改,我只想在满足某些条件的情况下动态替换当前显示的项目渲染.有谁知道如何以这种方式改变项目的布局?

.net c# sitecore sitecore6

1
推荐指数
1
解决办法
4983
查看次数

Identity Server 3 - invalid_scope

我正在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)

asp.net-mvc oauth oauth-2.0 openid-connect identityserver3

1
推荐指数
1
解决办法
4218
查看次数

以编程方式设置活动成员资格

我有一个带有自定义成员资格提供者的Web应用 我想要使​​用的提供程序连接到Progress数据库.

我有一个页面使用一个完全不同的会员提供商.我已经尝试通过web.config设置它但无法使其正常工作.

所以我想知道我是否可以通过编程方式为此页面设置成员资格提供程序.我在这里看到它在某种程度上是可能的,虽然这看起来非常h​​acky.我希望有一种干净的方式来做这种或那种方式.SO或更广泛的网络上的其他所有内容似乎都走到了尽头.这告诉我,我正在尝试的是不可能的,但是无论如何都知道它会很好.

是否可以在运行时简单地切换MembershipProvider?

.net c# asp.net asp.net-membership membership-provider

0
推荐指数
1
解决办法
3226
查看次数