Priyank Gupta
Priyank Gupta

Reputation: 942

ASp.Net Link button click event is not fired,

This is a very strange scenario,

Suppose, I browse my site like "http://web.site.com" this way. my site display perfectly my Home page, on this page on the top, i am using one user control and this user control is displaying a logout Link button.

case 1: When i click this button in this scenario then its does not fired,

Case 2: But if i open my site like "http://web.site.com/default.aspx" then its work correctly and fired.

Can any one suggest me on this?

the below control is using in user control

<asp:linkbutton id="logoutLinkButton" runat="server" 
         onclick="logoutLinkButton_Click1">logout</asp:linkbutton>

and the Link button event code is

protected void logoutLinkButton_Click1(object sender, EventArgs e)
         {
             var url = this.Request.RawUrl;
             Authentication.Logout();
             Response.Redirect(url); 
         }

Upvotes: 0

Views: 3259

Answers (2)

Habib
Habib

Reputation: 223257

The problem is that you are using Request.RawUrl

The raw URL is defined as the part of the URL following the domain information. In the URL string http://www.contoso.com/articles/recent.aspx, the raw URL is /articles/recent.aspx. The raw URL includes the query string, if present.

so for your case "http://web.site.com" RawUrl would be empty, and thus not doing anything. Instead you can use Request.Url.GetLeftPart(UriPartial.Authority) like

protected void logoutLinkButton_Click1(object sender, EventArgs e)
{
   var url = this.Request.Url.GetLeftPart(UriPartial.Authority);
   Authentication.Logout();
   Response.Redirect(url); 
}

Upvotes: 1

Neeraj
Neeraj

Reputation: 4489

Try Request.URL' instead ofRequest.RawUrl`

Upvotes: 0

Related Questions