简体   繁体   English

DelegatingHandler在Localhost上有效,但在Azure上无效

[英]DelegatingHandler works on Localhost but not on Azure

I have the following code which works fine when forwarding to my localhost:1671 : 我有以下代码,当转发到我的localhost:1671

protected override async System.Threading.Tasks.Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)
{
    UriBuilder forwardUri = new UriBuilder(request.RequestUri);
    //remove the proxy port and replace with an Http port
    forwardUri.Port = 1671;
    //send it on to the requested URL
    request.RequestUri = forwardUri.Uri;
    HttpClient client = new HttpClient();
    if (request.Method == HttpMethod.Get)
        request.Content = null;
    try
    {

        var response = await client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead);
        if (response.StatusCode == HttpStatusCode.OK)
        {
            ManageOnline(response.RequestMessage);
        }
        return response;
    }
    catch (Exception ex)
    {
        throw;
    }
}

However when I change it to my website on azure (eg xxxx.azurewebsites.net), it does not work. 但是,当我将其更改为我在azure上的网站(例如xxxx.azurewebsites.net)时,它不起作用。

Any idea if I need to have a different configuration to Azure? 我是否需要与Azure有不同的配置? I am assuming that on Azure the port is 80. 我假设在Azure上的端口为80。

I assume you're following this tutorial here : http://blog.kloud.com.au/2013/11/24/do-it-yourself-web-api-proxy/ 我假设您在这里遵循本教程: http : //blog.kloud.com.au/2013/11/24/do-it-yourself-web-api-proxy/

Check if you have the below entry on your web/app.config 检查您的web / app.config中是否包含以下条目

<system.net>
    <defaultProxy enabled="false" />
</system.net>

Remove the <defaultProxy enabled="false" /> 删除<defaultProxy enabled="false" />

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

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