我在我的应用程序中使用ASP.RavenDB-Embedded 2.0.2230与不同程序集中的 .Net Web API进行交互。
当我在文档存储上设置UseEmbeddedHttpServer = true
时,第一次向RavenDB发送请求时,它可以正常执行,但是当我第二次尝试时,我的应用程序显示Raven Studio。
当我删除UseEmbeddedServer
设置时,我的应用程序运行没有任何问题。
我的RavenDB在数据层配置了如下代码:
this.documentStore = new EmbeddableDocumentStore
{
ConnectionStringName = "RavenDB",
UseEmbeddedHttpServer = true
}.Initialize();
和Web.config
的实现在服务层中具有以下设置:
<connectionStrings>
<add name="RavenDB" connectionString="DataDir=~\App_Data\RavenDatabase" />
</connectionStrings>
有没有我错过的场景?
要将Raven Studio指向不同的端口,需要应用哪些设置?
发布于 2013-01-26 00:35:37
我可以重现你所描述的体验的唯一方法是故意制造端口冲突。默认情况下,RavenDB的web服务器托管在端口8080上,所以如果您没有更改raven的端口,那么您必须在端口8080上托管您的WebApi应用程序。如果不是这样,请在评论中告诉我,但我会假设是这样的。
要更改Raven使用的端口,只需在调用Initialize
方法之前修改端口值。
将此RavenConfig.cs
文件添加到您的App_Startup
文件夹:
using Raven.Client;
using Raven.Client.Embedded;
namespace <YourNamespace>
{
public static class RavenConfig
{
public static IDocumentStore DocumentStore { get; private set; }
public static void Register()
{
var store = new EmbeddableDocumentStore
{
UseEmbeddedHttpServer = true,
DataDirectory = @"~\App_Data\RavenDatabase",
// or from connection string if you wish
};
// set whatever port you want raven to use
store.Configuration.Port = 8079;
store.Initialize();
this.DocumentStore = store;
}
public static void Cleanup()
{
if (DocumentStore == null)
return;
DocumentStore.Dispose();
DocumentStore = null;
}
}
}
然后在Global.asax.cs
文件中,执行以下操作:
protected void Application_Start()
{
// with your other startup registrations
RavenConfig.Register();
}
protected void Application_End()
{
// for a clean shutdown
RavenConfig.Cleanup();
}
发布于 2013-01-28 21:58:43
在EmbeddableDocumentStore中启用HttpServer时,ravenDB会“劫持”When应用程序,并开始在应用程序运行的同一端口上进行侦听。
IIS :当您从
内部使用UseEmbeddedHttpServer时,它会从IIS获取端口。您需要重新设置该值
在https://groups.google.com/forum/?fromgroups=#!topic/ravendb/kYVglEoMncw上
防止这种情况的唯一方法是关闭raven http-server或将其分配到不同的端口。
int ravenPort = 8181;
NonAdminHttp.EnsureCanListenToWhenInNonAdminContext(ravenPort);
var ds = new EmbeddableDocumentStore {
DataDirectory = [DataFolder],
UseEmbeddedHttpServer = true,
Configuration = {Port = ravenPort}
};
https://stackoverflow.com/questions/13147077
复制相似问题