C# Can';在MVC5项目中工作的用户帐户是否无法获得电子邮件验证?

C# Can';在MVC5项目中工作的用户帐户是否无法获得电子邮件验证?,c#,email,asp.net-mvc-5,verification,C#,Email,Asp.net Mvc 5,Verification,在本教程之后,我正在尝试实现这一点: 但是我在连接smtp服务器时遇到问题。我通过www.one.com拥有一个.dk域,我正试图使用我自己的电子邮件登录凭据(代码中也有100%正确的凭据)在他们的SMTP服务器上测试此功能 当前我的注册方法如下所示: [HttpPost] [AllowAnonymous] [ValidateAntiForgeryToken] public async Task<ActionResult> Register(RegisterViewM

在本教程之后,我正在尝试实现这一点:

但是我在连接smtp服务器时遇到问题。我通过www.one.com拥有一个.dk域,我正试图使用我自己的电子邮件登录凭据(代码中也有100%正确的凭据)在他们的SMTP服务器上测试此功能

当前我的注册方法如下所示:

 [HttpPost]
  [AllowAnonymous]
  [ValidateAntiForgeryToken]
  public async Task<ActionResult> Register(RegisterViewModel model)
  {
   if (ModelState.IsValid)
    {
      var user = new ApplicationUser() { UserName = model.UserName };
      user.Email = model.Email;
      user.ConfirmEmail = false;
      var result = await UserManager.CreateAsync(user, model.Password);
      if (result.Succeeded)
       {
           var m = new MailMessage(new MailAddress("gwiz@blackweb.dk", "Web Registration"), new MailAddress(user.Email));
             m.Subject = "Email confirmation";
             m.Body = string.Format("Dear {0} <BR/>Thank you for your registration, please click on the below link to complete your registration: <a href=\"{1}\" title=\"User Email Confirm\">{1}</a>",
             user.UserName, Url.Action("ConfirmEmail", "Account", new { Token = user.Id, Email = user.Email }, Request.Url.Scheme));
           m.IsBodyHtml = true;

        //smtp.Credentials = new NetworkCredential("gwiz@blackweb.dk", "Tengri8971");
        //smtp.EnableSsl = true;    
           var smtp = new SmtpClient();
           smtp.Host = "send.one.com";
           smtp.EnableSsl = true;
           var networkCredential = new NetworkCredential("thecorrectusername", "thecorrectpassword");
           smtp.UseDefaultCredentials = false;
           smtp.Credentials = networkCredential;
           smtp.Port = 465;
           smtp.Send(m);
        return RedirectToAction("Confirm", "Account", new { Email = user.Email });
      }
      else
      {
        AddErrors(result);
      }
    }
  // If we got this far, something failed, redisplay form
    return View(model);
}
[HttpPost]
[异名]
[ValidateAntiForgeryToken]
公共异步任务“,
user.UserName,Url.Action(“ConfirmEmail”,“Account”,new{Token=user.Id,Email=user.Email},Request.Url.Scheme));
m、 IsBodyHtml=true;
//smtp.Credentials=新的网络凭据(“gwiz@blackweb.dk“,“腾格里8971”);
//smtp.EnableSsl=true;
var smtp=new SmtpClient();
smtp.Host=“send.one.com”;
smtp.EnableSsl=true;
var networkCredential=新的网络凭据(“更正者名称”、“更正密码”);
smtp.UseDefaultCredentials=false;
smtp.Credentials=网络凭据;
smtp.Port=465;
smtp.Send(m);
返回重定向操作(“确认”、“帐户”,新建{Email=user.Email});
}
其他的
{
加法器(结果);
}
}
//如果我们走到这一步,有些东西失败了,重新显示形式
返回视图(模型);
}
但是,每当我尝试创建一个新用户时,我都会遇到以下异常(据我在线所知,这意味着它没有正确连接到SMTP服务器?)

Serverfejl i programmet'/'。
Der kunne ikke læses Bindelsen的fra传输数据:网络io连接关闭。
最好的例子是:在自由贸易协定的框架下,在自由贸易协定的框架内,在自由贸易协定的框架内,在自由贸易协定的框架内,在自由贸易协定的框架内,在自由贸易协定的框架内,在自由贸易协定的框架内,在自由贸易协定的框架内,在自由贸易协定的框架内,在自由贸易协定的框架内,在自由贸易协定的框架内,在自由贸易协定的框架内,在自由贸易协定的框架内。
详细信息:System.IO.IOException:Der KUNE IKE læses BINDELSEN的fra传输数据:网络IO连接已关闭。
基尔德费尔:
Linje 404:smtp.Credentials=网络凭据;
Linje 405:smtp.Port=465;
linje406:smtp.Send(m);
Linje 407:返回重定向到操作(“确认”,“帐户”,新{Email=user.Email});
林杰408:}
Kildefil:c:\Users\Giuseppe\Desktop\MEV3\MEV3\Controllers\AccountController.cs Linje:406
Staksporing:
[IOException:Der kunne ikke læses Bindelsen的fra传输数据:网络io连接关闭。]
System.Net.Mail.SmtpReplyReaderFactory.ProcessRead(字节[]缓冲区,Int32偏移量,Int32读取,布尔读线)+1498507
System.Net.Mail.SmtpReplyReaderFactory.ReadLines(SmtpReplyReader调用者,布尔oneLine)+227
System.Net.Mail.SmtpReplyReaderFactory.ReadLine(SmtpReplyReader调用者)+16
System.Net.Mail.SmtpConnection.GetConnection(服务点服务点)+674
System.Net.Mail.SmtpTransport.GetConnection(服务点服务点)+170
System.Net.Mail.SmtpClient.GetConnection()+44
System.Net.Mail.SmtpClient.Send(MailMessage)+1554
[SmtpException:Der optstod en fejl ved afsendelsen af电子邮件。]
System.Net.Mail.SmtpClient.Send(MailMessage)+1906
c:\Users\Giuseppe\Desktop\MEV3\MEV3\Controllers\AccountController.cs:406中的MEV3.Controllers.d\u 20.MoveNext()
System.Runtime.CompilerServices.TaskWaiter.ThrowForNonSuccess(任务任务)+93
System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccessAndDebuggerNotification(任务)+52
System.Runtime.CompilerServices.TaskWaiter.GetResult()+21
lambda_方法(闭包,任务)+64
System.Threading.Tasks.TaskHelperExtensions.ThrowIfFaulted(任务)+64
System.Web.Mvc.Async.TaskAsyncActionDescriptor.EndExecute(IAsyncResult asyncResult)+114
System.Web.Mvc.Async.c__显示类34.b__33(IAsyncResult asyncResult)+65
System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult)+47
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End()+135
System.Web.Mvc.Async.asyncResultRapper.End(IAsyncResult asyncResult,对象标记)+102
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)+49
System.Web.Mvc.Async.AsyncInvocationWithFilters.b__3c()+117
System.Web.Mvc.Async.c__显示类45.b_3e()+323
System.Web.Mvc.Async.c__显示类30.b__2f(IAsyncResult asyncResult)+44
System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult)+47
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End()+135
System.Web.Mvc.Async.asyncResultRapper.End(IAsyncResult asyncResult,对象标记)+102
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult)+50
System.Web.Mvc.Async.c__显示类28.b__19()+72
System.Web.Mvc.Async.c__显示Class1E.b__1b(IAsyncResult asyncResult)+185
System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult)+42
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End()+132
System.Web.Mvc.Async.asyncResultRapper.End(IAsyncResult asyncResult,对象标记)+56
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult)+40
System.Web.Mvc.Controller.b_u1d(IAsyncResult asyncResult,ExecuteCorerate innerState)+34
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)+70
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End()+138
System.Web.Mvc.Async.asyncResultRapper.End(IAsyncResult asyncResult,对象标记)+59
System.Web.Mvc.Async.asyncResultRapper.End(IAsyncResult asyncResult,对象标记)+40
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult)+44
System.Web.Mvc.Controller.b_uu15(IAsyncResult asyncResult,Controller-Controller)+39
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)+62
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End()+138
System.Web.Mvc.Async.asyncResultRapper.End(IAsyncResul
Serverfejl i programmet '/'.
Der kunne ikke læses data fra transportforbindelsen: net_io_connectionclosed.
Beskrivelse: Der opstod en undtagelse, der ikke blev behandlet, under udførelse af den aktuelle webanmodning. Se staksporingen for at få flere oplysninger om fejlen, og hvor den kom fra i koden.

Detaljer om undtagelse: System.IO.IOException: Der kunne ikke læses data fra transportforbindelsen: net_io_connectionclosed.

Kildefejl:


Linje 404:           smtp.Credentials = networkCredential;
Linje 405:           smtp.Port = 465;
Linje 406:           smtp.Send(m);
Linje 407:        return RedirectToAction("Confirm", "Account", new { Email = user.Email });
Linje 408:      }


Kildefil: c:\Users\Giuseppe\Desktop\MEV3\MEV3\Controllers\AccountController.cs    Linje: 406

Staksporing:


[IOException: Der kunne ikke læses data fra transportforbindelsen: net_io_connectionclosed.]
   System.Net.Mail.SmtpReplyReaderFactory.ProcessRead(Byte[] buffer, Int32 offset, Int32 read, Boolean readLine) +1498507
   System.Net.Mail.SmtpReplyReaderFactory.ReadLines(SmtpReplyReader caller, Boolean oneLine) +227
   System.Net.Mail.SmtpReplyReaderFactory.ReadLine(SmtpReplyReader caller) +16
   System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint) +674
   System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint) +170
   System.Net.Mail.SmtpClient.GetConnection() +44
   System.Net.Mail.SmtpClient.Send(MailMessage message) +1554

[SmtpException: Der opstod en fejl ved afsendelsen af e-mail.]
   System.Net.Mail.SmtpClient.Send(MailMessage message) +1906
   MEV3.Controllers.<Register>d__20.MoveNext() in c:\Users\Giuseppe\Desktop\MEV3\MEV3\Controllers\AccountController.cs:406
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +93
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +52
   System.Runtime.CompilerServices.TaskAwaiter.GetResult() +21
   lambda_method(Closure , Task ) +64
   System.Threading.Tasks.TaskHelpersExtensions.ThrowIfFaulted(Task task) +64
   System.Web.Mvc.Async.TaskAsyncActionDescriptor.EndExecute(IAsyncResult asyncResult) +114
   System.Web.Mvc.Async.<>c__DisplayClass34.<BeginInvokeAsynchronousActionMethod>b__33(IAsyncResult asyncResult) +65
   System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +47
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +135
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +102
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +49
   System.Web.Mvc.Async.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3c() +117
   System.Web.Mvc.Async.<>c__DisplayClass45.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3e() +323
   System.Web.Mvc.Async.<>c__DisplayClass30.<BeginInvokeActionMethodWithFilters>b__2f(IAsyncResult asyncResult) +44
   System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +47
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +135
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +102
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +50
   System.Web.Mvc.Async.<>c__DisplayClass28.<BeginInvokeAction>b__19() +72
   System.Web.Mvc.Async.<>c__DisplayClass1e.<BeginInvokeAction>b__1b(IAsyncResult asyncResult) +185
   System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +42
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +132
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +56
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +40
   System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +34
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +70
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +138
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +59
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40
   System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +44
   System.Web.Mvc.Controller.<BeginExecute>b__15(IAsyncResult asyncResult, Controller controller) +39
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +62
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +138
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +59
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40
   System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +39
   System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +39
   System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__4(IAsyncResult asyncResult, ProcessRequestState innerState) +39
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +70
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +138
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +59
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +40
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +38
   System.Web.CallHandlerExecutionStep.OnAsyncHandlerCompletion(IAsyncResult ar) +129


Versionsoplysninger: Microsoft .NET Framework version:4.0.30319; ASP.NET version:4.0.30319.34212