简体   繁体   English

IIS上的Web API说连接被拒绝

[英]Web API on IIS says Connection Refused

I am working on a project which has 2 aspects: Web UI (Angular 5) and Web API (.NET Core 2.0) for backend database I am using MySql Engine. 我正在研究一个包含两个方面的项目:后端数据库的Web UI(Angular 5)和Web API(.NET Core 2.0)我正在使用MySql Engine。

I have hosted the Web UI as well as the Web API on the same VM machine on different ports. 我已经在不同端口的同一台VM机器上托管了Web UI和Web API。 Angular Website is running on the default port 80 and API is hosted on the port number 8000. Angular网站在默认端口80上运行,API在端口号8000上托管。

I am able to load the website home page properly on the network. 我可以在网络上正确加载网站主页。 But when my website make a call to the API on PORT 8000. It is throwing Connection refused error in chrome console. 但是,当我的网站在PORT 8000上调用该API时,它在chrome控制台中引发“连接被拒绝”错误。 eg: net::ERR_CONNECTION_REFUSED 例如:net :: ERR_CONNECTION_REFUSED

My website is using the an SSL certificate but my API is not. 我的网站使用的是SSL证书,但我的API未使用。 I have configured the API URL as localhost:8000 only in my angular website. 我仅在我的网站localhost:8000 API URL配置为localhost:8000

In my API startup.cs, i have configurations as follows: 在我的API startup.cs中,我的配置如下:

public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();
            services.AddCors(options =>
            {
                options.AddPolicy("AllowAllOrigins",
                    builder => builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader().AllowCredentials());
            });

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

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            env.ConfigureNLog("nlog.config");
            app.UseCors("AllowAllOrigins");
            app.UseMvc();
            loggerFactory.AddNLog();
       }

My web Application is working fine in my local environment. 我的Web应用程序在我的本地环境中运行良好。 But when i am hosting it on the VM, it is not connecting to my API. 但是,当我将其托管在VM上时,它没有连接到我的API。

I get below error: 我得到以下错误:

core.js:3121 Angular is running in the development mode. Call enableProdMode() to enable the production mode.
zone.js:2969 OPTIONS http://localhost:8000/api/authentication net::ERR_CONNECTION_REFUSED
scheduleTask @ zone.js:2969
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.scheduleTask @ zone.js:407
onScheduleTask @ zone.js:297
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.scheduleTask @ zone.js:401
push../node_modules/zone.js/dist/zone.js.Zone.scheduleTask @ zone.js:232
push../node_modules/zone.js/dist/zone.js.Zone.scheduleMacroTask @ zone.js:255
scheduleMacroTaskWithCurrentZone @ zone.js:1114
(anonymous) @ zone.js:3001
proto.(anonymous function) @ zone.js:1394
(anonymous) @ http.js:1629
push../node_modules/rxjs/_esm5/internal/Observable.js.Observable._trySubscribe @ Observable.js:43
push../node_modules/rxjs/_esm5/internal/Observable.js.Observable.subscribe @ Observable.js:29
(anonymous) @ subscribeTo.js:21
subscribeToResult @ subscribeToResult.js:11
push../node_modules/rxjs/_esm5/internal/operators/mergeMap.js.MergeMapSubscriber._innerSub @ mergeMap.js:74
push../node_modules/rxjs/_esm5/internal/operators/mergeMap.js.MergeMapSubscriber._tryNext @ mergeMap.js:68
push../node_modules/rxjs/_esm5/internal/operators/mergeMap.js.MergeMapSubscriber._next @ mergeMap.js:51
push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next @ Subscriber.js:54
(anonymous) @ scalar.js:5
push../node_modules/rxjs/_esm5/internal/Observable.js.Observable._trySubscribe @ Observable.js:43
push../node_modules/rxjs/_esm5/internal/Observable.js.Observable.subscribe @ Observable.js:29
push../node_modules/rxjs/_esm5/internal/operators/mergeMap.js.MergeMapOperator.call @ mergeMap.js:29
push../node_modules/rxjs/_esm5/internal/Observable.js.Observable.subscribe @ Observable.js:24
push../node_modules/rxjs/_esm5/internal/operators/filter.js.FilterOperator.call @ filter.js:15
push../node_modules/rxjs/_esm5/internal/Observable.js.Observable.subscribe @ Observable.js:24
push../node_modules/rxjs/_esm5/internal/operators/map.js.MapOperator.call @ map.js:18
push../node_modules/rxjs/_esm5/internal/Observable.js.Observable.subscribe @ Observable.js:24
push../src/app/login/login.component.ts.LoginComponent.onSubmit @ login.component.ts:53
(anonymous) @ LoginComponent.html:13
handleEvent @ core.js:10251
callWithDebugContext @ core.js:11344
debugHandleEvent @ core.js:11047
dispatchEvent @ core.js:7710
(anonymous) @ core.js:9190
schedulerFn @ core.js:3563
push../node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.__tryOrUnsub @ Subscriber.js:196
push../node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.next @ Subscriber.js:134
push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber._next @ Subscriber.js:77
push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next @ Subscriber.js:54
push../node_modules/rxjs/_esm5/internal/Subject.js.Subject.next @ Subject.js:47
push../node_modules/@angular/core/fesm5/core.js.EventEmitter.emit @ core.js:3535
push../node_modules/@angular/forms/fesm5/forms.js.FormGroupDirective.onSubmit @ forms.js:4560
(anonymous) @ LoginComponent.html:13
handleEvent @ core.js:10251
callWithDebugContext @ core.js:11344
debugHandleEvent @ core.js:11047
dispatchEvent @ core.js:7710
(anonymous) @ core.js:8154
(anonymous) @ platform-browser.js:988
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask @ zone.js:421
onInvokeTask @ core.js:3811
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask @ zone.js:420
push../node_modules/zone.js/dist/zone.js.Zone.runTask @ zone.js:188
push../node_modules/zone.js/dist/zone.js.ZoneTask.invokeTask @ zone.js:496
invokeTask @ zone.js:1540
globalZoneAwareCallback @ zone.js:1566
core.js:1673 ERROR HttpErrorResponse {headers: HttpHeaders, status: 0, statusText: "Unknown Error", url: null, ok: false, …}

Please help me with your suggestions. 请给我您的建议。

Thanks 谢谢

After some more thorough searches. 经过更彻底的搜索。 I found out that there can be only 2 problems: 我发现只有两个问题:

  1. Port 8000 is blocked 端口8000被阻止
  2. The application is not listening on the Port 8000. 应用程序未在端口8000上侦听。

For me it was 1st case. 对我来说,这是第一种情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM