<%@ Import Namespace="System.Net" %>
<script language="c#" runat="server" Debug="true">
  private void Page_Load(object sender, System.EventArgs e)
  {
    string LOGIN_URL = "https://mail.myserver.com/exchweb/bin/auth/owalogon.asp";
    string strUser = "MyUsername";
    string strPass = "MyPassword";
   
    byte[] response;
    WebClient webClient = new WebClient();
    response = webClient.DownloadData(LOGIN_URL);
    string strHTML = Encoding.Default.GetString(response);   
   
    // Fill in the form-based authentication - OPTIONAL
      // Fix relative paths
      strHTML = strHTML.Replace("/exchweb",
                "https://mail.myserver.com/exchweb");   
      // Fill in the form
      strHTML = strHTML.Replace("id=\"username\"",
                "id=\"username\" value=\"" + strUser + "\"");
      strHTML = strHTML.Replace("id=\"password\"",
                "id=\"password\" value=\"" + strPass + "\"");
      // Change the onload behavior to auto-submit the form
      strHTML = strHTML.Replace("onload=\"setFocus()\"",
                "onload=\"document.forms[0].submit()\"");

    // Render HTML
    Response.Write(strHTML);
  }

</script>