Note that there are some explanatory texts on larger screens.

plurals
  1. POMessage Popup Mvc3 with PostSharp OnException handling issue
    primarykey
    data
    text
    <ol> <li>I have some trouble with returning the message popup in mvc3 when some exception is thrown . </li> <li>I'm using PostSharp as a global AOP framework to catch the exceptions and handle them building the text of the popup . </li> <li>I've extended the ActionResult to custom object that in ExecuteResult implements the RenderViewToString method that creates the right html code for the messagePopup. </li> <li>The MessagePopup is shown on the page but the Action continues to perform itself.</li> </ol> <p><strong>How can i stop it from continuing to perform itself ?</strong></p> <p>When it fails I catch it globally at the</p> <pre><code>namespace Aop { /// &lt;summary&gt; /// Handles Aspect Object Programming in all the projects . /// The attribute is being injected through Shared AssemblyInfo.cs to all the /// relevant Assemblies in the project. /// The code of the class is being added to project in compilation time /// and by that improves the response time quality /// &lt;/summary&gt; [Serializable] [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Method | AttributeTargets.Constructor, AllowMultiple = true, Inherited = false)] [MulticastAttributeUsage(MulticastTargets.Method, AllowMultiple = true, AllowExternalAssemblies = true)] public sealed class TraceAttribute : OnMethodBoundaryAspect { [Inject] public IReportBLImpl _reportBL { get; set; } public TraceAttribute() { } #region Runtime semantics /// &lt;summary&gt; /// Handles all exception in all the project Ness.DoarKamuti exceptions /// &lt;/summary&gt; /// &lt;param name="eventArgs"&gt;&lt;/param&gt; public override void OnException(MethodExecutionEventArgs eventArgs) { … DefActionResult res = DefActionResult.Create("~/Views/Shared/MessagePopup.ascx",_report , DefConstants.MessageDesign.PopUp, "messagePopupBody"); eventArgs.ReturnValue = res; } } </code></pre> <p>Than it’s building the ActionResult of mine , after handling the message content</p> <p>public class DefActionResult : ActionResult {</p> <pre><code> public override void ExecuteResult(ControllerContext context) { DefJsonResult model = this.ActionModel; /* If a view name has been specified, render it */ if (!string.IsNullOrEmpty(model.ViewName)) model.ViewHTML = controller.RenderViewToString(model.ViewName, model.ViewModel); JsonResult res = new JsonResult() { Data = model, JsonRequestBehavior = JsonRequestBehavior.AllowGet }; res.ExecuteResult(context); } } </code></pre> <p>Then I’m building the response </p> <pre><code>public static class MVCExtensions { public static string RenderViewToString(this Controller controller, string viewName, object viewData) { //Create memory writer var sb = new StringBuilder(); var memWriter = new StringWriter(sb); //Create fake http context to render the view var fakeResponse = new HttpResponse(memWriter); var fakeContext = new HttpContext(HttpContext.Current.Request, fakeResponse); var fakeControllerContext = new ControllerContext( new HttpContextWrapper(fakeContext), controller.ControllerContext.RouteData, controller.ControllerContext.Controller); var oldContext = HttpContext.Current; HttpContext.Current = fakeContext; //Use HtmlHelper to render partial view to fake context var html = new HtmlHelper(new ViewContext(fakeControllerContext, new FakeView(), controller.ViewData, controller.TempData, memWriter), new ViewPage()); html.ViewDataContainer.ViewData = controller.ViewData; html.RenderPartial(viewName, viewData); //Restore context //HttpContext.Current = oldContext; //Flush memory and return output memWriter.Flush(); return sb.ToString(); } </code></pre> <p>After returning my Message Popup as it should , it continues to the original action as if it didn't crush , and of course crushing because the data source is not initialized .</p> <p>I don’t want to handle the errors with the HandleErrorAttribute because it’s not as dynamic as PostSharp . </p> <p><strong>How can I stop the remains of the original Request ?</strong> (A remark , I am using the Telerik grid for mvc to show the data .)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload