1. 添加多个数据库链接
services.AddDbContextPool / services.AddDbContext有几个加几个
2. options.UseMySql 没有UseMySql
引用Pomelo.EntityFrameworkCore.MySql,这个扩展方法是别的库实现的,微软官方没有实现。
3. 导入log4net: 引用包 Microsoft.Extensions.Logging.Log4Net.AspNetCore
3.1 配置及使用log4net: https://www.cnblogs.com/jesen1315/p/11067231.html
public class Program { public static void Main(string[] args) { CreateHostBuilder(args).Build().Run(); } public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) .ConfigureLogging((context, loggingBuilder) => { loggingBuilder.ClearProviders(); //loggingBuilder.AddFilter("System", LogLevel.Warning); //loggingBuilder.AddFilter("Microsoft", LogLevel.Warning);//过滤掉系统自带的System,Microsoft开头的,级别在Warning以下的日志 loggingBuilder.AddLog4Net("log4net.config"); //会读取appsettings.json的Logging:LogLevel:Default级别 }) .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); }); }
4. Startup 类: https://www.cnblogs.com/vipyoumay/p/5640645.html
5. 根据数据库表生成POCO: VS插件: EF Core Power Tools
6. ASP.Net Core Identity: cnblogs.com/i3yuan/p/14327822.html https://www.cnblogs.com/i3yuan/p/14352964.html
7. 将User ID类型从GUID改成int 自增长: https://docs.microsoft.com/en-us/aspnet/identity/overview/extensibility/change-primary-key-for-users-in-aspnet-identity#userclass
8. Areas: https://docs.microsoft.com/en-us/aspnet/core/mvc/controllers/areas?view=aspnetcore-5.0
9. 自定义密码规则: https://www.scottbrady91.com/aspnet-identity/aspnet-identity-password-policies-with-password-managers
services.AddDefaultIdentity<IdentityUser>(options => { options.SignIn.RequireConfirmedAccount = true; options.Password.RequireUppercase = false; options.Password.RequireLowercase = false; options.Password.RequireDigit = false; options.Password.RequireNonAlphanumeric = false; }) .AddEntityFrameworkStores<MesDbContext>();
10. 使用用户名代替邮箱注册:https://qa.1r1g.com/sf/ask/3904057671/
第一步是将身份标识到您的应用程序:
然后,您可以自定义Register.cshtml
/ Register.cshtml.cs
和Login.cshtml
/ Login.cshtml.cs
,更新模型和视图,并更改OnPostAsync
功能中的逻辑以适合您的要求。
11. 输入文本的校验规则:https://www.cnblogs.com/pengboke/p/16117768.html
12. ASP.NET Layout: https://docs.microsoft.com/en-us/aspnet/core/mvc/views/layout?view=aspnetcore-5.0
13. AddController vs AddMvc vs AddControllersWithViews vs AddRazorPages https://dotnettutorials.net/lesson/difference-between-addmvc-and-addmvccore-method/
AddMvc | AddControllersWithViews | AddController | AddRazorPages | |
Support of controller | √ | √ | √ | √ |
model binding | √ | √ | √ | √ |
API Explorer | √ | √ | √ | NOT |
Authorization | √ | √ | √ | √ |
CROSS | √ | √ | √ | NOT |
validation | √ | √ | √ | √ |
Formatter Mapping | √ | √ | √ | NOT |
Antiforgery | √ | √ | NOT | √ |
TempData | √ | √ | NOT | √ |
Views | √ | √ | NOT | √ |
Pages | √ | NOT | NOT | √ |
TagHelpers | √ | √ | NOT | √ |
memory Cache | √ | √ | NOT | √ |
14. 左侧动态菜单: https://www.codeproject.com/Articles/1271364/Creating-a-Side-Menu-for-ASP-NET-Core-using-a-View
15. log4net:ERROR Appender named [ColoredConsoleAppender] not found. https://issues.apache.org/jira/browse/LOG4NET-658
added a reference to the Nuget package System.Text.Encoding.CodePages and registered the code pages before I configure log4net:
static void Main() { Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); var configurationPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "log4net.config"); XmlConfigurator.Configure(new FileInfo(configurationPath)); }
16. controller里更新了字段的值,view上的input控件没有更新 : https://sorceryforce.net/en/tips/asp-net-core-post-value-change
[HttpPost] public IActionResult Sample(SampleViewModel model) { if (ModelState.IsValid == false) View(model); // ModelState の値を消してモデルの値をビューに返却できるようにする ModelState.Clear(); // ビューに返す値を設定する model.ResultValue1 = model.InputValue + " テキストを追加1"; model.ResultValue2 = model.InputValue + " テキストを追加2"; return View(model); }
17. Card样式: https://getbootstrap.com/docs/4.2/components/card/
18. EF 注解: https://docs.microsoft.com/en-us/dotnet/api/system.componentmodel.dataannotations?view=net-6.0
exclude property in EF: https://docs.microsoft.com/en-us/ef/core/modeling/entity-properties?tabs=data-annotations%2Cwithout-nrt
问题:Unknown column 'f.Devicedid' in 'field list'
Model中没有指定ForeignKey EF就按规则生成了一个字段作为foreignKey
https://docs.microsoft.com/en-us/ef/core/modeling/relationships?tabs=fluent-api%2Cdata-annotations-simple-key%2Csimple-key#no-foreign-key-property
19. EF 直接执行sql: context.Database.ExecuteSqlRaw https://docs.microsoft.com/en-us/ef/core/performance/efficient-updating