我想在asp.net頁面中檢測傳入url並在該url的基礎上做出一些決定但是我在這裏面臨的一些問題是我的c#代碼檢測URL和條件基於傳入的url調用url
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
String url = Request.ServerVariables["HTTP_REFERER"];
if (url != "http://172.17.0.221:84/CP.aspx")
{
Response.Redirect("http://a.sml.com.pk");
}
else
{
Response.Redirect("http://172.17.0.221:85/MilkSale.aspx");
}
}
}
</script>
但是當我調用的頁面從http://172.17.0.221:84/CP.aspx則給出了這樣的錯誤:
This webpage has a redirect loop.
The webpage at http://172.17.0.221:85/MilkSale.aspx has resulted in too many redirects. Clearing your cookies for this site or allowing third-party cookies may fix the problem. If not, it is possibly a server configuration issue and not a problem with your computer.
任何一個可以告訴我可以在這代碼中的錯誤?
它看起來像重定向多次到同一頁面。記錄正在處理的頁面的URL以確保。嘗試調用'Response.End'來結束處理。 – 2012-03-28 09:57:35
該腳本是否也在MilkSale.aspx頁面上?如果是這樣,它會每隔*時間發射一次。更改你的其他地址,如果url!=「http://172.17.0.221:85/MilkSale.aspx」{}來檢查這個。 – dash 2012-03-28 10:01:50
看起來像你導致永無止境的頁面重定向..可能它總是去**其他**部分。嘗試使用**否則如果**而不是**其他** – 2012-03-28 10:03:49