在一个webrole具有不同的web.config站点的多个实例 [英] Multiple instances of site in one webrole with different web.config

查看:110
本文介绍了在一个webrole具有不同的web.config站点的多个实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用相同的应用程序的多个物理站点我MVC3应用程序部署到Azure上。
这是伟大的,我可以用ServiceDefinition.csdef中的网站元素来做到这一点。

I would like to deploy my MVC3 app to Azure using multiple physical sites of the same app. It's great that I can use the sites element in ServiceDefinition.csdef to do this.

但我想每个站点连接到不同的数据库。连接字符串是在web.config中。有一个简单的方法来做到这一点,除了登录到虚拟机并手动改变呢?

But I want each of the sites to connect to a different database. The connection string is in the web.config. Is there an easy way to do this, besides logging into the vm and changing it by hand?

推荐答案

【答案您的评论] - 通过Windows Azure(实际上任何的PaaS解决方案)的拇指的第一条规则是,角色开始时所有的配置应该是准备和拇指的第二个规则是什么都不在VM通过RDP访问来完成,因为更改将不会持续。由于这种必需的配置无论是部署在Azure的包装或直接从启动任务修改。

[Answer to your comment] - With Windows Azure (actually with any PaaS solution) The first rule of thumb is that when the role starts all the configuration should be ready and the second rule of thumbs is that nothing should be done in VM through RDP access, because changes will not persist. Due to this required configuration either deployed in Azure Package or modified directly from start up task.

[回答您的问题]
在Windows Azure中,您可以运行一个Web角色中的多个站点但是他们都因为多个站点一台Web角色中运行应该分享同一个主web.config中。这里是你如何能做到这一点:
http://msdn.microsoft.com/en-us/library/windowsazure /gg433110.aspx

现在作为你的要求是有多个数据库,所以在你的web.config可以如下添加多个数据库连接字符串:
$

Now as your requirement is to have multiple databases, so in your web.config you can add multiple database connection string as below: $

 <ConnectionString>
 <Add name="DB1" connectionString="Data Source=DS1.........."/>
 <Add name="DB2" connectionString="Data Source=DS2.........."/>
 </ConnectionString>

一旦你有以上,在ASP.NET code可以列举这些连接字符串和在给定的例子描述的特定网站是:

once you have above, in your ASP.NET code you can enumerate these connection strings and use with specific sites as described in the given example:

http://www.dotnetspark.com/kb/780-how-to-use-multiple-database-connection.aspx

最后,你可以用你的Web角色发展过程中添加多个站点,也可以在web.config中指定特定的数据库连接,所以我不认为有任何需要使用启动任务的全部或做一些虚拟机,除非我我在这里失去了一些东西。

Finally, you can add multiple sites with your web role during development and can also have specific DB connection specified in web.config so I dont think there is any need to use startup task at all or do something in VM, unless i am missing something here.

这篇关于在一个webrole具有不同的web.config站点的多个实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆