我是ravendb.please的新手,请原谅我缺乏理解。首先,我创建了一个createUser函数。在这个函数中,我允许两个数据库(名为db1和db2)给用户。
public void createUser(DocumentStore documentStore, string userName, string password)
{
using (var session = documentStore.OpenSession())
{
AuthenticationUser user1 = new AuthenticationUser
{
Name = userName,
Id = "Raven/users/NewUser",
AllowedDatabases = new[] { "db1", "db2" },
Admin = true,
}.SetPassword(password);
session.Store(user1);
session.SaveChanges();
}
}
创建用户后,我想在凭据中创建该数据库中的文档但是在给出正确的凭据后,它给了我一个例外“远程服务器返回错误:(401)未经授权。”
public CreateDocumentResult CreateDocument(DocumentStore documentStore,string databaseName, string collectionName, string documentName)
{
NetworkCredential credential = new NetworkCredential("raj", "raj");
//documentStore.Credentials = credential;
var doc = documentStore.DatabaseCommands.ForDatabase(databaseName,credential);
var docExist = doc.Get(documentName);
DefaultD defaultDocument = new DefaultD();
if (docExist == null)
{
using (var session = documentStore.OpenSession(databaseName,credential))
{
Guid etag;
etag = Guid.NewGuid();
RavenJObject metadata=new RavenJObject();
metadata.Add("Raven-Entity-Name", collectionName);
createDocumentResult.FinalDocument=session.Advanced.DatabaseCommands.Put(documentName, etag, RavenJObject.FromObject(defaultDocument), metadata);
session.SaveChanges();
}
}
我从Ravendb认证视频中学到了这些东西。当然,有什么东西在那里我不知道。如何验证用户请告诉我的方式。谢谢你提前了很多