私はプロキシファイルを使用して、システムが ajax を使用してシステムの別のサブドメインからページをロードできるようにしています。最初の試行でこれを成功させましたが、2回目の試行でエラーが発生し、その理由を突き止めるのに苦労しています。助けていただければ幸いです。
まず、これは私の Proxy.aspx.cs です。
protected void Page_Load(object sender, EventArgs e)
{
string proxyURL = HttpUtility.UrlDecode(Request.QueryString["u"]);
if (proxyURL != string.Empty)
{
HttpWebRequest request = (HttpWebRequest) WebRequest.Create(proxyURL);
request.Method = "POST";
request.ContentLength = 0;
HttpWebResponse response = (HttpWebResponse) request.GetResponse();
if (response.StatusCode.ToString().ToLower() == "ok")
{
string contentType = response.ContentType;
Stream content = response.GetResponseStream();
if (content != null)
{
StreamReader contentReader = new StreamReader(content);
Response.ContentType = contentType;
Response.Write(contentReader.ReadToEnd());
}
}
}
}
私のHTML / Javascriptはこれだけです:
<script>
$(document).ready(function () {
$.ajax({
type: "POST",
url: "Proxy.aspx?u=<%=GetUrl()%>",
success: function (data) {
$('#iFrameHolder').html(data);
}
});
});
</script>
<div id="iFrameHolder"></div>
次に、GetUrl() 関数を使用して、サブドメインのプロジェクトから必要なページの URL を作成します。
1 つの URL ではまったく問題なく動作しましたが、2 回目の試行で次のエラーが発生しました。
System.Net.WebException: The remote server returned an error: (404) Not Found.
at System.Net.HttpWebRequest.GetResponse()
at G2F.Collective.WebApplication.Shared.Proxy.Page_Load(Object sender, EventArgs e)
in D:\My Documents\Firefly\Collective\Dev\Solution\WebSites\G2F.Collective.WebApplication\Shared\Proxy.aspx.cs:line 26
at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
私には、作成中の URL に問題があることが示唆されますが、Chrome の Web 開発者ツールを使用すると、プロキシに渡される正確なクエリ文字列をコピーして、ブラウザーのアドレス バーに貼り付け、問題なくページにアクセスできます。 、つまり、作成中の URL に問題はありません。したがって、これが 404 を返す理由がわかりません。何か提案があれば、よろしくお願いします。