2013-05-08 122 views
0

這是一個很奇怪的場景,ASp.Net鏈接按鈕單擊事件不會觸發,

想,我瀏覽我的網站,如「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); 
     } 
+0

什麼是你對那個按鈕的代碼? – Habib 2013-05-08 11:32:09

+0

檢查註銷鏈接。我想你沒有使用登錄狀態控制。 – nunespascal 2013-05-08 11:32:51

+0

您設置了哪些網址鏈接? – Sudz 2013-05-08 11:33:28

回答

1

的問題是,你正在使用Request.RawUrl

的原始網址被定義爲域 信息後面的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);  
} 
+0

謝謝,我已經嘗試過你的代碼,但它不工作,即使我沒有寫過像「Response.Write(」Test「); 」但它也沒有在這個簡單的情況下被解僱,但如果我通過在網址上的de​​fault.aspx,然後在頁面上寫「Test」。 – 2013-05-08 11:56:44

+0

@Priyank,那很奇怪,你在你的代碼裏放了什麼'Response.Write'。首先聲明事件 – Habib 2013-05-08 12:00:29

+0

我只在我的點擊事件中寫了Response.Write聲明。如果我沒有使用default.aspx瀏覽我的網站,它不寫我不想寫default.aspx – 2013-05-08 12:03:03

0

嘗試Request.URL' instead of Request.RawUrl`

+0

沒有它仍然沒有工作,即使我只寫了「Response.write(」Test「)而不是所有的代碼,然後不寫在頁面上。 – 2013-05-08 11:59:46

相關問題