I have an ASPX page (On server A) which is invoked using NTLM credentials. Part of that page's job is to call an HTML page (On server B) and proxy it back to the client. (The client has access to A, but not to B). Server B is also not open to anonymous access, so I need to supply credentials to it.
If I hardcode some credentials (as per the attached code), it works, but ideally I would echo the credentials that were received by the .aspx page. Is there some way to get those NetworkCredentials so I can pass them on?
protected void Page_Load(object sender, EventArgs e) {
Response.Clear();
WebClient proxyFile = new WebClient();
CredentialCache cc = new CredentialCache();
cc.Add(new Uri("http://serverB/"), "NTLM",
new NetworkCredential("userName", "password", "domain"));
proxyFile.Credentials = cc;
Stream proxyStream = proxyFile.OpenRead("http://serverB/Content/webPage.html");
int i;
do {
i = proxyStream.ReadByte();
if (i != -1) {
Response.OutputStream.WriteByte((byte)i);
}
} while (i != -1);
Response.End();
}