广告位联系
返回顶部
分享到

ASP.NET MVC使用Identity增删改查用户

asp.net 来源:互联网 作者:佚名 发布时间:2022-10-25 21:41:09 人浏览
摘要

源码在这里:https://github.com/darrenji/UseIdentityCRUDUserInMVC,本地下载 在VS2013中创建一个MVC项目,用默认的无身份验证作为身份验证机制。 通过控制台下载Bootstrap。 Install-Package -version 3.0.

源码在这里:https://github.com/darrenji/UseIdentityCRUDUserInMVC,本地下载

在VS2013中创建一个MVC项目,用默认的"无身份验证"作为身份验证机制。

通过控制台下载Bootstrap。

Install-Package -version 3.0.3 bootstrap

下载成功后,在解决方案下的Content和Scripts多了该版本的css和js文件。

把创建项目默认HomeController中的所有Action以及/Views/Home下的所有视图删除。

热热身

先来做一个简单练习。

在HomeController中的Index方法中,把一个字典传递给视图。

1

2

3

4

5

6

7

8

9

public class HomeController : Controller

{

    public ActionResult Index()

    {

        Dictionary<string, object> data = new Dictionary<string, object>();

        data.Add("placeholder", "placeholder");

        return View(data);

    }

}

_Layout.cshtml设置如下:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

    <meta charset="utf-8" />

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>ASP.NET Identity实战</title>

    <link href="~/Content/bootstrap.min.css" rel="external nofollow"  rel="stylesheet" />

    <link href="~/Content/bootstrap-theme.min.css" rel="external nofollow"  rel="stylesheet" />

    <style>

        .container {padding-top:10px;}

        .validation-summary-errors{color:red;}

    </style>

</head>

<body>

     

    <div class="container">

        @RenderBody()

    </div>

    @Scripts.Render("~/bundles/jquery")

    @Scripts.Render("~/bundles/bootstrap")

    @RenderSection("scripts", required: false)

</body>

Home/Index.cshtml视图中:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

@{

    ViewBag.Title = "Index";

    Layout = "~/Views/Shared/_Layout.cshtml";

}

<div class="panel panel-primary">

    <div class="panel-heading">用户明细</div>

    <table class="table table-striped">

        @foreach (string key in Model.Keys)

        {

            <tr>

                <th>@key</th>

                <td>@Model[key]</td>

            </tr>

        }

    </table>

</div>

前期准备

分别安装如下组件。

Install-Package Microsoft.AspNet.Identity.EntityFramework –Version 2.0.0
Install-Package Microsoft.AspNet.Identity.OWIN -Version 2.0.0
Install-Package Microsoft.Owin.Host.SystemWeb -Version 2.1.0

配置Web.config如下:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

<?xml version="1.0" encoding="utf-8"?>

<!--

  有关如何配置 ASP.NET 应用程序的详细信息,请访问

  http://go.microsoft.com/fwlink/?LinkId=301880

  -->

<configuration>

  <configSections>

    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->

    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />

  </configSections>

  <connectionStrings>

    <add name="IdentityDb" providerName="System.Data.SqlClient" connectionString="Data Source=(localdb)\v11.0;Initial Catalog=IdentityDb;Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False;MultipleActiveResultSets=True"/>

</connectionStrings>

  <appSettings>

    <add key="webpages:Version" value="3.0.0.0" />

    <add key="webpages:Enabled" value="false" />

    <add key="ClientValidationEnabled" value="true" />

    <add key="UnobtrusiveJavaScriptEnabled" value="true" />

    <add key="owin:AppStartup" value="WebApplication4.IdentityConfig" />

  </appSettings>

  <system.web>

    <compilation debug="true" targetFramework="4.5" />

    <httpRuntime targetFramework="4.5" />

  </system.web>

  <runtime>

    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">

      <dependentAssembly>

        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />

        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />

      </dependentAssembly>

      <dependentAssembly>

        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />

        <bindingRedirect oldVersion="1.0.0.0-5.0.0.0" newVersion="5.0.0.0" />

      </dependentAssembly>

      <dependentAssembly>

        <assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />

        <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />

      </dependentAssembly>

      <dependentAssembly>

        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />

        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />

      </dependentAssembly>

      <dependentAssembly>

        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />

        <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />

      </dependentAssembly>

    </assemblyBinding>

  </runtime>

  <entityFramework>

    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />

    <providers>

      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />

    </providers>

  </entityFramework>

</configuration>

以上,

  • 增加了connectionStrings节点,将自动创建localdb数据库
  • 在appSettings节点中增加了一个key为owin:AppStartup项,这是确保OWIN运行正常的全局配置

在Models文件夹下创建如下类。

1

2

3

public class AppUser : IdentityUser

{

}

在解决方案下创建Infrastructure文件夹。

在Infrastructure文件夹下创建一个上下文类,需要实现IdentityDbContext<>接口。

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

public class AppIdentityDbContext : IdentityDbContext<AppUser>

 {

     public AppIdentityDbContext()

         : base("IdentityDb")

     {

     }

     static AppIdentityDbContext()

     {

         //使用EF Code First第一次创建的时候调用

         Database.SetInitializer<AppIdentityDbContext>(new IdentityDbInit());

     }

     public static AppIdentityDbContext Create()

     {

         return new AppIdentityDbContext();

     }

 }

 //初始化

 public class IdentityDbInit : DropCreateDatabaseIfModelChanges<AppIdentityDbContext>

 {

     protected override void Seed(AppIdentityDbContext context)

     {

         PerformInitialSetup(context);

         base.Seed(context);

     }

     //初始化工作

     public void PerformInitialSetup(AppIdentityDbContext context)

     { }

 }

在Infrastructure文件夹下创建一个管理用户的类,需要继承UserManager<AppUser>类。

还记得,先前在appSettings节点中配置了一个如下方式:

<add key="owin:AppStartup" value="WebApplication4.IdentityConfig" />

OWIN需要一个全局启动文件,默认会到项目的顶级命名空间下找IdentityConfig这个类。

那就在App_Start中创建IdentityConfig这个类,这个类在WebApplication4这个命名空间下。

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

namespace WebApplication4

{

    public class IdentityConfig

    {

        public void Configuration(IAppBuilder app)

        {

            app.CreatePerOwinContext<AppIdentityDbContext>(AppIdentityDbContext.Create);

            app.CreatePerOwinContext<AppUserManager>(AppUserManager.Create);

            app.UseCookieAuthentication(new CookieAuthenticationOptions {

                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,

                LoginPath = new Microsoft.Owin.PathString("/Account/Login")

            });

        }

    }

}

显示用户

创建AdminController,现在可以向视图传递所有的用户了,编写如下:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

public class AdminController : Controller

{

    public ActionResult Index()

    {

        return View(UserManager.Users);

    }

    private AppUserManager UserManager

    {

        get

        {

            return HttpContext.GetOwinContext().GetUserManager<AppUserManager>();

        }

    }

}

再创建Admin/Index.cshtml类型为IEnumerable<AppUser>的强类型视图。

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

@model IEnumerable<WebApplication4.Models.AppUser>

@{

    ViewBag.Title = "Index";

    Layout = "~/Views/Shared/_Layout.cshtml";

}

<div class="panel panel-primary">

    <div class="panel-heading">

        所有用户账户

    </div>

    <table class="table table-striped">

        <tr><th>ID</th><th>Name</th><th>Email</th><th></th></tr>

        @if (Model.Count() == 0)

        {

            <tr><td colspan="4" class="text-center">还没有创建用户</td></tr>

        }

        else

        {

            foreach (WebApplication4.Models.AppUser user in Model)

            {

                <tr>

                    <td>@user.Id</td>

                    <td>@user.UserName</td>

                    <td>@user.Email</td>

                    <td>

                        @using (Html.BeginForm("Delete", "Admin",

                            new { id = user.Id }))

                        {

                            @Html.ActionLink("编辑", "Edit", new { id = user.Id },

                                    new { @class = "btn btn-primary btn-xs" })

                            <button class="btn btn-danger btn-xs"

                                    type="submit">

                                删除

                            </button>

                        }

                    </td>

                </tr>

            }

        }

    </table>

</div>

@Html.ActionLink("创建用户", "Create", null, new { @class = "btn btn-primary" })

创建用户

在Models文件夹下创建一个视图模型。

1

2

3

4

5

6

7

8

9

10

11

12

13

namespace WebApplication4.Models

{

    public class CreateModel

    {

        public string Id { get; set; }

        [Required]

        public string Name { get; set; }

        [Required]

        public string Email { get; set; }

        [Required]

        public string Password { get; set; }

    }

}

在AdminController中添加创建用户相关的方法。

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

public class AdminController : Controller

 {

     public ActionResult Index()

     {

         return View(UserManager.Users);

     }

     //创建显示

     public ActionResult Create()

     {

         return View();

     }

     [HttpPost]

     public async Task<ActionResult> Create(CreateModel model)

     {

         if(ModelState.IsValid)

         {

             var user = new AppUser{UserName = model.Name, Email = model.Email};

             IdentityResult result = await UserManager.CreateAsync(user, model.Password);

             if(result.Succeeded)

             {

                 return RedirectToAction("Index");

             }else{

                 AddErrorsFromResult(result);

             }

         }

         return View(model);

     }

     //创建接收

     private void AddErrorsFromResult(IdentityResult result)

     {

         foreach(var error in result.Errors)

         {

             ModelState.AddModelError("", error);

         }

     }

     private AppUserManager UserManager

     {

         get

         {

             return HttpContext.GetOwinContext().GetUserManager<AppUserManager>();

         }

     }

 }

在Admin/Create.cshtml视图页中:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

@model WebApplication4.Models.CreateModel

@{

    ViewBag.Title = "Create";

    Layout = "~/Views/Shared/_Layout.cshtml";

}

<h2>Create</h2>

@using (Html.BeginForm())

{

    @Html.AntiForgeryToken()

     

    <div class="form-horizontal">

        <h4>创建用户</h4>

        <hr />

        @Html.ValidationSummary(true)

        <div class="form-group">

            @Html.LabelFor(model => model.Name, new { @class = "control-label col-md-2" })

            <div class="col-md-10">

                @Html.EditorFor(model => model.Name)

                @Html.ValidationMessageFor(model => model.Name)

            </div>

        </div>

        <div class="form-group">

            @Html.LabelFor(model => model.Email, new { @class = "control-label col-md-2" })

            <div class="col-md-10">

                @Html.EditorFor(model => model.Email)

                @Html.ValidationMessageFor(model => model.Email)

            </div>

        </div>

        <div class="form-group">

            @Html.LabelFor(model => model.Password, new { @class = "control-label col-md-2" })

            <div class="col-md-10">

                @Html.EditorFor(model => model.Password)

                @Html.ValidationMessageFor(model => model.Password)

            </div>

        </div>

        <div class="form-group">

            <div class="col-md-offset-2 col-md-10">

                <input type="submit" value="创建用户" class="btn btn-default" />

            </div>

        </div>

    </div>

}

<div>

    @Html.ActionLink("返回", "Index")

</div>

点击"创建"按钮,创建成功返回显示用户页面。

oh, my god,只是配置了一下就有数据了? 数据在哪呢?

点击左上角的"服务器资源管理器",右键"IdentityDb",点击"刷新"。

再打开AspNetUsers表,刚创建的用户赫然在列。

好像还有点欠缺,用户输入密码的时候,总应该有些限制吧。

能想到的,ASP.NET Identity都为我们准备好了。有一个PasswordValidator类就是干这个的。

在Infrastructure文件夹中创建一个PasswordValidator类的继承子类。

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

namespace WebApplication4.Infrastructure

{

    public class CustomPasswordValidator : PasswordValidator

    {

        public override async Task<IdentityResult> ValidateAsync(string pass)

        {

            IdentityResult result = await base.ValidateAsync(pass);

            if (pass.Contains("12345"))

            {

                var errors = result.Errors.ToList();

                errors.Add("密码中包含太多连续数字");

                result = new IdentityResult(errors);

            }

            return result;

        }

    }

}

然后需要把这个规则告诉UserManager。

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

namespace WebApplication4.Infrastructure

{

    public class AppUserManager : UserManager<AppUser>

    {

        public AppUserManager(IUserStore<AppUser> store) : base(store) { }

        public static AppUserManager Create(IdentityFactoryOptions<AppUserManager> options, IOwinContext context)

        {

            //identity ef上下文

            AppIdentityDbContext db = context.Get<AppIdentityDbContext>();

            //与identity ef相关的UserStore

            IUserStore<AppUser> us = new UserStore<AppUser>(db);

            AppUserManager manager = new AppUserManager(us);

            //密码相关

            manager.PasswordValidator = new CustomPasswordValidator {

                RequiredLength = 6,

                RequireNonLetterOrDigit = false,

                RequireDigit = false,

                RequireLowercase = true,

                RequireUppercase = true

            };

            return manager;

        }

    }

}

再次运行程序,创建用户页面,尝试输入不通过的密码。

不过,关于密码的规则,似乎可以在View Model的验证层面就可以解决掉。

编辑和删除用户

在AdminController中增加编辑和删除的部分。

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

public class AdminController : Controller

{

    public ActionResult Index()

    {

        return View(UserManager.Users);

    }

    //创建显示

    public ActionResult Create()

    {

        return View();

    }

    //创建接收

    [HttpPost]

    public async Task<ActionResult> Create(CreateModel model)

    {

        if(ModelState.IsValid)

        {

            var user = new AppUser{UserName = model.Name, Email = model.Email};

            IdentityResult result = await UserManager.CreateAsync(user, model.Password);

            if(result.Succeeded)

            {

                return RedirectToAction("Index");

            }else{

                AddErrorsFromResult(result);

            }

        }

        return View(model);

    }

    //编辑显示

    public async Task<ActionResult> Edit(string id)

    {

        AppUser user = await UserManager.FindByIdAsync(id);

         

        if(User != null)

        {

            CreateModel createModel = new CreateModel();

            createModel.Id = user.Id;

            createModel.Email = user.Email;

            createModel.Name = user.UserName;

            createModel.Password = user.PasswordHash;

            return View(createModel);

        }

        else

        {

            return RedirectToAction("Index");

        }

    }

    //接收编辑

    [HttpPost]

    public async Task<ActionResult> Edit(CreateModel createModel)

    {

         

        if(ModelState.IsValid)

        {

            AppUser user = await UserManager.FindByIdAsync(createModel.Id);

            if (user != null)

            {

                //关于邮箱

                user.Email = createModel.Email;

                IdentityResult validEmail = await UserManager.UserValidator.ValidateAsync(user);

                if (!validEmail.Succeeded)

                {

                    AddErrorsFromResult(validEmail);

                }

                user.UserName = createModel.Name;

                //关于密码

                IdentityResult validPass = null;

                if (createModel.Password != string.Empty)

                {

                    validPass = await UserManager.PasswordValidator.ValidateAsync(createModel.Password);

                    if (validPass.Succeeded)

                    {

                        user.PasswordHash = UserManager.PasswordHasher.HashPassword(createModel.Password);

                    }

                    else

                    {

                        AddErrorsFromResult(validPass);

                    }

                }

                user.Email = createModel.Email;

                //验证结果

                if ((validEmail.Succeeded && validPass == null) || (validEmail.Succeeded

&& createModel.Password != string.Empty && validPass.Succeeded))

                {

                    IdentityResult result = await UserManager.UpdateAsync(user);

                    if (result.Succeeded)

                    {

                        return RedirectToAction("Index");

                    }

                    else

                    {

                        AddErrorsFromResult(result);

                    }

                }

                else

                {

                    ModelState.AddModelError("", "无此用户");

                }

            }

            return View(createModel);

        }

        else

        {

            return View(createModel);

        }

         

    }

    //删除

    [HttpPost]

    public async Task<ActionResult> Delete(string id)

    {

        AppUser user = await UserManager.FindByIdAsync(id);

        if(user != null)

        {

            IdentityResult result = await UserManager.DeleteAsync(user);

            if(result.Succeeded)

            {

                return RedirectToAction("Index");

            }

            else

            {

                return View("Error", result.Errors);

            }

        }

        else

        {

            return View("Error", new string[] { "没有此用户" });

        }

    }

    private void AddErrorsFromResult(IdentityResult result)

    {

        foreach(var error in result.Errors)

        {

            ModelState.AddModelError("", error);

        }

    }

    private AppUserManager UserManager

    {

        get

        {

            return HttpContext.GetOwinContext().GetUserManager<AppUserManager>();

        }

    }

}

Admin/Edit.cshtml视图。

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

@model WebApplication4.Models.CreateModel

@{

    ViewBag.Title = "Edit";

    Layout = "~/Views/Shared/_Layout.cshtml";

}

<h2>Edit</h2>

@using (Html.BeginForm())

{

    @Html.AntiForgeryToken()

     

    <div class="form-horizontal">

        <hr />

        @Html.ValidationSummary(true)

        @Html.HiddenFor(model => model.Id)

        <div class="form-group">

            @Html.LabelFor(model => model.Name, new { @class = "control-label col-md-2" })

            <div class="col-md-10">

                @Html.EditorFor(model => model.Name)

                @Html.ValidationMessageFor(model => model.Name)

            </div>

        </div>

        <div class="form-group">

            @Html.LabelFor(model => model.Email, new { @class = "control-label col-md-2" })

            <div class="col-md-10">

                @Html.EditorFor(model => model.Email)

                @Html.ValidationMessageFor(model => model.Email)

            </div>

        </div>

        <div class="form-group">

            @Html.LabelFor(model => model.Password, new { @class = "control-label col-md-2" })

            <div class="col-md-10">

                @Html.EditorFor(model => model.Password)

                @Html.ValidationMessageFor(model => model.Password)

            </div>

        </div>

        <div class="form-group">

            <div class="col-md-offset-2 col-md-10">

                <input type="submit" value="保存" class="btn btn-default" />

            </div>

        </div>

    </div>

}

<div>

    @Html.ActionLink("返回", "Index")

</div>

另外,如果删除失败,跳转到Shared/Error.cshtml视图页。

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

@model IEnumerable<string>

@{ ViewBag.Title = "Error";}

<div class="alert alert-danger">

    @switch (Model.Count())

    {

        case 0:

            @: Something went wrong. Please try again

            break;

        case 1:

        @Model.First();

                          break;

        default:

        @: 发现如下错误:

        <ul>

            @foreach (string error in Model)

            {

                <li>@error</li>

            }

        </ul>

            break;

    }

</div>

@Html.ActionLink("确定", "Index", null, new { @class = "btn btn-default" })

至此,使用ASP.NET Identy实现对用户的增删改查完毕,ASP.NET Identity真的很好很强大!


版权声明 : 本文内容来源于互联网或用户自行发布贡献,该文观点仅代表原作者本人。本站仅提供信息存储空间服务和不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权, 违法违规的内容, 请发送邮件至2530232025#qq.cn(#换@)举报,一经查实,本站将立刻删除。
原文链接 : https://www.cnblogs.com/darrenji/p/4444431.html
相关文章
  • .NET新能源汽车锂电池检测程序UI挂死问题分析

    .NET新能源汽车锂电池检测程序UI挂死问题分析
    一:背景 1. 讲故事 这世间事说来也奇怪,近两个月有三位朋友找到我,让我帮忙分析下他的程序hangon现象,这三个dump分别涉及: 医疗,新
  • ASP.NET MVC使用Identity增删改查用户

    ASP.NET MVC使用Identity增删改查用户
    源码在这里:https://github.com/darrenji/UseIdentityCRUDUserInMVC,本地下载 在VS2013中创建一个MVC项目,用默认的无身份验证作为身份验证机制。 通过
  • WPF实现雷达扫描图的绘制介绍

    WPF实现雷达扫描图的绘制介绍
    实现一个雷达扫描图。 源代码在TK_King/雷达 (gitee.com) https://gitee.com/TK_King/radar,自行下载就好了 制作思路 绘制圆形(或者称之轮) 绘制分割
  • .Net Core之JWT授权介绍

    .Net Core之JWT授权介绍
    JSON Web令牌(JWT)是一个开放标准(RFC 7519),它定义了一种紧凑且自包含的方式,用于在各方之间安全地传输信息作为JSON对象。由于此信息
  • ASP.NET Core使用Middleware设置有条件允许访问路由

    ASP.NET Core使用Middleware设置有条件允许访问路由
    1.简介 有时,我们可能在Web API中包含一些具有调试功能的请求。比如我们上次的文章中为什么ASP.NETCore数据库连接串的值和appsettings.json配的
  • ASP.NET Core使用功能开关控制路由访问操作

    ASP.NET Core使用功能开关控制路由访问操作
    前言: 在前面的文章,我们介绍了使用Middleware有条件地允许访问路由(《ASP.NETCore使用Middleware设置有条件允许访问路由》)。 而对于一些
  • ASP.NET Core使用功能开关控制路由访问操作(续)

    ASP.NET Core使用功能开关控制路由访问操作(续)
    前言: 在前面的文章,我们介绍了? ?使用功能开关控制路由访问??。 但其实我们使用了2个条件做的判断: 1 2 3 4 var isDebugEndpoint = context.Re
  • 详解MediatR的使用
    环境: .NET 5 ASP.NET Core MVC (project) 1. MediatR MediatR .NET中的简单中介者模式实现,一种进程内消息传递机制(无其他外部依赖)。支持以同步或
  • .NET Core 3.0里新的JSON API介绍
    为什么需要新的 JSON API ? JSON.NET 大家都用过,老版本的 ASP.NET Core 也依赖于 JSON.NET 。 然而这个依赖就会引起一些版本问题:例如 ASP .NET
  • Net Core Web Api项目与在NginX下发布的方法
    前言 本文将介绍Net Core的一些基础知识和如何NginX下发布Net Core的WebApi项目。 测试环境 操作系统:windows 10 开发工具:visualstudio 2019 框架:
  • 本站所有内容来源于互联网或用户自行发布,本站仅提供信息存储空间服务,不拥有版权,不承担法律责任。如有侵犯您的权益,请您联系站长处理!
  • Copyright © 2017-2022 F11.CN All Rights Reserved. F11站长开发者网 版权所有 | 苏ICP备2022031554号-1 | 51LA统计