[英]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.