Request against localhost relative url “Cannot assign requested address”
I have a visual studio 2017 [ / 2019 ] asp.net core web app project enabled with docker support using FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
and FROM microsoft/dotnet:2.1-sdk AS build
images.
When my f5 debug instance starts up on http://localhost:44301/ I attempt to make HttpClient.SendAsync() request against relative url /data/some.json
to pull in data making localhost debugging able to emulate security state only present in published app case.
When I f5 debug using project's IISExpress target this all works fine. When I f5 debug against the Docker target the HttpClient.SendAsync() call against the localhost relative url, or fully qualified https://localhost:44301/data/some.json
and http://localhost:8081/data/some.json
paths, generates the exception with message Cannot assign requested address
. If I change code to load some.json from a remote url, e.g. storage account public blob path, the f5 debug Docker target does not fail on this call.
One can repro issue using the https://github.com/myusrn/adncauthexploration.git
provided AzWebApp1
project which also requires https://github.com/myusrn/KK.AspNetCore.EasyAuthAuthentication.git
that is accessed using a project reference, to enable debugging contents of this nuget package. Using localhost f5 iisexpress target the issue doesn't repro. Switching to localhost f5 docker target the issue repros when debug url processing hits KK.AspNetCore.EasyAuthAuthenticationServicesEasyAuthWithAuthMeService.cs
| line 109 var response = await client.SendAsync(httpRequest);
.
I'm wondering if there is some Dockerfile setting I need to be making to enable this f5 debug localhost relative url request by the asp.net core web app startup code.
c# docker dockerfile asp.net-core-webapi dotnet-httpclient
add a comment |
I have a visual studio 2017 [ / 2019 ] asp.net core web app project enabled with docker support using FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
and FROM microsoft/dotnet:2.1-sdk AS build
images.
When my f5 debug instance starts up on http://localhost:44301/ I attempt to make HttpClient.SendAsync() request against relative url /data/some.json
to pull in data making localhost debugging able to emulate security state only present in published app case.
When I f5 debug using project's IISExpress target this all works fine. When I f5 debug against the Docker target the HttpClient.SendAsync() call against the localhost relative url, or fully qualified https://localhost:44301/data/some.json
and http://localhost:8081/data/some.json
paths, generates the exception with message Cannot assign requested address
. If I change code to load some.json from a remote url, e.g. storage account public blob path, the f5 debug Docker target does not fail on this call.
One can repro issue using the https://github.com/myusrn/adncauthexploration.git
provided AzWebApp1
project which also requires https://github.com/myusrn/KK.AspNetCore.EasyAuthAuthentication.git
that is accessed using a project reference, to enable debugging contents of this nuget package. Using localhost f5 iisexpress target the issue doesn't repro. Switching to localhost f5 docker target the issue repros when debug url processing hits KK.AspNetCore.EasyAuthAuthenticationServicesEasyAuthWithAuthMeService.cs
| line 109 var response = await client.SendAsync(httpRequest);
.
I'm wondering if there is some Dockerfile setting I need to be making to enable this f5 debug localhost relative url request by the asp.net core web app startup code.
c# docker dockerfile asp.net-core-webapi dotnet-httpclient
Not really clear why your web app is making calls to itself.
– John
Dec 28 '18 at 5:57
@John, its in order to support data/some.json coming from relative path or remote url path
– myusrn
Dec 28 '18 at 17:57
add a comment |
I have a visual studio 2017 [ / 2019 ] asp.net core web app project enabled with docker support using FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
and FROM microsoft/dotnet:2.1-sdk AS build
images.
When my f5 debug instance starts up on http://localhost:44301/ I attempt to make HttpClient.SendAsync() request against relative url /data/some.json
to pull in data making localhost debugging able to emulate security state only present in published app case.
When I f5 debug using project's IISExpress target this all works fine. When I f5 debug against the Docker target the HttpClient.SendAsync() call against the localhost relative url, or fully qualified https://localhost:44301/data/some.json
and http://localhost:8081/data/some.json
paths, generates the exception with message Cannot assign requested address
. If I change code to load some.json from a remote url, e.g. storage account public blob path, the f5 debug Docker target does not fail on this call.
One can repro issue using the https://github.com/myusrn/adncauthexploration.git
provided AzWebApp1
project which also requires https://github.com/myusrn/KK.AspNetCore.EasyAuthAuthentication.git
that is accessed using a project reference, to enable debugging contents of this nuget package. Using localhost f5 iisexpress target the issue doesn't repro. Switching to localhost f5 docker target the issue repros when debug url processing hits KK.AspNetCore.EasyAuthAuthenticationServicesEasyAuthWithAuthMeService.cs
| line 109 var response = await client.SendAsync(httpRequest);
.
I'm wondering if there is some Dockerfile setting I need to be making to enable this f5 debug localhost relative url request by the asp.net core web app startup code.
c# docker dockerfile asp.net-core-webapi dotnet-httpclient
I have a visual studio 2017 [ / 2019 ] asp.net core web app project enabled with docker support using FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
and FROM microsoft/dotnet:2.1-sdk AS build
images.
When my f5 debug instance starts up on http://localhost:44301/ I attempt to make HttpClient.SendAsync() request against relative url /data/some.json
to pull in data making localhost debugging able to emulate security state only present in published app case.
When I f5 debug using project's IISExpress target this all works fine. When I f5 debug against the Docker target the HttpClient.SendAsync() call against the localhost relative url, or fully qualified https://localhost:44301/data/some.json
and http://localhost:8081/data/some.json
paths, generates the exception with message Cannot assign requested address
. If I change code to load some.json from a remote url, e.g. storage account public blob path, the f5 debug Docker target does not fail on this call.
One can repro issue using the https://github.com/myusrn/adncauthexploration.git
provided AzWebApp1
project which also requires https://github.com/myusrn/KK.AspNetCore.EasyAuthAuthentication.git
that is accessed using a project reference, to enable debugging contents of this nuget package. Using localhost f5 iisexpress target the issue doesn't repro. Switching to localhost f5 docker target the issue repros when debug url processing hits KK.AspNetCore.EasyAuthAuthenticationServicesEasyAuthWithAuthMeService.cs
| line 109 var response = await client.SendAsync(httpRequest);
.
I'm wondering if there is some Dockerfile setting I need to be making to enable this f5 debug localhost relative url request by the asp.net core web app startup code.
c# docker dockerfile asp.net-core-webapi dotnet-httpclient
c# docker dockerfile asp.net-core-webapi dotnet-httpclient
edited Jan 2 at 3:13
myusrn
asked Dec 28 '18 at 5:55
myusrnmyusrn
175215
175215
Not really clear why your web app is making calls to itself.
– John
Dec 28 '18 at 5:57
@John, its in order to support data/some.json coming from relative path or remote url path
– myusrn
Dec 28 '18 at 17:57
add a comment |
Not really clear why your web app is making calls to itself.
– John
Dec 28 '18 at 5:57
@John, its in order to support data/some.json coming from relative path or remote url path
– myusrn
Dec 28 '18 at 17:57
Not really clear why your web app is making calls to itself.
– John
Dec 28 '18 at 5:57
Not really clear why your web app is making calls to itself.
– John
Dec 28 '18 at 5:57
@John, its in order to support data/some.json coming from relative path or remote url path
– myusrn
Dec 28 '18 at 17:57
@John, its in order to support data/some.json coming from relative path or remote url path
– myusrn
Dec 28 '18 at 17:57
add a comment |
1 Answer
1
active
oldest
votes
For accessing resource from IIS Express
, SelfHost
and Docker
, you could configure HttpClient.BaseAddress
with Http Request like below:
public class HomeController : Controller
{
private readonly HttpClient httpClient;
public HomeController(
, IHttpClientFactory httpClientFactory)
{
this.httpClient = httpClientFactory.CreateClient();
}
public async Task<IActionResult> Index()
{
this.httpClient.BaseAddress = new Uri($"{this.Request.Scheme}://{this.Request.Host}");
var response = await httpClient.SendAsync(new HttpRequestMessage(HttpMethod.Get,
"data/some.json"));
var result = await response.Content.ReadAsStringAsync();
return View();
}
}
thanks for response. That is what i'm doing already, tried both fully qualified base address and relative address requests. In the case of a localhost f5 debug session using iisexpress it works but when I change to localhost f5 debug session using docker it generates the error message I noted. Maybe you are suggesting something subtly different about how I create request that i'm overlooking?
– myusrn
Jan 1 at 16:23
@myusrn Is there any demo to reproduce your issue?
– Tao Zhou
Jan 2 at 1:55
thanks for continued interest in helping understand this issue and possible fixes. I added repo sources instructions to original question details.
– myusrn
Jan 2 at 2:48
@myusrn There are two projects, do you mean you send requests from one docker container to another?
– Tao Zhou
Jan 2 at 2:58
The only project involved in repro of this issue is the AzWebApp1 project and the project it references in lieu of nuget package in order to facilitate debugging into its sources which is where the localhost /.auth/me.json relative url call happens. Also note that I just updated the master branch with a check so that the startup.csoptions.AuthEndpoint = ".auth/me.json";
setting is enabled which is required for issue to repro. As noted in comments using non-localhost / relative urloptions.AuthEndpoint = "https://mysawestus.blob.core.windows.net/public/me.json"
makes error go away.
– myusrn
Jan 2 at 3:26
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53954244%2frequest-against-localhost-relative-url-cannot-assign-requested-address%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
For accessing resource from IIS Express
, SelfHost
and Docker
, you could configure HttpClient.BaseAddress
with Http Request like below:
public class HomeController : Controller
{
private readonly HttpClient httpClient;
public HomeController(
, IHttpClientFactory httpClientFactory)
{
this.httpClient = httpClientFactory.CreateClient();
}
public async Task<IActionResult> Index()
{
this.httpClient.BaseAddress = new Uri($"{this.Request.Scheme}://{this.Request.Host}");
var response = await httpClient.SendAsync(new HttpRequestMessage(HttpMethod.Get,
"data/some.json"));
var result = await response.Content.ReadAsStringAsync();
return View();
}
}
thanks for response. That is what i'm doing already, tried both fully qualified base address and relative address requests. In the case of a localhost f5 debug session using iisexpress it works but when I change to localhost f5 debug session using docker it generates the error message I noted. Maybe you are suggesting something subtly different about how I create request that i'm overlooking?
– myusrn
Jan 1 at 16:23
@myusrn Is there any demo to reproduce your issue?
– Tao Zhou
Jan 2 at 1:55
thanks for continued interest in helping understand this issue and possible fixes. I added repo sources instructions to original question details.
– myusrn
Jan 2 at 2:48
@myusrn There are two projects, do you mean you send requests from one docker container to another?
– Tao Zhou
Jan 2 at 2:58
The only project involved in repro of this issue is the AzWebApp1 project and the project it references in lieu of nuget package in order to facilitate debugging into its sources which is where the localhost /.auth/me.json relative url call happens. Also note that I just updated the master branch with a check so that the startup.csoptions.AuthEndpoint = ".auth/me.json";
setting is enabled which is required for issue to repro. As noted in comments using non-localhost / relative urloptions.AuthEndpoint = "https://mysawestus.blob.core.windows.net/public/me.json"
makes error go away.
– myusrn
Jan 2 at 3:26
add a comment |
For accessing resource from IIS Express
, SelfHost
and Docker
, you could configure HttpClient.BaseAddress
with Http Request like below:
public class HomeController : Controller
{
private readonly HttpClient httpClient;
public HomeController(
, IHttpClientFactory httpClientFactory)
{
this.httpClient = httpClientFactory.CreateClient();
}
public async Task<IActionResult> Index()
{
this.httpClient.BaseAddress = new Uri($"{this.Request.Scheme}://{this.Request.Host}");
var response = await httpClient.SendAsync(new HttpRequestMessage(HttpMethod.Get,
"data/some.json"));
var result = await response.Content.ReadAsStringAsync();
return View();
}
}
thanks for response. That is what i'm doing already, tried both fully qualified base address and relative address requests. In the case of a localhost f5 debug session using iisexpress it works but when I change to localhost f5 debug session using docker it generates the error message I noted. Maybe you are suggesting something subtly different about how I create request that i'm overlooking?
– myusrn
Jan 1 at 16:23
@myusrn Is there any demo to reproduce your issue?
– Tao Zhou
Jan 2 at 1:55
thanks for continued interest in helping understand this issue and possible fixes. I added repo sources instructions to original question details.
– myusrn
Jan 2 at 2:48
@myusrn There are two projects, do you mean you send requests from one docker container to another?
– Tao Zhou
Jan 2 at 2:58
The only project involved in repro of this issue is the AzWebApp1 project and the project it references in lieu of nuget package in order to facilitate debugging into its sources which is where the localhost /.auth/me.json relative url call happens. Also note that I just updated the master branch with a check so that the startup.csoptions.AuthEndpoint = ".auth/me.json";
setting is enabled which is required for issue to repro. As noted in comments using non-localhost / relative urloptions.AuthEndpoint = "https://mysawestus.blob.core.windows.net/public/me.json"
makes error go away.
– myusrn
Jan 2 at 3:26
add a comment |
For accessing resource from IIS Express
, SelfHost
and Docker
, you could configure HttpClient.BaseAddress
with Http Request like below:
public class HomeController : Controller
{
private readonly HttpClient httpClient;
public HomeController(
, IHttpClientFactory httpClientFactory)
{
this.httpClient = httpClientFactory.CreateClient();
}
public async Task<IActionResult> Index()
{
this.httpClient.BaseAddress = new Uri($"{this.Request.Scheme}://{this.Request.Host}");
var response = await httpClient.SendAsync(new HttpRequestMessage(HttpMethod.Get,
"data/some.json"));
var result = await response.Content.ReadAsStringAsync();
return View();
}
}
For accessing resource from IIS Express
, SelfHost
and Docker
, you could configure HttpClient.BaseAddress
with Http Request like below:
public class HomeController : Controller
{
private readonly HttpClient httpClient;
public HomeController(
, IHttpClientFactory httpClientFactory)
{
this.httpClient = httpClientFactory.CreateClient();
}
public async Task<IActionResult> Index()
{
this.httpClient.BaseAddress = new Uri($"{this.Request.Scheme}://{this.Request.Host}");
var response = await httpClient.SendAsync(new HttpRequestMessage(HttpMethod.Get,
"data/some.json"));
var result = await response.Content.ReadAsStringAsync();
return View();
}
}
answered Dec 31 '18 at 6:44
Tao ZhouTao Zhou
5,23531128
5,23531128
thanks for response. That is what i'm doing already, tried both fully qualified base address and relative address requests. In the case of a localhost f5 debug session using iisexpress it works but when I change to localhost f5 debug session using docker it generates the error message I noted. Maybe you are suggesting something subtly different about how I create request that i'm overlooking?
– myusrn
Jan 1 at 16:23
@myusrn Is there any demo to reproduce your issue?
– Tao Zhou
Jan 2 at 1:55
thanks for continued interest in helping understand this issue and possible fixes. I added repo sources instructions to original question details.
– myusrn
Jan 2 at 2:48
@myusrn There are two projects, do you mean you send requests from one docker container to another?
– Tao Zhou
Jan 2 at 2:58
The only project involved in repro of this issue is the AzWebApp1 project and the project it references in lieu of nuget package in order to facilitate debugging into its sources which is where the localhost /.auth/me.json relative url call happens. Also note that I just updated the master branch with a check so that the startup.csoptions.AuthEndpoint = ".auth/me.json";
setting is enabled which is required for issue to repro. As noted in comments using non-localhost / relative urloptions.AuthEndpoint = "https://mysawestus.blob.core.windows.net/public/me.json"
makes error go away.
– myusrn
Jan 2 at 3:26
add a comment |
thanks for response. That is what i'm doing already, tried both fully qualified base address and relative address requests. In the case of a localhost f5 debug session using iisexpress it works but when I change to localhost f5 debug session using docker it generates the error message I noted. Maybe you are suggesting something subtly different about how I create request that i'm overlooking?
– myusrn
Jan 1 at 16:23
@myusrn Is there any demo to reproduce your issue?
– Tao Zhou
Jan 2 at 1:55
thanks for continued interest in helping understand this issue and possible fixes. I added repo sources instructions to original question details.
– myusrn
Jan 2 at 2:48
@myusrn There are two projects, do you mean you send requests from one docker container to another?
– Tao Zhou
Jan 2 at 2:58
The only project involved in repro of this issue is the AzWebApp1 project and the project it references in lieu of nuget package in order to facilitate debugging into its sources which is where the localhost /.auth/me.json relative url call happens. Also note that I just updated the master branch with a check so that the startup.csoptions.AuthEndpoint = ".auth/me.json";
setting is enabled which is required for issue to repro. As noted in comments using non-localhost / relative urloptions.AuthEndpoint = "https://mysawestus.blob.core.windows.net/public/me.json"
makes error go away.
– myusrn
Jan 2 at 3:26
thanks for response. That is what i'm doing already, tried both fully qualified base address and relative address requests. In the case of a localhost f5 debug session using iisexpress it works but when I change to localhost f5 debug session using docker it generates the error message I noted. Maybe you are suggesting something subtly different about how I create request that i'm overlooking?
– myusrn
Jan 1 at 16:23
thanks for response. That is what i'm doing already, tried both fully qualified base address and relative address requests. In the case of a localhost f5 debug session using iisexpress it works but when I change to localhost f5 debug session using docker it generates the error message I noted. Maybe you are suggesting something subtly different about how I create request that i'm overlooking?
– myusrn
Jan 1 at 16:23
@myusrn Is there any demo to reproduce your issue?
– Tao Zhou
Jan 2 at 1:55
@myusrn Is there any demo to reproduce your issue?
– Tao Zhou
Jan 2 at 1:55
thanks for continued interest in helping understand this issue and possible fixes. I added repo sources instructions to original question details.
– myusrn
Jan 2 at 2:48
thanks for continued interest in helping understand this issue and possible fixes. I added repo sources instructions to original question details.
– myusrn
Jan 2 at 2:48
@myusrn There are two projects, do you mean you send requests from one docker container to another?
– Tao Zhou
Jan 2 at 2:58
@myusrn There are two projects, do you mean you send requests from one docker container to another?
– Tao Zhou
Jan 2 at 2:58
The only project involved in repro of this issue is the AzWebApp1 project and the project it references in lieu of nuget package in order to facilitate debugging into its sources which is where the localhost /.auth/me.json relative url call happens. Also note that I just updated the master branch with a check so that the startup.cs
options.AuthEndpoint = ".auth/me.json";
setting is enabled which is required for issue to repro. As noted in comments using non-localhost / relative url options.AuthEndpoint = "https://mysawestus.blob.core.windows.net/public/me.json"
makes error go away.– myusrn
Jan 2 at 3:26
The only project involved in repro of this issue is the AzWebApp1 project and the project it references in lieu of nuget package in order to facilitate debugging into its sources which is where the localhost /.auth/me.json relative url call happens. Also note that I just updated the master branch with a check so that the startup.cs
options.AuthEndpoint = ".auth/me.json";
setting is enabled which is required for issue to repro. As noted in comments using non-localhost / relative url options.AuthEndpoint = "https://mysawestus.blob.core.windows.net/public/me.json"
makes error go away.– myusrn
Jan 2 at 3:26
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53954244%2frequest-against-localhost-relative-url-cannot-assign-requested-address%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Not really clear why your web app is making calls to itself.
– John
Dec 28 '18 at 5:57
@John, its in order to support data/some.json coming from relative path or remote url path
– myusrn
Dec 28 '18 at 17:57