1

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

2
  • 1
    I had the same result. It'll work if you populate those TextBoxes in code-behind instead of markup. Commented Oct 6, 2010 at 19:59
  • 1
    Ups, reason it didn't work is because I forgot to call Page.Databind Commented Oct 6, 2010 at 20:12

1 Answer 1

2

if you want the full url you should use Request.Url.OriginalString, because AbsolutePath will omit the host part of the url.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.