【问题标题】:An unhandled exception occurred while processing the request in .netcore在 .net 核心中处理请求时发生未处理的异常
【发布时间】:2018-10-09 06:26:46
【问题描述】:

我有 .net 核心应用程序正在开发中,它工作正常,但是当我发布我的应用程序并在 IIS 上部署时,它在图片下方显示错误。我在这个问题上花了 5 6 个小时,但没有成功任何人帮助我。为什么它在我误会任何人指导我的地方显示这个错误

  public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Error");
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseStaticFiles();
           // app.UseSpaStaticFiles();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{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");
                }
            });
        }

angular.json

  {
      "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
      "version": 1,
      "newProjectRoot": "projects",
      "projects": {
        "ClientApp": {
          "root": "",
          "sourceRoot": "src",
          "projectType": "application",
          "prefix": "app",
          "schematics": {},
          "architect": {
            "build": {
              "builder": "@angular-devkit/build-angular:browser",
              "options": {
                "outputPath": "dist/ClientApp",
                "index": "src/index.html",
                "main": "src/main.ts",
                "polyfills": "src/polyfills.ts",
                "tsConfig": "src/tsconfig.app.json",
                "assets": [
                  "src/favicon.ico",
                  "src/assets"
                ],
                "styles": [
                  "src/styles.css",
                  "node_modules/bootstrap/dist/css/bootstrap.min.css"
                ],
                "scripts": [
                  "node_modules/bootstrap/dist/js/bootstrap.min.js"

                ]
              },
              "configurations": {
                "production": {
                  "fileReplacements": [
                    {
                      "replace": "src/environments/environment.ts",
                      "with": "src/environments/environment.prod.ts"
                    }
                  ],
                  "optimization": true,
                  "outputHashing": "all",
                  "sourceMap": false,
                  //"extractCss": true,
                  "namedChunks": false,
                  "aot": true,
                  "extractLicenses": true,
                  "vendorChunk": false,
                  "buildOptimizer": true
                }
              }
            },
            "serve": {
              "builder": "@angular-devkit/build-angular:dev-server",
              "options": {
                "browserTarget": "ClientApp:build"
              },
              "configurations": {
                "production": {
                  "browserTarget": "ClientApp:build:production"
                }
              }
            },
            "extract-i18n": {
              "builder": "@angular-devkit/build-angular:extract-i18n",
              "options": {
                "browserTarget": "ClientApp:build"
              }
            },
            "test": {
              "builder": "@angular-devkit/build-angular:karma",
              "options": {
                "main": "src/test.ts",
                "polyfills": "src/polyfills.ts",
                "tsConfig": "src/tsconfig.spec.json",
                "karmaConfig": "src/karma.conf.js",
                "styles": [
                  "src/styles.css"
                ],
                "scripts": [],
                "assets": [
                  "src/favicon.ico",
                  "src/assets"
                ]
              }
            },
            "lint": {
              "builder": "@angular-devkit/build-angular:tslint",
              "options": {
                "tsConfig": [
                  "src/tsconfig.app.json",
                  "src/tsconfig.spec.json"
                ],
                "exclude": [
                  "**/node_modules/**"
                ]
              }
            }
          }
        },
        "ClientApp-e2e": {
          "root": "e2e/",
          "projectType": "application",
          "architect": {
            "e2e": {
              "builder": "@angular-devkit/build-angular:protractor",
              "options": {
                "protractorConfig": "e2e/protractor.conf.js",
                "devServerTarget": "ClientApp:serve"
              },
              "configurations": {
                "production": {
                  "devServerTarget": "ClientApp:serve:production"
                }
              }
            },
            "lint": {


       "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": "e2e/tsconfig.e2e.json",
            "exclude": [
              "**/node_modules/**"
            ]
          }
        }
      }
    }
  },
  "defaultProject": "ClientApp"
}

【问题讨论】:

  • 听起来您的 IIS 进程没有正确的权限。什么错误表明,它正在尝试运行 mkdir ... 命令并且它没有正确的权限这样做。我不能告诉你它为什么要在c:/windows/... 中创建一个目录,但是尝试使用 IIS 进程/容器/应用程序的权限
  • 你可以尝试用 vs 代码编译,看看会发生什么?我以前看过这个
  • 是的,它成功构建
  • 当我在 IIS 上部署代码时出现此错误

标签: angular .net-core asp.net-core-mvc angular6


【解决方案1】:

经过一天的研究,在这里找到了适合我的解决方案https://github.com/aspnet/AspNetCore/issues/5238 正如@boonmathew 所指出的那样。 解决方案是确保启动文件中的根路径

// In production, the Angular files will be served from this directory
services.AddSpaStaticFiles(configuration =>
{
   configuration.RootPath = "ClientApp/dist";
});

匹配 angular.json 文件中的输出路径 "outputPath": "dist",

由于您看到该消息,如果您使用右键单击发布,请确保将部署设置 ASPNETCORE_ENVIRONMENT 更改为生产

edit app settings

environment definition

这就是为我解决的问题。 祝你好运!

【讨论】:

    【解决方案2】:

    ./ 语句丢失

     "styles": [
                  "src/styles.css",
                  "node_modules/bootstrap/dist/css/bootstrap.min.css"
                ],
                "scripts": [
                  "node_modules/bootstrap/dist/js/bootstrap.min.js"
    
                ]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-21
      • 2021-02-20
      • 1970-01-01
      • 1970-01-01
      • 2012-01-20
      • 2020-06-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多