问题
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
回答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>
回答2:
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.
来源:https://stackoverflow.com/questions/22773144/mvc-durandal-app-only-works-in-server-root-url