小编Ven*_*n R的帖子

发布到 IIS 后启用 CORS 不起作用

我将 dotnet core 2.2 web api 应用程序托管到本地 IIS。当我运行托管站点时,站点正在运行。我正在尝试从 angular 登录,但它不起作用。

它说访问 XMLHttpRequest at 'http://192.168.43.143:100/Auth/Login' from origin 'http://localhost:4200' has been Blocked by CORS policy: No 'Access-Control-Allow-Origin' header存在于请求的资源上。

注意:它在本地工作。没有发生 CORS 政策问题

我在 ConfigureServices 中添加了 cors 策略并提供中间件来添加 UseCors()。

public void ConfigureServices(IServiceCollection services)
{
   services.AddCors(c =>  
            {    
                c.AddPolicy("AllowOrigin", options => options.AllowAnyHeader()
                    .AllowAnyMethod().AllowAnyOrigin()
                    .SetIsOriginAllowed((host) => true).AllowCredentials());  
            });

   services.Configure<MvcOptions>(options => {
                options.Filters.Add(new CorsAuthorizationFilterFactory("AllowOrigin"));
            });
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
    app.UseCors("AllowOrigin");
    app.UseMvc();
}
Run Code Online (Sandbox Code Playgroud)

我安装的软件详细信息如下,

  • 系统:Windows 10
  • 点网核心 SDK:2.2.110 & 3.1.201
  • Windows 服务器托管:2.2.1 …

.net-core iis-10 asp.net-core-webapi

7
推荐指数
1
解决办法
6033
查看次数

npm 在多个环境上运行构建,没有提及指定的环境

我正在使用具有多个环境的角度项目。每当为单个环境进行构建需要很长时间时。我怎样才能减少它。我在这里添加了我的项目配置。

包.json:

{
  "name": "test",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "node --max_old_space_size=10240 ./node_modules/@angular/cli/bin/ng serve --aot",
    "build": "rimraf dist && node --max_old_space_size=10240 ./node_modules/@angular/cli/bin/ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "build:universal": "npm run build:client-and-server-bundles && npm run webpack:server",
    "serve:universal": "node dist/server.js",
    "build:client-and-server-bundles": "ng build --prod && ng build --prod --app 1 --output-hashing=false",
    "webpack:server": "webpack --config webpack.server.config.js --progress --colors",
    "postbuild": "node zipbuild"
  },
  "private": true,
  "dependencies": {
    "@angular-devkit/core": "7.3.3",
    "@angular/animations": "7.2.6",
    "@angular/cdk": "^7.3.3",
    "@angular/cli": "7.3.3", …
Run Code Online (Sandbox Code Playgroud)

npm angular

4
推荐指数
1
解决办法
7875
查看次数

标签 统计

.net-core ×1

angular ×1

asp.net-core-webapi ×1

iis-10 ×1

npm ×1