【问题标题】:Publishing ASP.NET MVC/AngularJS Application发布 ASP.NET MVC/AngularJS 应用程序
【发布时间】:2015-12-16 22:05:41
【问题描述】:

我正在开发一个带有 AngularJS 前端的 ASP.NET MVC 应用程序,它在从 Visual Studio/iis express 运行时运行良好,但当我尝试发布它以便其他用户可以访问它时效果不是很好(例如,在浏览器中导航到 http://server/application)。我在服务器上配置了 IIS,以便 http://server/application 指向一个“应用程序”文件夹,该文件夹的结构如下:

application
    app
        areas
        foundation
        main
            layout
                layout.html
    bin
    Content
    fonts
    Scripts
    Templates
    Views
        Shared
            _Layout.cshtml
            Index.cshtml
    Logs
    Global.asax
    web.config

初始页面 Index.cshtml(在 Views/Shared/ 下)已加载,但包含以下内容:

<div ng-include="'app/main/layout/layout.html'"></div>

返回 500.24 - 内部服务器错误。

如果我将 ng-include 更改为:

<div ng-include="'application/app/main/layout/layout.html'"></div>

然后发布的应用程序可以工作,但从 Visual Studio/iis express 运行它会返回 404.0 - 尝试加载该 layout.html 文件时未找到响应,我假设是因为它运行时没有父“应用程序”文件夹使用iisexpress。

我确实设法通过将已发布的应用程序文件夹的内容复制到服务器的 C:\inetpub\wwwroot 文件夹来使已发布的应用程序在某一时刻正常工作,但这似乎不是一个合适的解决方案,那么最好的方法是通知 Angular 查找此 ng-include 的正确位置?

【问题讨论】:

    标签: angularjs asp.net-mvc iis-7.5


    【解决方案1】:

    我最终做的是在我的 web.config 文件中添加一个应用程序路径变量,并在我的所有 ng-include 或其他 URL 前加上应用程序路径,所以它们看起来像

    <div ng-include="'application/app/main/layout/layout.html'"></div>
    

    然后将我的项目 Web 属性更新为以下内容:

    这样无论我是发布它还是通过 Visual Studio 运行它,它都在“应用程序”文件夹下运行,并在适当的位置查找 html 文件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-01
      相关资源
      最近更新 更多