RavenDB Network Access

孤街浪徒 提交于 2019-12-09 04:19:55

问题


I'm having a difficult time finding information on how to get RavenDB to work on a network. Within the same network, I can have an instance of my app running, and it will show data from my RavenDB. However, when I try to write data, I get a 401 Unauthorized exception.

What is the correct way to set up a RavenDB to be accessed over the network?

Right now, I have this in Raven.Server.exe.config, which is just a short-term solution:

<add key="Raven/AnonymousAccess" value="All" />

What I don't understand, is that the RavenDB web site says to use something like this:

<connectionStrings>
  <add name="RavenDb" 
       connectionString="Url=http://serverName:8080;user=user;password=password"/>
</connectionStrings>

Ok, that's great for the application that's running, but how do I set the RavenDB server to allow that user and password? Is that just the wrong way to do it (somehow setting the RavenDB config file to allow those credentials)? If that's wrong, how am I supposed to define credentials on the server side?

Edit: Here are my attempts and results:

I'm running RavenDB by double-clicking Raven.Server.exe.

Scenario 1

Client app.Config:

  <connectionStrings>
    <add name="RavenDb" connectionString="Url = http://server:8080;domain=Xx;user=Xx\user;password=pw"/>
  </connectionStrings>

DocumentStore Setup:

DocumentStore documentStore = new DocumentStore();
documentStore.ConnectionStringName = "RavenDb";
documentStore.Initialize();

Save Operation:

Session.Store(objectToSave);

Result: "The remote server returned an error: (401) Unauthorized."

Scenario 2

Client app.config:

<add key="databaseUrl" value="http://server:8080"/>

DocumentStore Setup:

string databaseUrl = ConfigurationManager.AppSettings["databaseUrl"];            
DocumentStore documentStore = new DocumentStore();
documentStore.Url = databaseUrl;
documentStore.Initialize();

Save Operation:

Session.Store(objectToSave);

Result: "The remote server returned an error: (401) Unauthorized." Inner exception: "The target principal name is incorrect"


回答1:


Create a local user on the machine RavenDB runs on and use any credentials you'd like. Then assign read/write permissions for the /Data directory (and the /Tenants directory if needed) to this user.

If you're running RavenDB as a service or standalone application, remote auth should work with the (windows)users credentials. If you're running on IIS, please make sure you have Windows Authentication enabled (disabled by default!).




回答2:


For me, I had to add domain to the connection string on the prod machine, but NOT when accessing that same machine remotely... I dunno.

Of note: I created a windows user named RAVENDB, and assigned it full permissions to the data directory.

so my connection string that worked fine remotely was

<add name="raven" connectionString="Url=http://myserver.com:8080;user=RAVENDB;password=PASS" />

whereas on the actual server, i had to use

<add name="raven" connectionString="Url=http://myserver:8080;DOMAIN=MYSERVERNAME;user=RAVENDB;password=PASS" />



回答3:


Bob, By default, RavenDB uses Windows authentication. So if you create the user on the server machine, it would accept it. The alternative is to define ravendb specific users, but many people just use Windows Auth.



来源:https://stackoverflow.com/questions/8672237/ravendb-network-access

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!