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 wh开发者_如何学Cere 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>";
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);
}
string ActivationLink=Request.Url.ToString().Substring(0, Request.Url.ToString().LastIndexOf('/')) + "/Authenticate-User.aspx?emailID=" + emailfield;
精彩评论