2

I'm trying to set my user variable in my link equal to the current user's username.

Here is what I have:

<li><a runat="server" href="~/Profiles?user=<%: Context.User.Identity.GetUserName() %>">Profile</a></li>

The url that I end up getting is this:

/Profiles?user=<%:%20Context.User.Identity.GetUserName()%20%>

How do I amend my code to properly place the username in the url?

I'm using the webforms template and identity 2.0

hildk
  • 149
  • 1
  • 7
  • I don't know if there is a canonical duplicate for such questions, so meanwhile [this](http://stackoverflow.com/q/32477107/728795) should suffice – Andrei Sep 21 '15 at 22:27
  • Constructing url with string concatenation should be used only when you've learnt URI RFC by heart. Otherwise - use existing methods - http://stackoverflow.com/questions/14517798/append-values-to-query-string. After properly constructing url use link suggested by @Andrei to write it as href. – Alexei Levenkov Sep 21 '15 at 22:38

1 Answers1

1

You can get the HREF attribute set at runtime though like

Design:

<li><a id="A1" runat="server">Profile</a></li>

In Code:

this.A1.HRef = "~/Profiles?user=" + Context.User.Identity.Name;
Rahul
  • 76,197
  • 13
  • 71
  • 125