Pages

Request.ApplicationPath is not working in some cases

Request.ApplicationPath will work only IE. When we want to support different browsers like Chrome, Safari and Firefox, we should use the below property to get the correct relative URL.
this.Request.Url.GetLeftPart(UriPartial.Authority)
Example:

If we use Request.ApplicationPath 
window.open('" + Request.ApplicationPath + "/abc/testpage.aspx?x=1"','test page', 'toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes ,modal=yes'); }", true); 
It will be rendered as http://abc/testpage.aspx?x=1

If we use Request.Url.GetLeftPart(UriPartial.Authority), then it will be rendered as 
http://ServerName/abc/testpage.aspx?x=1



1 comment:

  1. string navigatePath = HttpContext.Current.Request.Url.AbsolutePath;
    navigatePath += "/abc/testpage.aspx?x=1";

    ReplyDelete