我有一個使用NTLM憑據調用的ASPX頁面(在服務器A上)。該頁面的一部分工作是調用HTML頁面(在服務器B上)並將其代理回客戶端。 (防火牆允許訪問A,但不允許B訪問。用戶通常可以訪問兩臺服務器。)。服務器B也不開放給匿名訪問,所以我需要提供憑據給它。從APSX頁面的響應中獲取NTLM憑據
如果我硬編碼一些憑據(按照附加的代碼),它可以工作,但理想情況下我會回顯.aspx頁面收到的憑據。有什麼方法可以獲得這些NetworkCredentials,以便我可以傳遞它們嗎?
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();
}