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

时光怂恿深爱的人放手 提交于 2019-12-24 10:14:54

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!