smsohan / MvcMailer

A Mailer for ASP.Net MVC that forms the Email Body using MVC Views (Razor etc.) following Ruby on Rails ActionMailer style
MIT License
582 stars 178 forks source link

Server cannot set content type after HTTP headers have been sent #87

Closed Epstone closed 11 years ago

Epstone commented 11 years ago

Hi, I'm getting the following exception when calling the "populate body" method and I have no idea how to solve this:
Edit: MVCMailer3 nuget package used. [HttpException (0x80004005): Der Server kann den Inhaltstyp nicht festlegen, nachdem HTTP-Header gesendet wurden.] System.Web.HttpResponse.set_ContentType(String value) +9681750 System.Web.UI.Page.SetIntrinsics(HttpContext context, Boolean allowAsync) +236 System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +14 System.Web.UI.Page.ProcessRequest(HttpContext context) +58 System.Web.Mvc.ViewPage.ProcessRequest(HttpContext context) +35 ASP.views_usermailer_test_aspx.ProcessRequest(HttpContext context) in c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\37d509b9\c175c5f\App_Web_xknc2s2q.1.cs:0 System.Web.Mvc.<>cDisplayClass1.b0() +22 System.Web.Mvc.<>cDisplayClass4.b3() +10 System.Web.Mvc.ServerExecuteHttpHandlerWrapper.Wrap(Func1 func) +54 System.Web.Mvc.ServerExecuteHttpHandlerWrapper.Wrap(Action action) +65 System.Web.Mvc.ServerExecuteHttpHandlerWrapper.ProcessRequest(HttpContext context) +71 System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage, VirtualPath path, VirtualPath filePath, String physPath, Exception error, String queryStringOverride) +1729[HttpException (0x80004005): Fehler beim Ausführen der untergeordneten Anforderung für Handler System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerWrapper.] System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage, VirtualPath path, VirtualPath filePath, String physPath, Exception error, String queryStringOverride) +3123183 System.Web.HttpServerUtility.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage) +76 System.Web.HttpServerUtility.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm) +28 System.Web.HttpServerUtilityWrapper.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm) +19 System.Web.Mvc.ViewPage.RenderView(ViewContext viewContext) +248 System.Web.Mvc.WebFormView.RenderViewPage(ViewContext context, ViewPage page) +84 System.Web.Mvc.WebFormView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) +38 System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) +115 Mvc.Mailer.StringResult.ExecuteResult(ControllerContext context) +483 Mvc.Mailer.StringResult.ExecuteResult(ControllerContext context, String mailerName) +163 Mvc.Mailer.MailerBase.EmailBody(String viewName, String masterName) +336 Mvc.Mailer.MailerBase.PopulateHtmlBody(MailMessage mailMessage, String viewName, String masterName) +65 Mvc.Mailer.MailerBase.PopulateBody(MailMessage mailMessage, String viewName, String masterName, Dictionary2 linkedResources) +438 ProjectName.Mailer.UserMailer.SendNewStatusMessage(IUiItemWithImage profile, Int32 senderId, IEnumerable1 emailAddresses, String msgText, IUiItemWithImage messageSender) in C:\Projekte\SpacialStartup\ProjectName.Mailer\UserMailer.cs:140 ProjectName.Management.NotificationService.NewStatusMessage(IUiItemWithImage parentProfile, List1 receiverIds, INewsFeedMessage msg) in C:\Projekte\SpacialStartup\ProjectName.Management\NotificationService.cs:214 ProjectName.Management.NewsfeedManagement.StatusUpdateEmailNotification(IUiItemWithImage parentProfile, Int32 senderUserId, Guid senderKey, List1 receiverIds, NewsfeedMessage msg) in C:\Projekte\SpacialStartup\ProjectName.Management\NewsFeedManagement.cs:109 ProjectName.Management.NewsfeedManagement.UserWritesOnLocationWall(Int32 senderUserID, Guid userKey, NewsfeedMessage msg, Nullable1 usersLocationRole, Location location) in C:\Projekte\SpacialStartup\ProjectName.Management\NewsFeedManagement.cs:84 MVCProject.Controllers.NewsFeedController.AddStatusMessage(Guid parentProfileKey, String text, E_ItemType itemType, String feedType) in C:\Projekte\SpacialStartup\MVCProject\Controllers\NewsFeedController.cs:52 lambdamethod(Closure , ControllerBase , Object[] ) +291 System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +14 System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary2 parameters) +214 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary2 parameters) +27 System.Web.Mvc.<>cDisplayClass15.b12() +55 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func1 continuation) +253 System.Web.Mvc.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() +21 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList1 filters, ActionDescriptor actionDescriptor, IDictionary2 parameters) +191 System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +324 System.Web.Mvc.Controller.ExecuteCore() +106 System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +91 System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10 System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +34 System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +19 System.Web.Mvc.Async.<>c__DisplayClass81.b__7(IAsyncResult ) +10 System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62 System.Web.Mvc.<>cDisplayClasse.bd() +48 System.Web.Mvc.SecurityUtil.b__0(Action f) +7 System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +22 System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +60 System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9629296 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

Can you help me with that? EDIT2: Forget to write that the Mailer Code and also the PopulateBody call is also outside of the MVC Project. Is this okay? Thank you for your time!

Epstone commented 11 years ago

Whoops, I had the UserMailer declared as static. Works now fine again without that keyword... Fail.