简体   繁体   English

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

[英]Sitecore 7.2 - Item Web API-User Authentication

I want to restrict the Sitecore Item Web API to send data to authenticated user only & as per the documentation,we need to pass the user name & password in http request header as X-Scitemwebapi-Username & X-Scitemwebapi-Password 我想限制Sitecore Item Web API仅向经过身份验证的用户发送数据,并且根据文档,我们需要在http request header传递用户名和密码,如X-Scitemwebapi-UsernameX-Scitemwebapi-Password

To achieve this,I used below code: 为此,我使用下面的代码:

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());

In Sitecore.ItemWebApi.config I've added setting for my website as below: Sitecore.ItemWebApi.config我为我的网站添加了如下设置:

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

Now while running my app I'm getting this error: 现在,在运行我的应用程序时,我收到此错误:

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

You are passing the user without the domain it belongs to. 您传递的用户没有它所属的域。 The ItemWebAPI does not have a default domain so every time you make you make a call you need to pass your user like this "domain\\user\u0026quot;. ItemWebAPI没有默认域名,因此每次拨打电话时都需要通过用户“域\\用户”。

All that said - try it like this: 所有这一切 - 试试这样:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Sitecore-Web Api用户身份验证 - Sitecore-Web Api User authentication 如何使用项目Web API在SiteCore 6.5中创建媒体项目 - How to create a media item in sitecore 6.5 using item web api 解析从Sitecore Item Web API返回的JSON - Parsing JSON returned from the Sitecore Item Web API 具有自定义用户数据库的Web API令牌身份验证 - Web API token authentication with a custom user database Web API和Angular 5令牌身份验证 - 登录后获取用户信息 - Web API and Angular 5 Token Authentication - Get user info after log in 使用MVC4 Web API创建全局用户身份验证系统 - Creating a Global user authentication system using MVC4 web api 在C#Web API上进行用户身份验证的最佳做法是什么? - What is the best practice for user authentication on a C# web api? WEB API表单身份验证 - 我在哪里可以为用户设置角色 - WEB API Forms Authentication - Where can i set Roles for a User 在REST WCF Web API中使用Windows身份验证对用户进行身份验证 - Authenticate User using Windows Authentication in REST WCF Web API Web API:使用Windows身份验证在上下文用户下创建对数据库的查询 - Web API: create query to database under context user with Windows authentication
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM