Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 无法识别的配置节system.webServer。(用于角型芯-角型)_Angular_Asp.net Core - Fatal编程技术网

Angular 无法识别的配置节system.webServer。(用于角型芯-角型)

Angular 无法识别的配置节system.webServer。(用于角型芯-角型),angular,asp.net-core,Angular,Asp.net Core,我试图在Asp.Net core api文件中集成angular,但在访问/调用api(.core)时,显示了以下错误。已经通过了不同的链接,不知道确切的原因,这导致了错误 // "error": { "innerExceptionMessage": "Failed to read the config section for authentication providers.", "mess

我试图在Asp.Net core api文件中集成angular,但在访问/调用api(.core)时,显示了以下错误。已经通过了不同的链接,不知道确切的原因,这导致了错误

//
 "error": {
        "innerExceptionMessage": "Failed to read the config section for authentication providers.",
        "message": "The type initializer for 'Microsoft.Data.SqlClient.SqlAuthenticationProviderManager' threw an exception.",
        "exception": "TypeInitializationException"
    }
}
// in Inner Exception
Unrecognized configuration section system.webServer. (D:\WorkSpace\API\API_New\bin\Debug\netcoreapp3.1\project.dll.config line 4)
相关代码如下所示:

app.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>

    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Angular Routes" stopProcessing="true">
                    <match url="./*" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />
                    </conditions>
                </rule>
            </rules>
        </rewrite>
    </system.webServer>

</configuration>

我正在显示上面的配置,因为错误显示在

我缺少的内容请与我分享相关想法/链接和代码。

您的开发计算机上缺少IIS服务器的URL重写扩展,因此无法识别配置的重写规则部分

您有两种选择:

  • 安装URL重写扩展

  • 删除或注释掉web.config中的“重写规则”部分。也许您根本不需要开发机器上的URL重写功能


  • 尝试了第二个选项,但仍然显示上述错误。您现在添加的第二个错误与第一个错误无关,因此注释掉“重写规则”部分就成功了。也许第二个错误应该在另一个问题中。明白了。。那里几乎没有字符空间。。现在这个工作很好。谢谢@Nenad
      public class Startup
        {
            public Startup(IConfiguration configuration, IWebHostEnvironment env)
            {
                Configuration = configuration;
                Environment = env;
            }
    
            public IConfiguration Configuration { get; }
            private IWebHostEnvironment Environment { get; }
            public string MyAllowSpecificOrigins { get; private set; }
    
            // This method gets called by the runtime. Use this method to add services to the container.
            public void ConfigureServices(IServiceCollection services)
            {
                services.AddCors(options =>
                {
                    options.AddDefaultPolicy(
                                      builder =>
                                      {
                                          builder.WithOrigins("http://localhost:50040/"
                                                              ).AllowAnyMethod().AllowAnyOrigin().AllowAnyHeader();
                                      });
                });
    
                services.AddControllers();
                string constring = Configuration.GetConnectionString("DefaultConnection");
                services.AddDbContext<SRCSContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
    
                // In Dev Mode we will use the ClientApp at the root level
                if (Environment.IsDevelopment())
                {
                    services.AddSpaStaticFiles(configuration =>
                    {
                        configuration.RootPath = "SRCS-Web/dist";
    
                    });
                }
                else
                {
                    // In production, the Angular files will be served from this directory
                    services.AddSpaStaticFiles(configuration =>
                    {
                        configuration.RootPath = "publish/SRCS-Web/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");
                    // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                    app.UseHsts();
                }
    
                app.UseMiddleware<ExceptionHandler>();
                app.UseHttpsRedirection();
                if (!env.IsDevelopment())   
                {
                    
                    app.UseSpaStaticFiles();
                }
    
                app.UseRouting();
                app.UseCors();
                app.UseAuthorization();
    
                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 = "SRCS-Web";
    
                    if (env.IsDevelopment())
                    {
                        //Configure the timeout to 3 minutes to avoid "The Angular CLI process did not start listening for requests within the timeout period of 50 seconds." issue
                        spa.Options.StartupTimeout = new TimeSpan(0, 6, 30);
                        spa.UseAngularCliServer(npmScript: "start");
                    }
                });
            }
        }
    }