Этот подход работает для NopCommerce 4.10
Этот код перенаправит запросы "/ Register" с помощью метода "GET" на действие "YourCustomAction" внутри "YourCustomController".
Шаг 1:
реализовать INopStartup
public class NopStartup : INopStartup
{
public void ConfigureServices(IServiceCollection services, IConfiguration configuration)
{
services.Configure<MvcOptions>(config =>
{
config.Filters.Add<YourCustomActionFilter>();
});
}
public void Configure(IApplicationBuilder application)
{
}
public int Order => 0;
}
Шаг 2:
public class YourCustomActionFilter : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext context)
{
if (!(context.ActionDescriptor is ControllerActionDescriptor actionDescriptor)) return;
if (actionDescriptor.ControllerTypeInfo == typeof(CustomerController) &&
actionDescriptor.ActionName == "Register" &&
context.HttpContext.Request.Method == "GET")
{
string controllerName = nameof(YourCustomController).Replace("Controller", "");
string actionName = nameof(YourCustomController.YourCustomAction);
var values = new RouteValueDictionary(new
{
action = actionName,
controller = controllerName
});
context.Result = new RedirectToRouteResult(values);
}
}
}
При таком подходе вы можете сократить процесс регистрации и добавить дополнительную проверку / процесс, после чего вы можете перейти к процессу регистрации.