MVC Durandal应用程序仅适用于服务器根URL [英] MVC Durandal app only works in server root url

查看:115
本文介绍了MVC Durandal应用程序仅适用于服务器根URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我从Visual Studio 2013 Durandal模板创建项目并运行项目时,它会从我的开发Web服务器中提供Durandal Starter Kit Web的工作实例。



当我将其部署到IIS Web应用程序时,它会到达启动画面,然后停止。 Fiddler透露404尝试 GET /App/main.js HTTP / 1.1 这显然是它失速的原因。



<这带给我们的问题是:大概有些设置需要注意,但是在什么地方和哪里?这应该是 GET /c2/App/main.js HTTP / 1.1 或者可能 GET App / main.js HTTP / 1.1

解决方案

我不知道应该是我还是项目模板的作者感到尴尬。在Index.cshtml文件中,main.js由此行加载:

 < script type =text / javascript 
src =〜/ Scripts / require.js
data-main =/ App / main>
< / script>

真的吗?一个绝对的URL?



至少它很容易修复。



删除前导斜杠或向HTML添加基本标记,如下所示:

 < HTML> 
< head>
< base href =http:// myserver / path / to / app / root //>

你最好从 data-main中删除前导斜杠因为您可以使用相对路径发布到任何位置。我想你也可以为基本标签指定一个相对基数,但我从来没有对它进行过测试,反正还有更多的代码。

  < script type =text / javascript
src =〜/ Scripts / require.js
data-main =App / main>
< / script>


When I create a project from the Visual Studio 2013 Durandal template and run the project, it serves a working instance of the Durandal Starter Kit web out of my development web server.

When I deploy this to an IIS Web Application, it gets as far as the splash screen, and there it stalls. Fiddler reveals a 404 trying to GET /App/main.js HTTP/1.1 which clearly is the reason it stalls.

This brings us to the question: presumably there are settings requiring attention, but what and where? This should be GET /c2/App/main.js HTTP/1.1 or possibly GET App/main.js HTTP/1.1

解决方案

I don't know whether it should be me or the author of the project template to feel embarrassed. In the Index.cshtml file, main.js is loaded by this line:

<script type="text/javascript" 
        src="~/Scripts/require.js" 
        data-main="/App/main">
</script>

Really? An absolute URL?

At least it's easy to fix.

Either remove the leading slash or add a base tag to the HTML like this:

<html>
  <head>
    <base href="http://myserver/path/to/app/root/" />

You're better off removing the leading slash from data-main because with a relative path you can publish to any location. I suppose you could also specify a relative base for the base tag but I've never tested it and it's more code anyway.

<script type="text/javascript" 
        src="~/Scripts/require.js" 
        data-main="App/main">
</script>

这篇关于MVC Durandal应用程序仅适用于服务器根URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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