Why does HttpContext.Current.Request.Url.AbsolutePath return an empty string?

When the user asks http://localhost/WebApp1/Default.aspx, it txtApplicationPath.Textshould be assigned "/WebApp1", but it txtAbsolutePath.Textshould be assigned "http://localhost/WebApp1/Default.aspx", but instead both text fields display blank lines.

Why?

Default.aspx:

<asp:TextBox ID="txtApplicationPath" runat="server" 
    Text='<%# HttpContext.Current.Request.ApplicationPath %>'>
</asp:TextBox> <br />
<asp:TextBox ID="txtAbsolutePath" runat="server" 
    Text='<%# HttpContext.Current.Request.Url.AbsolutePath %>'>
</asp:TextBox> 

Thank you

+1
source share
1 answer

if you need the full url you should use Request.Url.OriginalString because AbsolutePath will omit the host portion of the url.

+2
source

All Articles