0

i am tryin to send mail to a user and providing him a authetication link to activate his account but i am hard coding the link. is there any way where i need not hard code

string url = "http://localhost:3876/User/Authenticate-User.aspx?emailID=" + emailfield;

string msgBody = "<h3>Dear User</h3>" + "<p>Thanks for your interest, Kindly click on the URL below to authenticate</p><br>" +
                              "<a href='" + url + "'>Activate Link</a><br><br>" +
                              "\r\n<p>With Regards,<br>Team</p>";
1
  • So whats the problem. You are generating ActivateLink dynamically I guess. If the same message is to be sent to every user then it is ok. How you want it to be? Commented Mar 15, 2011 at 12:35

2 Answers 2

2

You can get the correct address for where a page is hosted using Request.Url

I find the "GetComponents" method most flexible in that you can see your options with Intellisense quite easily.

string serverAddress = "http://" + 
HttpContext.Current.Request.Url.GetComponents(UriComponents.Host, UriFormat.SafeUnescaped);
if (!string.IsNullOrEmpty(HttpContext.Current.Request.Url.GetComponents(UriComponents.Port, UriFormat.SafeUnescaped))) {
    serverAddress = serverAddress + ":" + HttpContext.Current.Request.Url.GetComponents(UriComponents.Port, UriFormat.SafeUnescaped);
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot!! both the answer worked up voted for both thanks
1
string ActivationLink=Request.Url.ToString().Substring(0, Request.Url.ToString().LastIndexOf('/')) + "/Authenticate-User.aspx?emailID=" + emailfield;

2 Comments

Thanks a lot!! both the answer worked up voted for both thanks
Just need to make sure the file generating ActivationLink is in same folder as Authenticate-User.aspx. Use Server.MapPath otherwise.

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.