Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Try this approach based on ControllerFactory, HttpModule:</p> <p><strong>Steps:</strong></p> <p>1# Create a new 'Class Library' Project. Add reference to your asp.net mvc web application project. Also add reference to 'System.Web', 'System.Web.Mvc', 'Microsoft.Web.Infrastructure.dll' assemblies.</p> <p>2# Create a new Controller class inherited from the controller (TargetController) that has the bug:</p> <pre><code>public class FixedContorller : TargetController { [FixedActionSelector] [ActionName("Index")] public ActionResult FixedIndex() { ViewBag.Title = "I'm Fixed..."; return View(); } } </code></pre> <p>The [FixedActionSelectorAttribute] is ActionSelector attribute, used to resolve the action name.</p> <pre><code> public class FixedActionSelector : ActionMethodSelectorAttribute { public override bool IsValidForRequest(ControllerContext controllerContext, System.Reflection.MethodInfo methodInfo) { return true; } } </code></pre> <p>3# Define a custom ControllerFactory, that will create the fixed controller instead of the target controller:</p> <pre><code>public class MyControllerFactory : DefaultControllerFactory { private static string targetControllerName = "Target"; private static string targetActionName = "Index"; protected override Type GetControllerType(System.Web.Routing.RequestContext requestContext, string controllerName) { var action = requestContext.RouteData.Values["action"].ToString(); if (targetControllerName.Equals(controllerName, StringComparison.InvariantCultureIgnoreCase) &amp;&amp; targetActionName.Equals(action, StringComparison.InvariantCultureIgnoreCase)) { return typeof(FixedContorller); } return base.GetControllerType(requestContext, controllerName); } } </code></pre> <p>4# Now define a HttpModule, that will set the above controller-factory on application init. The httpModule will register itself programmatically, no need to register in web.config.</p> <pre><code>using System; using System.Web; using System.Web.Mvc; [assembly: PreApplicationStartMethod(typeof(YourApp.Patch.FixerModule), "Register")] namespace YourApp.Patch { public class FixerModule : IHttpModule { private static bool isStarted = false; private static object locker = new object(); public void Dispose() { } public void Init(HttpApplication context) { if (!isStarted) { lock (locker) { if (!isStarted) { ControllerBuilder.Current.SetControllerFactory(typeof(MyControllerFactory)); isStarted = true; } } } } public static void Register() { Microsoft.Web.Infrastructure.DynamicModuleHelper.DynamicModuleUtility.RegisterModule(typeof(FixerModule)); } } } </code></pre> <p>Compile the project and copy the .dll in the bin folder of your web application.</p> <p>Hopes this helps...</p>
    singulars
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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