2

I have a page for registering students and an email activation link is sent after submitting records. I have included the link for activation but it gets the whole url and includes it in the email. Can someone show how to solve the issue as currently it sends the whole page url in the email? Here is a sample of what is send to email:

localhost:89192/Staff/Register.aspx?rwndrnd=0.6363636646446373333CompleteRegistration.aspx?id=8901b88k1-81fa-8u10-m96e-892f6aea6710

Below is how am getting the current url

activationUrl = HttpContext.Current.Request.Url.Host+""+"://CompleteAccount.aspx?id=" + id.ToString();
Kristof Claes
  • 10,797
  • 3
  • 30
  • 42
ping
  • 45
  • 10

1 Answers1

4

Simply use

activationUrl = Request.Url.AbsoluteUri

Also, Request.Url.ToString() returns the full url (including querystring)

Linga
  • 10,379
  • 10
  • 52
  • 104
  • This gets for me the whole url currently in the page registration but i needed to include the url+the activation page by getting only the url+ the activation link this format .. `localhost:89192/CompleteRegistration.aspx?id=8901b88k1-81fa-8u10-m96e-892f6aea6710` – ping Jan 16 '14 at 07:22
  • What is your current `url` and what is your expected result? – Linga Jan 16 '14 at 07:31
  • Below is my current url showing when i use activationUrl = Request.Url.AbsoluteUri `http://localhost:89192/Staff/Register.aspx?rwndrnd=0.6363636646446373333` my expexted result is to include my Activation Page which is `CompleteRegistration.aspx?id=8901b88k1-81fa-8u10-m96e-892f6aea6710` when sending the email link.The url changes at times since have published it.I was hard coding but i now need it to include the current url+the activation page link – ping Jan 16 '14 at 07:48
  • Unclear with your comment, if you want to change url try `Response.Redirect("~/CompleteRegistration.aspx?id=8901b88k1-81fa-8u10-m96e-892f6aea6710");` – Linga Jan 16 '14 at 08:12
  • This is what i mean,i have a page called Activate Account and another page called Register.When one registers,an email is send to him which contains the url with link to Activate Account.My application runs locally in my machine and have also published it whereby i have also the link for that.I needed it to act in a way such that if i am running it on the remote server,it picks that url too.I had coded it but i need always to pick the curreny url whether locall url address or the remote url.I hope this gives light to you now – ping Jan 16 '14 at 08:20
  • Do you want to check whether the current url is local or remote? – Linga Jan 16 '14 at 08:27
  • Yes really.thats what i need to – ping Jan 16 '14 at 08:34
  • http://stackoverflow.com/questions/2528415/check-if-the-path-input-is-url-or-local-file – Linga Jan 16 '14 at 08:53
  • several questions are already asked. refer http://stackoverflow.com/questions/354477/method-to-determine-if-path-string-is-local-or-remote-machine – Linga Jan 16 '14 at 08:54
  • @Jopito have you got it? – Linga Jan 16 '14 at 09:15
  • my server has gone down and i cannot confirm whether its solved so as i can test the remote URL,however.this is what i have used in my code and seems to be what i was looking at.Below is the snippet of code i have used `activationUrl = Request.Url.GetComponents(UriComponents.SchemeAndServer, UriFormat.Unescaped);` `newUrl = activationUrl + VirtualPathUtility.ToAbsolute("~/ActivateAccount.aspx?id=" + id.ToString() + HttpUtility.UrlEncode(newUrl));` – ping Jan 16 '14 at 14:21