0

I have a web application in asp.net/c# 4.5

I have an href element on my front-end like below:

<a href="" id="myhref" runat="server"> my text </a>

What I want is to set an href and innerText to the element using c#, but the content will be starting with ~/

So in the code what I do:

myhref.href = "~/default.aspx?id=" + ID;
myhref.InnerText= "~/default.aspx?id=" + ID;

The problem is even though href looks like "http://localhost:12345/default.aspx?id=10" and once clicked it navigates the user to the correct page, the inner text on the screen is "~/default.aspx?id=10". I need the innerText to show the complete address on the screen as well. How can I provide it?

Thanks

  • maybe see here: https://stackoverflow.com/questions/26189953/how-to-get-current-domain-name-in-asp-net/26190007 – pcalkins Aug 16 '21 at 20:22

1 Answers1

0

Check this post out. https://stackoverflow.com/a/1214619/15082946

Hopefully that will help you :)

using System.Web;

Uri MyUrl = Request.Url; <----
 Response.Write("URL Port: " + MyUrl.Port + "<br>");
MeDead
  • 197
  • 2
  • 9