这是一个aspnet核心+角度2项目。 我的网站无法在托管环境中找到(404 Not Found)js文件。它在VS2015的开发环境中运行良好。
在我的开发环境中,我的angluar2文件位于我的aspnetcore_project_directory / wwwroot / app文件夹下。
angular2的主要app文件位于aspnetcore_project_directory / wwwroot / app / main.js
内容systemjs.config.js
/**
* System configuration for Angular samples
* Adjust as necessary for your application needs.
*/
(function (global) {
System.config({
paths: {
// paths serve as alias
'npm:': 'node_modules/'
},
// map tells the System loader where to look for things
map: {
// our app is within the app folder
app: 'app',
// angular bundles
'@angular/core': 'npm:@angular/core/bundles/core.umd.js',
'@angular/common': 'npm:@angular/common/bundles/common.umd.js',
'@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
'@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
'@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
'@angular/http': 'npm:@angular/http/bundles/http.umd.js',
'@angular/router': 'npm:@angular/router/bundles/router.umd.js',
'@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',
// other libraries
'rxjs': 'npm:rxjs',
'angular-in-memory-web-api': 'npm:angular-in-memory-web-api'
},
// packages tells the System loader how to load when no filename and/or no extension
packages: {
app: {
main: 'main.js',
defaultExtension: 'js'
},
rxjs: {
defaultExtension: 'js'
},
'angular-in-memory-web-api': {
main: 'index.js',
defaultExtension: 'js'
}
}
});
})(this);
当我在vs2015的开发环境中进行测试时,此设置很好。 我将发布的内容复制到IIS。这里的文件夹结构是 inetpub \ wwwroot \ myprj 所以在 inetpub \ wwwroor \ myprj \ wwwroot \ app 下我有角文件。
我以
启动我的网站http://example.com/myprj
并且所有与aspnet相关的代码都正确加载。但是当它试图加载角度模块时,它试图从
加载main.jshttp://example.com/app/main.js
而不是
http://example.com/myprj/wwwroot/app/main.js
我不确定如果我没有将文件复制到正确的位置,或者没有在systemjs文件中正确引用它们,或者两者都没有..
的index.html
<!DOCTYPE html>
<html>
<head>
<base href="/">
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Index - myprj</title>
<link rel="stylesheet" href="/myprj/lib/bootstrap/dist/css/bootstrap.css" />
<link rel="stylesheet" href="/myprj/css/site.css" />
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/myprj">myprj</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li><a href="/myprj/SiteManager">Stats</a></li>
<li><a href="/myprj">Home</a></li>
<li><a href="/myprj/Home/About">About</a></li>
<li><a href="/myprj/Home/Contact">Contact</a></li>
</ul>
<form method="post" id="logoutForm" class="navbar-right" action="/myprj/Account/LogOff">
<ul class="nav navbar-nav navbar-right">
<li>
<a title="Manage" href="/myprj/Manage">Hello padhu@adsc.com!</a>
</li>
<li>
<button type="submit" class="btn btn-link navbar-btn navbar-link">Log off</button>
</li>
</ul>
<input name="__RequestVerificationToken" type="hidden" value="CfDJ8KehTnO-SvNKgU7UYNtLOEZOnq1O6ETchwbvuVHy4sOk8JDjACikATgFczHo5p0CZiGbPYRpa4cZ0Kx43DFrV9JidqSTjTMdAFcAu_YBlXl54-m0NRAvtOVIZudX7Rm7MD7y006yAcfujAaPK72-j2AGf2L50f7CSxpUyH964Mi22A4IxgVgerkO9aja_rYEow" /></form>
</div>
</div>
</div>
<div class="container-fluid body-content">
<!-- Css -->
<link rel="stylesheet" href="/myprj/css/site.css" /><link rel="stylesheet" href="/myprj/css/site.min.css" /><link rel="stylesheet" href="/myprj/css/spinkit.css" />
<!-- Js -->
<script src="/myprj/lib/jQuery/dist/jquery.js"></script>
<script src="/myprj/node_modules/systemjs/dist/system.js"></script>
<script src="/myprj/node_modules/core-js/client/shim.js"></script>
<script src="/myprj/node_modules/zone.js/zone.js"></script>
<script src="/myprj/node_modules/reflect-metadata/reflect.js"></script>
<!-- Configure SystemJS -->
<script src="/myprj/js/systemjs.config.js"></script>
<script>
System.import('app').catch(function(err){ console.error(err); });
</script>
<my-app>Loading...</my-app>
<hr />
<footer>
<p>© 2016 - myprj</p>
</footer>
</div>
<script src="/myprj/lib/jquery/dist/jquery.js"></script>
<script src="/myprj/lib/bootstrap/dist/js/bootstrap.js"></script>
<script src="/myprj/js/site.js?v=PO_8e6bIDi7De8_fdNEN0tfEE9tOM_13R3l4268U5_Y"></script>
</body>
</html>
答案 0 :(得分:0)
由于网站在子目录中运行,我不得不更改_Layout.cshtml文件中的 base 。
从
更改了它<base href="/">
到
<script>
document.write('<base href="' + document.location + '" />');
</script>
由于托管在子目录中,这几乎解决了所有参考问题。