【发布时间】:2013-07-18 02:30:35
【问题描述】:
我有一个控制器
public class InvitationController : Controller
{
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Create(InvitationModel invitationmodel)
{
if (ModelState.IsValid)
{
var regLink = _repo.SaveAndGetRegistrationLink(invitationmodel);
IEMailer mailer = new EMailer();
var inv = mailer.Invitation(invitationmodel.Email, regLink);
await Task.WhenAll(new AsyncEmailSender().SendEmail(inv));
return RedirectToAction("Index");
}
return View(invitationmodel);
}
}
它在我的本地主机上运行良好(发送电子邮件后重定向到所需的页面)。 我将我的网站发布到 smarterasp.net
现在它显示一个字符串而不是重定向:
System.Threading.Tasks.Task`1[System.Web.Mvc.ActionResult]
是什么原因,如何解决?
Elmah 没有记录任何内容。电子邮件实际上已发送。
我尝试添加 MVC dll。以下所有文件都位于我的网站 dll 旁边。
- System.Web.Mvc
- Microsoft.Web.Infrastructure
- System.Web.Razor
- System.Web.WebPages
- System.Web.WebPages.Razor
- System.Web.Helpers
编辑
主机管理员从 iis 向我发送了一条日志:
Exception: System.NullReferenceException
Message: Object reference not set to an instance of an object.
StackTrace: at System.Web.ThreadContext.AssociateWithCurrentThread(Boolean setImpersonationContext)
at System.Web.HttpApplication.OnThreadEnterPrivate(Boolean setImpersonationContext)
at System.Web.LegacyAspNetSynchronizationContext.CallCallbackPossiblyUnderLock(SendOrPostCallback callback, Object state)
at System.Web.LegacyAspNetSynchronizationContext.CallCallback(SendOrPostCallback callback, Object state)
at System.Web.LegacyAspNetSynchronizationContext.Post(SendOrPostCallback callback, Object state)
at System.Threading.Tasks.SynchronizationContextAwaitTaskContinuation.PostAction(Object state)
at System.Threading.Tasks.AwaitTaskContinuation.RunCallback(ContextCallback callback, Object state, Task& currentTask)
--- End of stack trace from previous location where exception was thrown ---
at System.Threading.Tasks.AwaitTaskContinuation.<ThrowAsyncIfNecessary>b__1(Object s)
at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
【问题讨论】:
-
您是否发布了
System.Web.Mvc.dll?听起来服务器使用的是旧版本。 -
我试过了——同样的事情
-
.NET、ASP.NET 和 ASP.NET-MVC 哪个版本?
-
@JohnSaunders .NOT 4.5,MVC 4
-
对
async的支持是 C# 5.0/ASP.NET 4.5 的一部分。
标签: c# .net asp.net-mvc asp.net-mvc-4