听起来您有一行标记和源代码作为字符串存储在数据库表中的某个位置?
您是否考虑过将这些数据/代码/值移动到 web.config 中?
考虑将您的环境配置设置存储在 web.config 中。即
<appSettings>
<add Name="IsProduction" value="true" />
<add Name="RequiresSecure" value="true" />
您的控制器和模型可以读取这些值,并将环境设置传递给视图。
当您写出这些常见问题条目时,您可以使用简单的if 修改输出。
<% if (Model.IsProduction) //have your ViewModel pass along whether you're in Production mode, Dev mode, URLs to have SSL, or whatever criteria you like, etc.
{%>
<!-- my production markup, with image URL, SSL'd etc. -->
<img src="https://mysite.com/img.png" />
<%}
else {%>
<!-- my other Dev markup, with image URL, etc. -->
<img src="https://myDevServer/img.png" />
<%} %>
将代码保留在数据库中通常被认为是一种不好的做法,甚至是一种dub-tee-eff。考虑“将数据保存在数据库中”的规则。