[英]ASp.Net Link button click event is not fired,
這是一個非常奇怪的情況,
假設我這樣瀏覽我的網站,例如“ http://web.site.com ”。 我的網站完美地顯示了我的主頁,在頂部的該頁面上,我正在使用一個用戶控件,而該用戶控件正在顯示注銷鏈接按鈕。
情況1:在這種情況下,當我單擊此按鈕時,則不會觸發,
情況2:但是,如果我打開“ http://web.site.com/default.aspx ”之類的網站,則其工作正常並被解雇。
有人可以建議我嗎?
以下控件在用戶控件中使用
<asp:linkbutton id="logoutLinkButton" runat="server"
onclick="logoutLinkButton_Click1">logout</asp:linkbutton>
並且“鏈接”按鈕事件代碼為
protected void logoutLinkButton_Click1(object sender, EventArgs e)
{
var url = this.Request.RawUrl;
Authentication.Logout();
Response.Redirect(url);
}
問題是您正在使用Request.RawUrl
原始URL定義為URL中域信息之后的一部分。 在URL字符串http://www.contoso.com/articles/recent.aspx中 ,原始URL是/articles/recent.aspx。 原始URL包含查詢字符串(如果存在)。
因此對於您的情況, "http://web.site.com"
RawUrl
將為空,因此不執行任何操作。 相反,您可以像這樣使用Request.Url.GetLeftPart(UriPartial.Authority)
protected void logoutLinkButton_Click1(object sender, EventArgs e)
{
var url = this.Request.Url.GetLeftPart(UriPartial.Authority);
Authentication.Logout();
Response.Redirect(url);
}
嘗試使用Request.URL' instead of
Request.RawUrl`
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.