基于带有C#MVC的开发环境的不同url [英] Different url based on development environment with C# MVC

查看:46
本文介绍了基于带有C#MVC的开发环境的不同url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个MVC Web应用程序,分别是www.company.com和solution.company.com

I have two MVC web applications, a www.company.com and a solution.company.com

网站www.company.com包含指向solution.company.com/Contact的链接,但是如何在视图中设置href以便能够在开发/预生产/生产环境中对其进行测试?

The website www.company.com include links to solution.company.com/Contact but how can I set the href in the View to be able to test them in the development/pre-production/production environments?

开发:

<a href="http://localhost:88/Contact/">Contact Us</a> 

质量检查:

<a href="http://qa.solution.company.com/Contact/">Contact Us</a> 

珠三角:

<a href="http://solution.company.com/Contact/">Contact Us</a> 

推荐答案

您可以使用web.config设置不同的变量.对每个环境使用单独的web.config.例如. web.release和web.debug.您可以使用相同的方式.每种环境使用单独的文件

You can use web.config to set different variables. Use separate web.config for each environment. Eg. web.release and web.debug. Same way you can use. Separate files for each environment

如果使用八达通部署.使用也可以在章鱼变量中设置.

If you use, Octopus deployment. Use can set in octopus variables also.

<appSettings>
  <add key="MyVariable1" value="False" />
  <add key="MyName" value="akshay bheda" />
</appSetting>

现在,您可以轻松地从C#代码中访问此变量及其值:

Now you can easily access this variable and its value from your C# code:

string myVariable = System.Configuration.ConfigurationSettings.AppSettings["MyName"];

现在,您可以使用此字符串代替在那儿写url.

Now instead of writing url there, you can use this string instead.

<a href="<%= ConfigurationManager.AppSettings["someKey"] %>">

如果您不想使用章鱼部署",则可以执行以下步骤.

If you don't want to use Octopus Deployment, You can follow below steps.

1.)从配置管理器中创建新的配置.它位于构建"菜单下. 并创建一个新的配置,例如.生产 并从Debug或其他任何现有的web.config中选择复制设置",因此您无需再次编写.

1.) Create new Configuration from Configuration Manager. It is located under Build Menu. and create a new configuration say for eg. Production and select Copy settings from Debug or any other present web.config so you don't have to write again.

2.)创建新配置后,右键单击Web.config,然后单击添加配置转换 之后,您将找到新配置的web.config.

2.) After creating a new configuration, Right click on Web.config and click Add Config Transformation after that you will find your new configuration's web.config.

在每个配置的 appSettings 部分中进行更改,并在启动项目时选择构建配置.

Make the changes in the appSettings section in each of your config and while starting the project, select your build configuration.

它将从相应配置的 appSettings 部分获取配置设置.

It will take the configuration settings from your appSettings section from that respective config.

这篇关于基于带有C#MVC的开发环境的不同url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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