![](/img/trans.png)
[英]how to change the default redirect page of a url in sitemap in another page in C# asp.net
[英]Redirect an asp page to another URL
我有一個沒有action屬性的asp.net表單,提交將由ajax處理,如下所示。
$.ajax({
url: "home2.aspx/DoSubmit",
type: "POST",
contentType: "application/json; charset=utf-8",
data: '{x: "' + $("#x").val() + '",y: "' + $("#y").val() + '"}',
dataType: "json",
success: function (result)
{
alert("success...");
},
error: function (xhr, status) {
alert("Error", status);
}
});
return false;
});
在為ajax調用提供相關響應之后,在后面的代碼中,我想將asp.net頁面與其他我在后端有的參數重定向到另一個URL(甚至是不同的域)。 我測試了此方法,創建了HttpWebRequest,但是不起作用。
var postData = (requestParam.ToString());
var data = Encoding.ASCII.GetBytes(postData);
HttpWebRequest request;
try
{
request = (HttpWebRequest)HttpWebRequest.Create("https:someDomain");
}
catch (UriFormatException)
{
request = null;
}
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = data.Length;
Stream postStream = request.GetRequestStream()
postStream.Write(data, 0, data.Length);
postStream.Flush();
postStream.Close();
這會導致以下錯誤: 身份驗證失敗,因為遠程方已關閉傳輸流。
謝謝你的幫助
Ajax調用是瀏覽器中的OOB(帶外)。 它與瀏覽器導航機制具有絕對零連接。 因此,您的重定向將不起作用。
您需要訂閱ajax成功(和/或失敗)事件。 在這種情況下,您將通過任何數量的瀏覽器導航方法(例如window.location
)執行客戶端重定向。
如果您需要重定向URL來自服務器,則讓您的操作將其作為Ajax響應的一部分返回。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.