microsoft / ApplicationInsights-aspnetcore

ASP.NET Core web applications monitoring
313 stars 123 forks source link

dotnet core 2.0 project redirected to random localhost port #610

Closed webmonger closed 6 years ago

webmonger commented 6 years ago

When you run a fresh project with react and redux installed and install AppInsights the the run endpoint is started on a strange port number and all javascript and css served causes 500 error

Repro Steps

mkdir NewWebApp cd NewWebApp dotnet new reactredux npm install dotnet add package Microsoft.ApplicationInsights.AspNetCore

Follow instructions from https://github.com/Microsoft/ApplicationInsights-aspnetcore/wiki/Getting-Started-for-a-ASP.NET-CORE-2.0-WebApp

  1. Add the instrumentation key: Option 1 add to appsettings.json
  2. Either follow Option 1 or Option 2 under the "Add Application Insights instrumentation in code."
  3. in vscode or VS hit F5

Actual Behavior

Compilation complete listing host started on http://localhost:5000 Browser opened at http://localhost:55343 (port changes on each run, seems random but always over 50000) Notice if you load http://localhost:5000 the site loads however no javascript or css is processed at the server

Expected Behavior

Compilation complete listing host started on http://localhost:5000 Browser opened at http://localhost:5000

Example project

You can find an example of this issue in this repo - https://github.com/webmonger/ApsNetReduxBasic in settings.cs add or remove line 27 to cause/remove the issue: https://github.com/webmonger/ApsNetReduxBasic/blob/master/Startup.cs#L27

Version Info

SDK Version : 2.2.1 .NET Version : Core 2.1.4 How Application was onboarded with SDK(VisualStudio/StatusMonitor/Azure Extension) : OS : OS X, Windows Hosting Info (IIS/Azure WebApps/ etc) : Kestral, IIS Express

cijothomas commented 6 years ago

@webmonger Thanks for taking time to report the issue. I could not run your repro as my machine didn't have node.js installed. But I am not sure how adding application insights changes the default port of the application launch. Not familiar with dotnet new reactredux , but i dont find this issue with other default templates like dotnet new webapi

Do you see this issue if you just run your app by using ``dotnet myapp``` command? Or is it only in VScode/vs? I am suspecting something in this IDE can cause default port change?

SergeyKanzhelev commented 6 years ago

@pakrym can you route this to the appropriate person in asp.net team?

pakrym commented 6 years ago

@cijothomas nodejs is available for download from https://nodejs.org/en/

@webmonger I tried the repro and didn't observe any port change when adding/removing that line. What version of VS are you using?

webmonger commented 6 years ago

@pakrym Sorry for the delay in coming back to you on this: dotnet --version: 2.1.4 code: Version 1.22.1 (1.22.1)

I just followed the repro steps listed above on my mac and found the issue is still occurring. I searched in the terminal output for the erroneous port number and found the following:

Application Insights Telemetry (unconfigured): {"name":"Microsoft.ApplicationInsights.RemoteDependency","time":"2018-04-12T10:03:57.9960740Z","tags":{"ai.application.ver":"1.0.0.0","ai.operation.id":"11ffd631-493d2ff03c4c9953","ai.internal.sdkVersion":"rdddsc:2.5.1-195"},"data":{"baseType":"RemoteDependencyData","baseData":{"ver":2,"name":"POST /","id":"|11ffd631-493d2ff03c4c9953.","data":"http://localhost:60688/","duration":"00:00:00.6074350","resultCode":"200","success":true,"type":"Http","target":"localhost","properties":{"AspNetCoreEnvironment":"Development"}}}}

and

Hosting environment: Development
Content root path: /[Absolute Path to Project location]/reacttest
Launching browser (open http://localhost:60688)
Now listening on: http://localhost:5000
Application started. Press Ctrl+C to shut down.
pakrym commented 6 years ago

Can you check your project properties debug tab and see if Browse URL is set to http://localhost:60688?

cijothomas commented 6 years ago

@webmonger Please re-open if you need more help here. I don't believe this is an application insights sdk issue though.