简体   繁体   English

ASP.Net Core 2.2 App中身份控制器的扩展方法

[英]Extension methods for Identity Controllers in ASP.Net Core 2.2 App

In my older MVC app I had some extension methods like the one below 在我较老的MVC应用中,我有一些扩展方法,例如以下

 public static string ChangePasswordCallbackLink(this IUrlHelper urlHelper, string appUserId, string parameter)
 {
     return urlHelper.Action(
            action: nameof(AccountController.ChangePassword),
            controller: "Account",
            values: new { appUserId, parameter}
            );
 }

Since there is no longer an account controller (something I still don't understand in Core) when you scaffold out the identity pages in the default Asp.Net Core 2.2 Web Application, how does one go about creating this type of extension? 当您不再使用默认的Asp.Net Core 2.2 Web应用程序中的身份页面时,由于不再有帐户控制器(我在Core中仍然不了解这一点),如何创建这种类型的扩展?

AccountController is just a scaffolded class containing basic logic for user account management, you can create it easily on your own. AccountController只是一个脚手架类,包含用于用户帐户管理的基本逻辑,您可以轻松地自行创建它。 I did HomeController containing ChangePassword action method and HomePage with predefined parameters for the link: 我做了HomeController,其中包含ChangePassword动作方法和带有预定义参数的HomePage链接:

public static class Extensions
    {
        public static string ChangePasswordCallbackLink(this IUrlHelper urlHelper, string appUserId, string parameter)
        {
            return urlHelper.Action(
                action: nameof(HomeController.ChangePassword),
                controller: "Home",
                values: new { appUserId, parameter }
            );
        }
    }
    public class HomeController : Controller
    {
        public IActionResult ChangePassword(string appUserId, string parameter)
        {
            return View();
        }
        public IActionResult Index()
        {
            var link = Url.ChangePasswordCallbackLink("123", "qwerty");
            return View(model: link);
        }
    }

Written extension method still works well 书面扩展名方法仍然有效

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ASP.Net Core 2.2 Web App中的自定义身份 - Custom Identity in ASP.Net Core 2.2 Web App Asp.Net Core 2.2身份验证 - Asp.Net Core 2.2 Identity Authentication 如何将身份用户从 MVC5 应用程序迁移到 ASP.NET Core 2.2 应用程序 - How to migrate Identity users from a MVC5 app to a ASP.NET Core 2.2 app 如何在ASP.NET Core 2.2中实现身份 - How to implement Identity in ASP.NET Core 2.2 Asp.Net Core Identity 2.2和Identity Server 4,更改用户ID类型会导致数据库上下文错误 - Asp.Net Core Identity 2.2 and Identity Server 4, Changing User Id type results in an error in the db context ASP.NET CORE 2.2 WEB APP 中的 Session 过期问题 - Session expire problen in ASP.NET CORE 2.2 WEB APP 无法通过UserManager更新用户 <TUser> 在asp.net core 2.2应用程序中使用ef core 2.2 - unable to update user via UserManager<TUser> using ef core 2.2 in asp.net core 2.2 app ASP.NET Core 控制台应用找不到控制器 - ASP.NET Core console app cannot find controllers 扩展方法中的ASP.NET核心依赖注入 - ASP.NET Core Dependecy Injection in Extension Methods 在ASP.NET Core中使用扩展方法中的中间件配置 - Using middleware config from extension methods in ASP.NET Core
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM