Search code examples
asp.netpostasp-classicwindows-authentication

Authentication prevents posting to Classic ASP from Web form using WebClient() from Code Behind


I am managing and old web site (site, not application) that is a hybrid of Web Forms and Classic ASP. The Classic ASP is being phased out, but that is probably a year away. Right now, we are dropping the old form of authentication in favor of Windows Authentication in the web.config.

The problem is that I am attempting to post to a Classic page from the code behind of a web form (http://www.blahsiblah.com/index.aspx) and am getting a 401 error.

var webClient = new WebClient();
var urlClassicASP = "http://www.blahsiblah.com/classic.asp";
var responseArray = webClient.UploadValues(urlClassicASP, "POST", nameValueCollection);

This throws "The remote server returned an error: (401) Unauthorized"

My question is, how can I post to the classic page without invoking the authentication of the dotNet side?


Solution

  • My solution was to set:

    webClient.UseDefaultCredentials = true;