[Mono-dev] ASP.MVC Accesing HttpContext.Current from AsyncController action..
Pablo Ruiz
pablo.ruiz at gmail.com
Sat Oct 2 20:03:32 EDT 2010
I have an ASP MVC2 application (running under mono 2.8 p1) which has an
async action (ValidateAsync) which handles user verification by consulting
an external subsystem (hence the async nature of the operation), after a
valid response it's received by the async completed method
(ValidateCompleted), the user it's authenticated by using
FormsAuthentication..
The code it's working ok on MS side, however, on mono looks like
HttpContext.Current it's not (re-)set before calling async action response
method..
Has anyone tried MVC2 Async action methods on mono?
Here it's a stacktrace of the failure:
System.Web.HttpException: Context is null!
at System.Web.Security.FormsAuthentication.SetAuthCookie
(string,bool,string) [0x00042] in
/usr/src/redhat/BUILD/mono-2.8/mcs/class/System.Web/System.Web.Security/FormsAuthentication.cs:654
at System.Web.Security.FormsAuthentication.SetAuthCookie (string,bool)
[0x00005] in /usr/src/redhat/BUILD/mono-2.8/mcs/class/System.Web/System.Web.Security/FormsAuthentication.cs:640
at Herma.WebSite.FormsAuthenticationService.SignIn (string,bool)
[0x0001b] in /srv/hudson/workspace/Herma-v1.x/BUILD/Herma/WebSite/Services/FormsAuthenticationService.cs:25
at Herma.WebSite.Controllers.AccountController.ValidateCompleted
(Herma.WebSite.Models.AccountValidationModel,Herma.Messaging.AccountValidationRes)
[0x0002d] in /srv/hudson/workspace/xxx-v1.x/BUILD/xxx/WebSite/Controllers/AccountController.cs:185
at (wrapper dynamic-method)
System.Runtime.CompilerServices.ExecutionScope.lambda_method
(System.Runtime.CompilerServices.ExecutionScope,System.Web.Mvc.ControllerBase,object[])
<IL 0x00035, 0x00088>
at System.Web.Mvc.ActionMethodDispatcher.Execute
(System.Web.Mvc.ControllerBase,object[]) <IL 0x00008, 0x00018>
at System.Web.Mvc.Async.ReflectedAsyncActionDescriptor/<BeginExecute>c__AnonStorey2E.<>m__34
(System.IAsyncResult) <IL 0x00047, 0x000bf>
at System.Web.Mvc.Async.AsyncResultWrapper/WrappedAsyncResult`1<object>.End
() <0x0004e>
at System.Web.Mvc.Async.AsyncResultWrapper.End<object>
(System.IAsyncResult,object) <0x00035>
at System.Web.Mvc.Async.ReflectedAsyncActionDescriptor.EndExecute
(System.IAsyncResult) <IL 0x00000, 0x0001c>
at System.Web.Mvc.Async.AsyncControllerActionInvoker/<BeginInvokeAsynchronousActionMethod>c__AnonStorey21.<>m__1C
(System.IAsyncResult) <IL 0x00007, 0x00018>
at System.Web.Mvc.Async.AsyncResultWrapper/WrappedAsyncResult`1<System.Web.Mvc.ActionResult>.End
() <0x0004e>
at System.Web.Mvc.Async.AsyncResultWrapper.End<System.Web.Mvc.ActionResult>
(System.IAsyncResult,object) <0x00035>
at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod
(System.IAsyncResult) <IL 0x00000, 0x0001a>
at System.Web.Mvc.Async.AsyncControllerActionInvoker/<BeginInvokeActionMethodWithFilters>c__AnonStorey1E/<BeginInvokeActionMethodWithFilters>c__AnonStorey1F.<>m__27
() <IL 0x00030, 0x00062>
at System.Web.Mvc.Async.AsyncControllerActionInvoker/<InvokeActionMethodFilterAsynchronously>c__AnonStorey25.<>m__20
() <IL 0x00008, 0x00028>
And here it's a sample snippet of the code failing:
[HttpPost]
public void ValidateAsync(AccountValidationModel model)
{
AsyncManager.Parameters["model"] = model;
if (!ModelState.IsValid)
{
AsyncManager.Parameters["result"] = false;
return;
}
try
{
AsyncManager.OutstandingOperations.Increment();
AsyncManager.Timeout = 15000;
_bus.Send<AccountValidationReq>(x =>
{
x.Email = model.Email;
x.Random = model.Code;
})
.Register<AccountValidationRes>(x =>
{
AsyncManager.Parameters["result"] = x;
AsyncManager.OutstandingOperations.Decrement();
});
}
catch (TimeoutException ex)
{
AsyncManager.Parameters["result"] = AccountValidationRes.Timeout;
AsyncManager.OutstandingOperations.Decrement();
_Log.Error("Account validation request timedout", ex);
}
}
public ActionResult ValidateCompleted(AccountValidationModel model,
AccountValidationRes result)
{
if (result == AccountValidationRes.Success)
{
....
FormsService.SignIn(model.Email, false /* createPersistentCookie */);
return this.RedirectToAction<HomeController>(x => x.Index());
}
....
return View(model);
}
Greets.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20101003/ce94446c/attachment-0001.html
More information about the Mono-devel-list
mailing list