首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Uncaught :在IIS服务器子文件夹下运行时意外的角标记

Uncaught :在IIS服务器子文件夹下运行时意外的角标记
EN

Stack Overflow用户
提问于 2022-10-31 16:55:47
回答 1查看 72关注 0票数 0

我已经创建了角11模板(角11 + .Net核心5.0)使用VisualStudio2019。角应用程序应该从subfolder(caui)运行,而不是从根文件夹运行。我已经发布了have应用程序并部署在IIS中。但是我在浏览器中得到了跟踪错误。

代码语言:javascript
运行
复制
Uncaught SyntaxError: Unexpected token '<' (at runtime.js:1:1)
polyfills.js:1 Uncaught SyntaxError: Unexpected token '<' (at polyfills.js:1:1)
main.js:1 Uncaught SyntaxError: Unexpected token '<' (at main.js:1:1)
manifest.json:1 Manifest: Line: 1, column: 1, Syntax error.

下面是我的项目中的配置。

Index.html

代码语言:javascript
运行
复制
<!doctype html>
<html lang="en">

<head>
  <meta charset="utf-8" />
  <title>tester</title>
  <base href="/caui/" />
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <meta name="theme-color" content="#3dcd58" />
  <link rel="manifest" href="manifest.json" />
  <link rel="icon" type="image/x-icon" href="favicon.ico" />
  <link rel="apple-touch-icon" sizes="180x180" href="apple-touch-icon.png" />
</head>

<body>
  <!--[if lt IE 10]>
  <p>
    You are using an <strong>outdated</strong> browser.
    Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.
  </p>
  <![endif]-->
  <noscript>
    <p>
      This page requires JavaScript to work properly. Please enable JavaScript in your browser.
    </p>
  </noscript>
  <ses-app theme="auto">
    <app-root></app-root>
  </ses-app>
</body>

Angular.json

代码语言:javascript
运行
复制
{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "cli": {
    "analytics": false
  },
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "LowcostCAApp": {
      "projectType": "application",
      "schematics": {
        "@schematics/angular:component": {
          "style": "scss"
        },
        "@schematics/angular:application": {
          "strict": true
        }
      },
      "root": "",
      "sourceRoot": "src",
      "prefix": "app",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "baseHref": "/caui/",
            "deployUrl": "/caui/",
            "outputPath": "dist",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.app.json",
            "aot": true,
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/styles.scss"
            ],
            "scripts": []
          },
          "configurations": {
            "production": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "namedChunks": false,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "4mb",
                  "maximumError": "6mb"
                },
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "2kb",
                  "maximumError": "4kb"
                }
              ]
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "LowcostCAApp:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "LowcostCAApp:build:production",
              "baseHref": "/caui/",
              "servePath": "/caui/"
            }
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "LowcostCAApp:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "src/test.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.spec.json",
            "karmaConfig": "karma.conf.js",
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/styles.scss"
            ],
            "scripts": []
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "tsconfig.app.json",
              "tsconfig.spec.json",
              "e2e/tsconfig.json"
            ],
            "exclude": [
              "**/node_modules/**"
            ]
          }
        },
        "e2e": {
          "builder": "@angular-devkit/build-angular:protractor",
          "options": {
            "protractorConfig": "e2e/protractor.conf.js",
            "devServerTarget": "LowcostCAApp:serve"
          },
          "configurations": {
            "production": {
              "devServerTarget": "LowcostCAApp:serve:production"
            }
          }
        }
      }
    }
  },
  "defaultProject": "LowcostCAApp"
}

package.json

代码语言:javascript
运行
复制
"scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build  --prod --aot --base-href /caui/ --output-hashing none",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  }

.Net核Startup.cs

代码语言:javascript
运行
复制
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.SpaServices.AngularCli;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace ui
{
    public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllersWithViews();
            // In production, the Angular files will be served from this directory
            services.AddSpaStaticFiles(configuration =>
            {
                configuration.RootPath = "ClientApp/dist";
            });
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Error");
            }

            app.UseStaticFiles();
            if (!env.IsDevelopment())
            {
                app.UseSpaStaticFiles();
            }

            app.UseRouting();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller}/{action=Index}/{id?}");
            });

            app.UseSpa(spa =>
            {
                // To learn more about options for serving an Angular SPA from ASP.NET Core,
                // see https://go.microsoft.com/fwlink/?linkid=864501

                spa.Options.SourcePath = "ClientApp";

                if (env.IsDevelopment())
                {
                    spa.UseAngularCliServer(npmScript: "start");
                }
            });
        }
    }
}

Publishprofile.pubxml

浏览器网络选项卡跟踪

IIS服务器设置

我解决不了这个问题。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-11-03 14:36:40

我找到了解决办法。因为我们使index.html类似于子路径。<base href="/caui/" />

包被发布到Clientapp/dist/caui文件夹中。但是,应该将index.html放在Clientapp/dist文件夹位置以满足请求。

如果我将Index.html从caui文件夹移到外面,那么它就可以工作了。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74266696

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档