I am new to asp.net core 7.0.
I am working on the Web Api. However I created one controller with [ApiController] decoration.
In the launchSettings.json file it shows port number as 14023 as shown below :-
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:14023",
"sslPort": 44381
}
Means that my Web API will be pointing to http://localhost:14023
However when I run the application and navigate to http://localhost:14023 it shows below error :
This site can’t be reached
localhost refused to connect.
ERR_CONNECTION_REFUSED
And when I hit the same API URL through Postman then below error coming :-
Error: connect ECONNREFUSED 127.0.0.1:14023 Initially I thought that it could be related to CORS so I added below code in Program.cs file :-
builder.Services.AddCors();
app.UseCors(options =>
options.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader()
);
Can anyone help me on this?
I am stuck. Even I googled but did not find any suitable answer.