问题
When user requests http://localhost/WebApp1/Default.aspx
, txtApplicationPath.Text
should be assigned “/WebApp1”
, while txtAbsolutePath.Text
should be assigned “http://localhost/WebApp1/Default.aspx”
, but instead both textboxes display empty strings.
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:
if you want the full url you should use Request.Url.OriginalString, because AbsolutePath will omit the host part of the url.
来源:https://stackoverflow.com/questions/3876271/why-does-httpcontext-current-request-url-absolutepath-return-an-empty-string