MVC Durandal app only works in server root url

2020-04-11 04:37发布

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

标签: iis durandal
2条回答
beautiful°
2楼-- · 2020-04-11 05:03

This will work regardless of the route. If you are using ASP.NET MVC - Razor.

data-main="@Url.Content("~/Scripts/app/main")"

Assuming that your file is located at c2/Scripts/app/main.js where c2 is your project folder.

查看更多
家丑人穷心不美
3楼-- · 2020-04-11 05:09

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>
查看更多
登录 后发表回答