2
Answers

Getting error HTTP Error 400 - Bad Request when usiing hyperlink with query string

programmerAt

programmerAt

14y
4.6k
1
hi
i have two pages default.aspx and view.aspx,
default.aspx has hyperlink control and on code behind file in page load event i have written this
Hyperlink.NavigateUrl = "view.aspx?ReturnUrl=" + HttpUtility.UrlEncode(Request.Url.AbsolutePath);

and on view.aspx i have 1 more hyperlink i have written this on code behind file page load event
BackHyperLink.NavigateUrl = HttpUtility.UrlEncode(Request.QueryString["ReturnUrl"]);

when i click Back hyperlink i am getting this error
HTTP Error 400 - Bad Request.

Can anyone help me plz.

Thanks

Answers (2)
1
programmerAt
NA 3 4.6k 14y
Hi, Thanks I removed httpUtility.UrlEncode from view.aspx page and it worked.
1
Krishna Garad
NA 16.5k 6.2m 14y
Hi..
Welcome to Csharpcorner
Normally this error occur when we are trying to access the resource which is not available. In your case check out view.aspx location means see is it present in any directory.If it is then try like

Hyperlink.NavigateUrl = "~/view.aspx?ReturnUrl=" +
HttpUtility.UrlEncode(Request.Url.AbsolutePath); 

As well your target url must be able to Decode.