Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6810433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:12:18+00:00 2026-05-26T20:12:18+00:00

I have some trouble with returning the message popup in mvc3 when some exception

  • 0
  1. I have some trouble with returning the message popup in mvc3 when
    some exception is thrown .
  2. I’m using PostSharp as a global AOP
    framework to catch the exceptions and handle them building the text
    of the popup .
  3. I’ve extended the ActionResult to custom object that
    in ExecuteResult implements the RenderViewToString method that
    creates the right html code for the messagePopup.
  4. The MessagePopup is shown on the page but the Action continues to perform itself.

How can i stop it from continuing to perform itself ?

When it fails I catch it globally at the

namespace Aop
{
/// <summary>
/// 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
/// </summary>
[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

    /// <summary>
    /// Handles all exception in all the project Ness.DoarKamuti exceptions
    /// </summary>
    /// <param name="eventArgs"></param>
    public override void OnException(MethodExecutionEventArgs eventArgs)
    {
    …
     DefActionResult res = DefActionResult.Create("~/Views/Shared/MessagePopup.ascx",_report , DefConstants.MessageDesign.PopUp, "messagePopupBody");

            eventArgs.ReturnValue = res;
 }

     }

Than it’s building the ActionResult of mine , after handling the message content

public class DefActionResult : ActionResult
{

    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);
    }
}

Then I’m building the response

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();
    }

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 .

I don’t want to handle the errors with the HandleErrorAttribute because it’s not as dynamic as PostSharp .

How can I stop the remains of the original Request ?
(A remark , I am using the Telerik grid for mvc to show the data .)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T20:12:19+00:00Added an answer on May 26, 2026 at 8:12 pm

    To stop the method from proceeding as normal use args.FlowBehavior.Return. The method should do this already unless there is some other mechanism using a try/catch, but your aspect should apply itself as the outer most try/catch. You really need to look at your finale IL of the assembly using ILSpy (none of the other decompilers will see postsharp modifications at this point in time) then you will be able to see what is going on. If you have an action attribute, then I bet it has something to do with it since postsharp will modify the method but the action attribute will not so it remains the outer most controller of flow. Try FlowBehavior first.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good Morning, i have some Trouble with the Zend Framework and Zend_DB_Select, i want
I have some trouble when using SPUtility.SendEmail method in a custom workflow. private void
I have some trouble using Tomcat Client Deployer (TCD) with a local Tomcat installation.
I have some trouble for choosing the right type of exception to throw when
I have some trouble getting the VCS of teamcity work. I'm using perforce and
I have some trouble with my trac installation (version 11.4). What should I do
I have some trouble with jquery ui-events: In my application, there are some sliders.
I have some trouble achieving adequate real-time performance from my application and wondering if
I'm have some trouble with the fulltext CONTAINS operator. Here's a quick script to
I am mlearning javascript and have some trouble creating an onject via prototype. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.