2011-03-15 46 views
0

我試着發送郵件給用戶,並提供給他一個認證鏈接來激活他的帳戶,但我很難編碼鏈接。有沒有什麼辦法,我需要不硬編碼在asp.net中的根目錄不需要硬編碼

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>"; 
+0

那麼最新的問題。我猜你正在動態生成ActivateLink。如果將相同的消息發送給每個用戶,那麼它就可以。你想如何? – 2011-03-15 12:35:23

回答

1
string ActivationLink=Request.Url.ToString().Substring(0, Request.Url.ToString().LastIndexOf('/')) + "/Authenticate-User.aspx?emailID=" + emailfield; 
+0

非常感謝!兩個答案都投了贊成 – abhijit 2011-03-15 12:54:48

+0

只需要確保生成ActivationLink的文件與Authenticate-User.aspx在同一個文件夾中。否則使用Server.MapPath。 – 2011-03-15 13:06:10

2

你可以得到正確的地址,其中一個頁面是用Request.Url

主辦我找到「GetComponents」的方法最靈活的,你可以用Intellisense輕鬆查看您的選項。

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); 
} 
+0

非常感謝!這兩個答案都投了贊成謝謝 – abhijit 2011-03-15 12:55:31

相關問題