Statuscode = 407, Reasonphrase: 'authenticationrequired under development only

Asked

Viewed 79 times

1

I have an ASP.NET application that accesses a remote server (outside the company domain; external URL) to verify some data. When I run the application on development environment - localhost accessing external URL, I take 407 error. That same code when published to the homologation server, that doesn’t happen. My problem is finding a way to identify the user credentials on the localhost. I am using the following code to check the proxy:

var oHand = new HttpClientHandler();    
if (WebRequest.DefaultWebProxy.GetProxy(new Uri(pURL)) != null)
       {
                    oHand.Proxy = WebRequest.DefaultWebProxy;
                    oHand.Proxy.Credentials = CredentialCache.DefaultNetworkCredentials;
                }

The only way I could make it work was by putting user data (network login and password) on web.config, which complicates version control, as it can put the network password of someone on the team exposed by accident. Someone would have a suggestion?

1 answer

0

Anderson Oliveira, look at this, maybe it’ll help you:

This method can avoid the need for HARD CODE (failed code) or configure proxy credentials, which may be desirable.

Put this in your app configuration file, probably in "app.config". Visual Studio will rename it to "Filename.exe.config" in the compilation, and it will end next to its executable. If you don’t have an application setup file, just add one using Add New Item in Visual Studio.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.net>
    <defaultProxy useDefaultCredentials="true" />
  </system.net>
</configuration>

Read more on:

Proxy Basic Authentication in C#: HTTP 407 error

407 Proxy Authentication Required

(407) Proxy Authentication Required.

  • 1

    @fabioln , thank you for your contribution. However, I’ve tried that too. In development, with this config, does not find the credentials of the user, I imagine for not running directly on the machine and yes on IIS. In a Windows app that I have, works normally. But in Desenv does not scroll...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.