gpt4 book ai didi

c# - Sitecore 7.2 - 项目 Web API - 用户身份验证

转载 作者:太空狗 更新时间:2023-10-29 21:33:40 25 4
gpt4 key购买 nike

我想限制 Sitecore Item Web API 仅向经过身份验证的用户发送数据,根据文档,我们需要在 http 请求 header 中将用户名和密码作为 X 传递-Scitemwebapi-用户名 & X-Scitemwebapi-密码

为此,我使用了以下代码:

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://scapidemo.local/-/item/v1/?sc_itemid={110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}&sc_database=master");

request.Headers["X-Scitemwebapi-Username"] = "admin";
request.Headers["X-Scitemwebapi-Password"] = "b";

HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Response.Write(String.Format("Content length is {0}", response.ContentLength));
Response.Write(String.Format("Content type is {0}", response.ContentType));
// Get the stream associated with the response.
Stream receiveStream = response.GetResponseStream();

// Pipes the stream to a higher level stream reader with the required encoding format.
StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8);

Response.Write("<br /> Response stream received. <br />");
Response.Write(readStream.ReadToEnd());

Sitecore.ItemWebApi.config 中,我为我的网站添加了如下设置:

itemwebapi.mode="StandardSecurity"
itemwebapi.access="ReadOnly"
itemwebapi.allowanonymousaccess="false"/>

现在在运行我的应用程序时出现此错误:

{"statusCode":401,"error":{"message":"Access to site is not granted."}}  

最佳答案

您正在传递没有所属域的用户。 ItemWebAPI 没有默认域,因此每次调用时都需要像这样传递用户“域\用户”。

综上所述 - 像这样尝试:

request.Headers["X-Scitemwebapi-Username"] = @"sitecore\admin";
request.Headers["X-Scitemwebapi-Password"] = "b";

关于c# - Sitecore 7.2 - 项目 Web API - 用户身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25383502/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com