這是備份網站。主網站位於http://www.dotblogs.com.tw/mis2000lab/ MIS2000 Lab's ASP.NET & Linux (Trad. Chinese 正體中文;Big5)。這個網站,是我們(MIS2000 Lab.資訊工作室)多年教學的實際心得與上課範例,有ASP.NET程式設計,也有Linux的相關文件。
編輯。 您也可以直接參觀主網站
MIS2000 Lab. is MVP 2008-2017/7/1 for ASP/ASP.NET.
(2) Visual Studio 上方的功能列 「工具」 =>「Nuget套件管理器」=>「套件管理器主控台」
輸入指令 Scaffold-DbContext 'Server=.\sqlexpress;Database=xxxx' Microsoft.EntityFrameworkCore.SqlServer
出現這樣的錯誤: A connection was successfully established with the server, but then an error occurred during the login process. (provider: Shared Memory Provider, error: 0 - 管道的另一端上無任何處理程序。) 與伺服器的連接已成功建立,但在登入程序時發生錯誤。 (provider: 共用記憶提供者, error: 0 - 管道的另一端上無任何處理程序。)
using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authentication.Cookies; using System.Security.Claims; // Claims會用到 using Microsoft.AspNetCore.Authorization;
(4-1) Login登入,輸入帳號、密碼。
public IActionResult Login()
{
return View();
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Login(db_user _User)
{
if (ModelState.IsValid)
{ // 入門版,先不連結DB,固定帳號密碼來做(微軟範例也是這樣) // 線上課程裡會有連結資料庫,比對帳號與密碼的教材。 初學者不要急,一步一步學習。
if (_User.UserName != "123" && _User.UserPassword != "123")
{
ViewData["ErrorMessage"] = "帳號與密碼有錯";
return View();
}
#region ***** 不使用ASP.NET Core Identity的 cookie 驗證 *****
var claims = new List// 搭配 System.Security.Claims; 命名空間 { new Claim(ClaimTypes.Name, _User.UserName), // new Claim(ClaimTypes.Role, "Administrator"), // 如果要有「群組、角色、權限」,可以加入這一段 }; // 底下的 ** 登入 Login ** 需要下面兩個參數 (1) claimsIdentity (2) authProperties
var claimsIdentity = new ClaimsIdentity(
claims, CookieAuthenticationDefaults.AuthenticationScheme);
var authProperties = new AuthenticationProperties
{ //AllowRefresh = , // Refreshing the authentication session should be allowed. //ExpiresUtc = DateTimeOffset.UtcNow.AddMinutes(10), // The time at which the authentication ticket expires. A // value set here overrides the ExpireTimeSpan option of // CookieAuthenticationOptions set with AddCookie. //IsPersistent = true, // Whether the authentication session is persisted across // multiple requests. When used with cookies, controls // whether the cookie's lifetime is absolute (matching the // lifetime of the authentication ticket) or session-based. //IssuedUtc = , // The time at which the authentication ticket was issued. //RedirectUri = // The full path or absolute URI to be used as an http redirect response value.
}; // *** 登入 Login *********
HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme,
new ClaimsPrincipal(claimsIdentity),
authProperties);
#endregion
return Content("