c# - 如何为不同的 SQL Server 文件夹运行相同的 angularjs 应用程序(.NET MVC 5)?
问题描述
我对 AngularJS 和 SQL Server 配置问题非常陌生。
我使用 ASP.NET MVC 5 开发了 AngularJS 应用程序。基本上,前端基于 AngularJS,后端使用 C#。
一旦我们将应用程序放入 SQL Server 中,应用程序就会按预期工作。为了运行该应用程序,我从 Web.Config 文件中获取了 SurveyID = 1(例如)。
现在,我想为多个调查使用不同的 SurveyID 运行相同的应用程序。
a. The server folder is \\Survey with SurveyID = 1
b. The server folder is \\Survey2 with SurveyID = 2
c. The server folder is \\Survey3 with SurveyID = 3
d. The server folder is \\Survey4 with SurveyID = 4
即使应用程序放入不同的文件夹结构,应用程序始终会读取恰好是 \Survey 且 SurveyID = 1 的根文件夹
但是在 MVC Layout_Page 中,我使用的是 HTML 标签,我想知道这是否是根本问题的原因。
现在,我如何根据 Web.Config SurveyID 告诉 angularJS 应用程序哪个是根目录
我该如何解决这个问题?MVC HOME 控制器内部
DataAccessSurvey data;
int surveyID;
public HomeController()
{
data = new DataAccessSurvey();
surveyID = Convert.ToInt32(ConfigurationManager.AppSettings["SurveyId"]);
}
[HttpGet]
public ActionResult GetSurveyInfoData()
{
var surveyData = data.GetSurveyById(surveyID);
var Survey = new Survey();
//the rest of the code to populate the Survey related data
}
在 Angular Controller.jS 中,我调用以下方式
SurveyServices.getSurveyData()
.then(function (result) {
//alert("Success getSurveyData GetSurveyInfoData");
vm.SurveyInfo = result.data;
}
请帮帮我。提前致谢。
解决方案
看看这个 SO answer about embedding Web.Config values in your JavaScript code。具体来说,您可以使用.constant()
(此处的文档)将它们注册到您的 AngularJS 应用程序中,并将它们导入到您的组件或控制器中。
angular.module('myApp')
.constant('SurveyID', <%=ConfigurationManager.AppSettings["SurveyID"] %>)
.controller('MyCtrl', ['SurveyID', function(SurveyID) { ... }]);
推荐阅读
- java - 创建 n 大小的排列
- c++ - 如何每 X 秒创建一次线程,但前提是之前的迭代线程在 C++11 中完成?
- html - 为什么 HTML 中的文本周围有空格?
- python-3.x - 如何使用 python 中的新数据重新训练 AdaBoostClassifier?
- excel - 我在 excel 中制作奖牌以将一张纸连接到另一张纸
- php - 如何在 Laravel 6 中设置引导程序
- ionic3 - 电话号码插件问题
- android - 当用户在应用程序关闭时单击通知时无法从通知中获取价值
- kubernetes - 用于 Docker Registry 的 Spinnaker Jfrog Artifactory 集成
- javascript - 未找到 webpack es6 模块