2020年6月4日 星期四

NET Core 2.1開始Identity UI被包進Razor Class Library

NET Core 2.1開始Identity UI被包進Razor Class Library
如果需要Identity Core的cshtml修改可以參考
指令產生
先安裝ASP.NET Core scaffolding engine
指令dotnet tool install -g dotnet-aspnet-codegenerator

指令dotnet aspnet-codegenerator identity 
需要先用NuGet安裝以下套件(用Visual Studio的Scaffolding Item會自動安裝)
Microsoft.VisualStudio.Web.CodeGeneration.Design 
Microsoft.AspNetCore.Identity.UI
Microsoft.EntityFrameworkCore.Design
Microsoft.EntityFrameworkCore.SqlServer

2020年6月3日 星期三

error CS0234: 命名空間 'Microsoft.AspNetCore.Identity' 中沒有類型或命名空間名稱 'UI' (是否遺漏了組件參考?)

因為Microsoft.AspNetCore.Identity.UI 3.1.4 只支援.NET Core 3.1以上
https://www.nuget.org/packages/Microsoft.AspNetCore.Identity.UI
所以要把專案升級到.NET Core 3.1以上


obj\Debug\netcoreapp3.0\SkillTreeRazorPageBlogSample.AssemblyInfo.cs(14,42): error CS0234: 命名空間 'Microsoft.AspNetCore.Identity' 中沒有類型或命名空間名稱 'UI' (是否遺漏了組件參考?) [D:\temptest\SkillTreeRazorPageBlogSample.csproj]
    0 個警告
    1 個錯誤

經過時間 00:00:03.72
RunTime 00:00:14.95

2020年6月1日 星期一

TagMode.StartTagAndEndTag

https://docs.microsoft.com/zh-tw/aspnet/core/mvc/views/tag-helpers/authoring?view=aspnetcore-3.1

You can use the following markup with a closing tag and remove the line with TagMode.StartTagAndEndTag in the tag helper:
<website-information info="webContext" >
</website-information>



https://whosnailaspnetcoredocs.readthedocs.io/ko/latest/mvc/views/tag-helpers/authoring.html
[HtmlTargetElement("email", TagStructure = TagStructure.WithoutEndTag)] 
public class EmailVoidTagHelper : TagHelper
{
    private const string EmailDomain = "contoso.com";
    // Code removed for brevity
 
 ref:
https://www.cnblogs.com/dotNETCoreSG/p/aspnetcore-4_3_6_2-tag-helpers-authoring.html

2020年5月23日 星期六

libphonenumber-csharp

https://github.com/twcclegg/libphonenumber-csharp

檢查電話號碼格式是否正確
還會顯示分類:FIXED_LINE、MOBILE、VOIP(070門號)、TOLL_FREE(080門號)

DEMO:
https://libphonenumber.appspot.com

Java原版:
https://github.com/google/libphonenumber

ref:
https://www.twilio.com/blog/validating-phone-numbers-effectively-with-c-and-the-net-frameworks

https://medium.com/frochu/libphonenumber-example-app-f60680faa599 

InvalidOperationException: Unable to resolve service for type 'Microsoft.AspNetCore.Mvc.Infrastructure.IActionContextAccessor' while attempting to activate

 寫.NET Core遇到Unable to resolve service for type通常是忘記註冊物件給DI容器

 Startup.cs的ConfigureServices(IServiceCollection services)加入以下這一行
            //TagsHelper使用
            services.AddSingleton<IActionContextAccessor, ActionContextAccessor>();


錯誤訊息:
InvalidOperationException: Unable to resolve service for type 'Microsoft.AspNetCore.Mvc.Infrastructure.IActionContextAccessor' while attempting to activate

IList和IEnumerable的比較

自己通常使用IEnumerable<T>
但還是會有需要用到IList<T>的時候

http://trufflepenne.blogspot.com/2013/04/ilistienumerable.html

https://stackoverflow.com/questions/376708/ilist-vs-ienumerable-for-collections-on-entities