Zin*_*nov 7 c# asp.net-mvc asp.net-mvc-4 asp.net-mvc-5
我有这个字符串格式化,并在此部分抛出异常(字符串体....)
private Task SendEmailConfirmation(UserModel user)
{
var emailService = new EmailUnsecServiceAgent(null);
string 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
{
confirmationToken = user.ConfirmationToken,
email = user.Email
},,
Request.Url.Scheme));
return Task.Run(() => emailService.SendEmail("Confirm your account", body, null, true, null, null, null));
}
Run Code Online (Sandbox Code Playgroud)
confirmationToken并且email是字符串,我的ConfirmEmail是
[AllowAnonymous]
public async Task<ActionResult> ConfirmEmail(string confirmationToken, string email)
{
var securityService = new SecurityUnsecServiceAgent(null);
UserModel user = securityService.GetUserByConfirmationToken(confirmationToken);
if (user != null)
{
if (user.Email == email)
{
user.ConfirmedEmail = true;
securityService.UpdateUser(user);
return View("RegisterMessage");
}
return View("ConfirmEmail", user);
}
return RedirectToAction("ConfirmEmail", user);
}
Run Code Online (Sandbox Code Playgroud)
这是StackTrace:
at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode)
at System.Web.Hosting.IIS7WorkerRequest.GetServerVariableInternal(String name)
at System.Web.Hosting.IIS7WorkerRequest.GetServerVariable(String name)
at System.Web.WebPages.UrlRewriterHelper.WasThisRequestRewritten(HttpContextBase httpContext)
at System.Web.WebPages.UrlRewriterHelper.WasRequestRewritten(HttpContextBase httpContext)
at System.Web.WebPages.UrlUtil.GenerateClientUrlInternal(HttpContextBase httpContext, String contentPath)
at System.Web.WebPages.UrlUtil.GenerateClientUrl(HttpContextBase httpContext, String contentPath)
at System.Web.Mvc.UrlHelper.GenerateUrl(String routeName, String actionName, String controllerName, RouteValueDictionary routeValues, RouteCollection routeCollection, RequestContext requestContext, Boolean includeImplicitMvcValues)
at System.Web.Mvc.UrlHelper.GenerateUrl(String routeName, String actionName, String controllerName, RouteValueDictionary routeValues)
at System.Web.Mvc.UrlHelper.Action(String actionName, String controllerName, Object routeValues)
at SendEmailConfirmation(UserModel user) in c:\Projects\..\Controllers\AccountController.cs:line 361
at Controllers.AccountController.<>c__DisplayClass21.<Register>b__1d() in c:\Projects\..\Controllers\AccountController.cs:line 318
at System.Threading.Tasks.Task`1.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
Run Code Online (Sandbox Code Playgroud)
C B*_*uer 14
URL助手可能在请求被销毁后尝试创建URL(因为它是异步的).在这种情况下,尝试Url.Action()时会出错.
尝试在非异步控制器中生成电子邮件正文,并将其作为参数发送到您的电子邮件类中.
这个问题自定义任务运行方法引发的ArgumentException似乎是密切相关的,你看到的(下降到堆栈跟踪和OP到达一个答案的方法).
| 归档时间: |
|
| 查看次数: |
5713 次 |
| 最近记录: |