Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# asp.net中的根目录不需要硬代码_C#_Asp.net - Fatal编程技术网

C# asp.net中的根目录不需要硬代码

C# asp.net中的根目录不需要硬代码,c#,asp.net,C#,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

我试图发送邮件给一个用户,并为他提供一个授权链接,以激活他的帐户,但我硬编码的链接。有没有办法不需要硬代码

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>";
stringurl=”http://localhost:3876/User/Authenticate-User.aspx?emailID=“+emailfield;
string msgBody=“亲爱的用户”+“感谢您的关注,请单击下面的URL进行身份验证


”+ “

”+ “\r\n关于,
团队

”;
您可以使用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);
}

您可以使用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);
}

那么问题出在哪里呢。我想你是在动态生成ActivateLink。如果要向每个用户发送相同的消息,则可以。你希望它是怎样的?那么问题是什么。我想你是在动态生成ActivateLink。如果要向每个用户发送相同的消息,则可以。你想怎么样?非常感谢!!这两个答案都投了赞成票,表示感谢。必须确保生成ActivationLink的文件与Authenticate-User.aspx位于同一文件夹中。否则请使用Server.MapPath。非常感谢!!这两个答案都投了赞成票,表示感谢。必须确保生成ActivationLink的文件与Authenticate-User.aspx位于同一文件夹中。否则请使用Server.MapPath。非常感谢!!两个答案都很正确,都投了两个谢谢的票!!两人的回答都是正确的,都投了赞成票,谢谢