2

asp.net mvc Web アプリケーションがあり、外部の cron ジョブが特定の URL を呼び出して、CronJobController次のような特定のメソッドを実行しています。

/// <summary>
    /// Will be called externally by www.setcronjob.com.
    /// </summary>
    /// <returns></returns>
    public async Task<ActionResult> Index()
    {
        RunTwitterSearchQuery();
        RunFacebookSearchQuery();
        return new ContentResult { Content = "Ok" };
    }

RunTwitterSearchQuery で、いくつかのメールを送信したいので、たとえばMvcMailerActionMailerの両方を試しました(ActionMailer を使用):

var mailController = new MailController();
mailController.HttpContextBase = this.HttpContext;
mailController.MoreThanXFollowersEmail(alertEmailModel).Deliver();

http コンテキストが null であるため、NPE を回避するためにこのように設定する必要がありますが、その後、非常に奇妙な例外を受け取ります (MvcMailer と ActionMailer の両方で):

    System.ArgumentException: Value does not fall within the expected range.
at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
       at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode)
       at System.Web.Hosting.IIS7WorkerRequest.GetUserAgentInternal()
       at System.Web.Hosting.IIS7WorkerRequest.GetKnownRequestHeader(Int32 index)
       at System.Web.HttpRequest.get_UserAgent()
       at System.Web.HttpRequestWrapper.get_UserAgent()
       at System.Web.WebPages.BrowserHelpers.GetOverriddenUserAgent(HttpContextBase httpContext)
       at System.Web.WebPages.BrowserHelpers.GetOverriddenBrowser(HttpContextBase httpContext, Func`2 createBrowser)
       at System.Web.WebPages.BrowserHelpers.GetOverriddenBrowser(HttpContextBase httpContext)
       at System.Web.WebPages.DisplayModeProvider.<.ctor>b__2(HttpContextBase context)
       at System.Web.WebPages.DefaultDisplayMode.CanHandleContext(HttpContextBase httpContext)
       at System.Web.WebPages.DisplayModeProvider.<>c__DisplayClass6.<GetAvailableDisplayModesForContext>b__5(IDisplayMode mode)
       at System.Linq.Enumerable.WhereListIterator`1.MoveNext()
       at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
       at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
       at System.Web.Mvc.VirtualPathProviderViewEngine.GetPath(ControllerContext controllerContext, String[] locations, String[] areaLocations, String locationsPropertyName, String name, String controllerName, String cacheKeyPrefix, Boolean useCache, String[]& searchedLocations)
       at System.Web.Mvc.VirtualPathProviderViewEngine.FindView(ControllerContext controllerContext, String viewName, String masterName, Boolean useCache)
       at System.Web.Mvc.ViewEngineCollection.<>c__DisplayClassc.<FindView>b__a(IViewEngine e)
       at System.Web.Mvc.ViewEngineCollection.Find(Func`2 lookup, Boolean trackSearchedPaths)
       at System.Web.Mvc.ViewEngineCollection.FindView(ControllerContext controllerContext, String viewName, String masterName)
       at ActionMailer.Net.Mvc.EmailResult.LocateViews(ControllerContext context) in c:\Dev\actionmailer\src\ActionMailer.Net.Mvc\EmailResult.cs:line 127
       at ActionMailer.Net.Mvc.EmailResult.AddMessageViews(ControllerContext context) in c:\Dev\actionmailer\src\ActionMailer.Net.Mvc\EmailResult.cs:line 155
       at ActionMailer.Net.Mvc.EmailResult.ExecuteResult(ControllerContext context) in c:\Dev\actionmailer\src\ActionMailer.Net.Mvc\EmailResult.cs:line 98
       at ActionMailer.Net.Mvc.MailerBase.Email(String viewName, Object model, String masterName, Boolean trimBody) in c:\Dev\actionmailer\src\ActionMailer.Net.Mvc\MailerBase.cs:line 166
       at SocialCrm.Controllers.MailController.MoreThanXFollowersEmail(AlertEmailModel model) in c:\dev\palminfo\SocialCrm\SocialCrm\Controllers\MailController.cs:line 18
       at SocialCrm.Controllers.CronJobController.SendAlertEmail(SearchResultModel searchResultModel, Int32 searchQueryId, List`1 alerts, String emailTo, String streamName) in c:\dev\palminfo\SocialCrm\SocialCrm\Controllers\Batch\CronJobController.cs:line 146
       at SocialCrm.Controllers.CronJobController.<RunTwitterSearchQuery>b__3() in c:\dev\palminfo\SocialCrm\SocialCrm\Controllers\Batch\CronJobController.cs:line 83

これは非常に醜いので、この問題について何か助けていただければ幸いです。

更新: MvcMailer を使用している場合、これは私が受け取るエラーです。

4

1 に答える 1

0

MvcMailer を使用している場合は、非常によく似た問題について github に投稿された解決策を試してください。解決策は、メールが送信されるたびに新しい UserMailer を作成することでした: Github Answer

于 2013-10-24T21:30:13.003 に答える