在开发和生产环境中使用不同的Web.config

编程入门 行业动态 更新时间:2024-10-24 18:25:26
本文介绍了在开发和生产环境中使用不同的Web.config的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我需要使用不同的数据库连接字符串和SMTP服务器地址在我的ASP.NET应用程序,这取决于它是在开发或生产环境中运行。

I need to use different database connection string and SMTP server address in my ASP.NET application depending on it is run in development or production environment.

应用程序通过 WebConfigurationManager.AppSettings 属性。

我使用Build / Publish命令部署应用程序生产服务器通过FTP,然后手动替换远程Web.config与正确的。

I use Build/Publish command to deploy the application to production server via FTP and then manually replace remote Web.config with correct one.

是否可能以某种方式简化部署过程?感谢!

Is it possible somehow simplify the process of deployment? Thanks!

推荐答案

在Visual Studio 2010及更高版本中,您现在可以将变换应用于web.config

In Visual Studio 2010 and above, you now have the ability to apply a transformation to your web.config depending on the build configuration.

创建web.config时,您可以在解决方案资源管理器中展开该文件,您将看到两个文件:

When creating a web.config, you can expand the file in the solution explorer, and you will see two files:

  • Web.Debug.Config
  • Web.Release.Config

它们包含可用于

  • 更改连接字符串
  • 删除调试跟踪和设置
  • 注册错误页面

href =msdn.microsoft/en-us/library/dd465326(VS.100).aspx =nofollow noreferrer> Web.config Web应用程序项目部署的转换语法 MSDN获取更多信息。

See Web.config Transformation Syntax for Web Application Project Deployment on MSDN for more information.

尽管官方不支持,也可以对非web应用程序应用相同的转换 app.config 文件。请参阅 Phil Bolduc博客,了解如何修改您的项目文件向msbuild添加一个新任务。

It is also possible, albeit officially unsupported, to apply the same kind of transformation to an non web application app.config file. See Phil Bolduc blog concerning how to modify your project file to add a new task to msbuild.

这是一个很长的在Visual Studio Uservoice上请求。

一个 Visual Studio 2010的新扩展及更高版本, SlowCheetah 是可用于为任何配置文件创建转换。

A new extension for Visual Studio 2010 and above, "SlowCheetah," is available to take care of creating transform for any config file.

更多推荐

在开发和生产环境中使用不同的Web.config

本文发布于:2023-11-01 01:16:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1547825.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:环境   Web   config

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!