Following completion API to verify AD password Later,Then try to write the part to change the password,Even though I stumbled, I finally finished it.。This time I will share how to write three different packages.,And the title will mention “Change your AD password” It’s because I discovered during the writing process,Some methods require the permissions of a domain administrator to perform,Therefore, the scope of this article will be limited to only using the user’s own account and password.,You can complete the action of changing the password。
Recently I tried to write an AD account password modification program through ASP.NET Core.,In terms of architecture, there is generally a Web API for AD authentication and password modification.,Finally, write a desktop application,Let users modify it themselves。What is completed this time is the Web API for account and password verification.,The program is as follows:
Previously, colleagues reported that Google’s QR Code API sometimes failed to work.,After checking the relevant information,Got the idea to learn C# by writing this API,Spent some time exploring,I really got it out of you。The function of this API is to enter a value in the URL,You can generate QRCode images directly in the browser,The following will be written for the first time ASP.NET Core / Explained from the perspective of a newbie in C#。
<%# Eval("SDate", "{0:yyyy/MM/dd}") %> // 0: 表示定義整個括號裡面的第 0 個變數要採用此日期格式。 // 以下為兩個變數的範例。 string s = String.Format("At {0}, the temperature is {1}°C.", DateTime.Now, 20.4); Console.WriteLine(s); // Output similar to: 'At 4/10/2015 9:29:41 AM, the temperature is 20.4°C.'
【參考連結】
- asp.net – how to apply particular FORMAT of date by using eval? – Stack Overflow
- c# – What does the 0 in “{0:MM dd yyyy}” do? – Stack Overflow
- String.Format method (System) | Microsoft Docs
- Custom date and time format strings | Microsoft Docs
- Standard date and time format strings | Microsoft Docs
//MVC3開始,新增Razer語法,不同於先前的<%...%>括號語法,使用At Sgin(@)敘述程式碼片段。 //在Razer檢視中,使用@*...*@進行程式註解。 //在程式碼中,要輸出內容,要加@或@(...) //在html標籤中,要輸出內容,要加@ //在程式碼中,要輸出純文字,要加@:
@if(true) { String strPrint = "這是測試輸出文字"; @strPrint<br/> <span>strPring</span><br /> <span>@strPrint</span><br /> } @{string strl = "測試";} @(strl)輸出文字<br /> @{ string strHtml1 = "<ul><li>項目一</li></ul>";} @Html.Raw(strHtml1)<br />
//在測試Controller與View時,如果因為設中斷點導致網頁顯示不完整而無法進行測試, //可以試著點選"跳離函式(Shift+F11)",讓頁面完整顯示,以進行測試。 //先於Model設計好欄位變數等, //再於Controller設定執行時,透過剛設計的Model樣板,進行各個變數的處理(遞交資料) //如從網頁欄位A讀取資料到變數X,再把X送到網頁的欄位B //最後於View設計各欄位的顯示情形
//Controllers\HomeController.cs public ActionResult Index() { TempData["Message"] = "修改此範本即可開始著手進行您的ASP.NET MVC應用程式。"; return View(); }
<!--Views\Home\Index.cshtml--> <h2>@TempData["Message"]</h2>
//資料模型一對多關聯 public class Guestbook { public int Id { get; set; } public string Content { get; set; } public DateTime CreateTime { get; set; } public Member Member { get; set; } } public class Member { [Key] public string Username { get; set; } public string Password { get; set; } public string Name { get; set; } public string Email { get; set; } public ICollection<Guestbook> Guestbook { get; set; } } //Code First 就是在Model定義好各欄位後,其他的Controller、View都會自動幫你產生, //很神奇的功能,讓你專注在寫Model的部分就好
public class Index { [DisplayName("必選修")] //上面中括號這項非必要 public string Required { get; set; } /*name只能有一個,所以這兩段先註解掉 [Required(ErrorMessage = "學生姓名不得為空白")] public string Name { get; set; } [StringLength(10, ErrorMessage = "學生姓名不得超過10字元")] public string Name { get; set; } */ [StringLength(10, ErrorMessage = "學生姓名必須介於2-10字元", MinimumLength = 2)] public string Name { get; set; } [Range(0, 100, ErrorMessage = "得分必須介於0~100之間")] public int Point { get; set; } [System.Web.Mvc.Compare("re_password", ErrorMessage = "兩次密碼輸入不一致")] //上面沒有using System.Web.Mvc的話,這邊就要打完整的命名空間 public string Password { get; set; } public string Re_password { get; set; } [RegularExpression( @"^[0-9]{2,4}-?[0-9]{3,4}-?[0-9]{-4}$", ErrorMessage = "請輸入正確的電話號碼")] public string Phone { get; set; } [EmailAddress(ErrorMessage = "這不是E-mail格式")] public string Studentmail { get; set; } [Url(ErrorMessage = "這不是網址標準格式")] public string Url { get; set; } [FileExtensions(ErrorMessage = "所上傳的檔案不是圖片")] public string File { get; set; } [CreditCard(ErrorMessage = "這不是信用卡格式")] public string CreditCard { get; set; } [DataType(DataType.Date)] public string Date { get; set; } [Remote("RemoteTest", "Home", ErrorMessage = "Remote屬性測試")] public string For_Remote { get; set; } [MetadataType(typeof(ContentMetaData))] public partial class Content { private class ContentMetaData { [DisplayName("編號")] public int Id { get; set; } [DisplayName("姓名")] [Required(ErrorMessage = "請輸入性名")] [StringLength(10, ErrorMessage = "姓名不得超過10字元")] public string Name { get; set; } [DisplayName("內容")] [Required(ErrorMessage = "請輸入內容")] public string Content { get; set; } } } }
public class Index { [DisplayName("必選修")] public string required { get; set; } /*name只能有一個,所以這兩段先註解掉 [Required(ErrorMessage = "學生姓名不得為空白")] public string name { get; set; } [StringLength(10, ErrorMessage = "學生姓名不得超過10字元")] public string name { get; set; } */ [StringLength(10, ErrorMessage = "學生姓名必須介於2-10字元", MinimumLength = 2)] public string name { get; set; } [Range(0, 100, ErrorMessage = "得分必須介於0~100之間")] public int point { get; set; } [System.Web.Mvc.Compare("re_password", ErrorMessage = "兩次密碼輸入不一致")] //上面沒有using System.Web.Mvc,所以這邊就要打完整的命名空間 public string password { get; set; } public string re_password { get; set; } [RegularExpression( @"^[0-9]{2,4}-?[0-9]{3,4}-?[0-9]{-4}$", ErrorMessage = "請輸入正確的電話號碼")] public string phone { get; set; } [EmailAddress(ErrorMessage = "這不是E-mail格式")] public string studentmail { get; set; } [Url(ErrorMessage = "這不是網址標準格式")] public string url { get; set; } }