徐培堯
  • NEW!
    NEW!  Connect Ideas Across Notes
    Save time and share insights. With Paragraph Citation, you can quote others’ work with source info built in. If someone cites your note, you’ll see a card showing where it’s used—bringing notes closer together.
    Got it
      • Create new note
      • Create a note from template
        • Sharing URL Link copied
        • /edit
        • View mode
          • Edit mode
          • View mode
          • Book mode
          • Slide mode
          Edit mode View mode Book mode Slide mode
        • Customize slides
        • Note Permission
        • Read
          • Only me
          • Signed-in users
          • Everyone
          Only me Signed-in users Everyone
        • Write
          • Only me
          • Signed-in users
          • Everyone
          Only me Signed-in users Everyone
        • Engagement control Commenting, Suggest edit, Emoji Reply
      • Invite by email
        Invitee

        This note has no invitees

      • Publish Note

        Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

        Your note will be visible on your profile and discoverable by anyone.
        Your note is now live.
        This note is visible on your profile and discoverable online.
        Everyone on the web can find and read all notes of this public team.

        Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

        Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

        Explore these features while you wait
        Complete general settings
        Bookmark and like published notes
        Write a few more notes
        Complete general settings
        Write a few more notes
        See published notes
        Unpublish note
        Please check the box to agree to the Community Guidelines.
        View profile
      • Commenting
        Permission
        Disabled Forbidden Owners Signed-in users Everyone
      • Enable
      • Permission
        • Forbidden
        • Owners
        • Signed-in users
        • Everyone
      • Suggest edit
        Permission
        Disabled Forbidden Owners Signed-in users Everyone
      • Enable
      • Permission
        • Forbidden
        • Owners
        • Signed-in users
      • Emoji Reply
      • Enable
      • Versions and GitHub Sync
      • Note settings
      • Note Insights New
      • Engagement control
      • Make a copy
      • Transfer ownership
      • Delete this note
      • Save as template
      • Insert from template
      • Import from
        • Dropbox
        • Google Drive
        • Gist
        • Clipboard
      • Export to
        • Dropbox
        • Google Drive
        • Gist
      • Download
        • Markdown
        • HTML
        • Raw HTML
    Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
    Create Create new note Create a note from template
    Menu
    Options
    Engagement control Make a copy Transfer ownership Delete this note
    Import from
    Dropbox Google Drive Gist Clipboard
    Export to
    Dropbox Google Drive Gist
    Download
    Markdown HTML Raw HTML
    Back
    Sharing URL Link copied
    /edit
    View mode
    • Edit mode
    • View mode
    • Book mode
    • Slide mode
    Edit mode View mode Book mode Slide mode
    Customize slides
    Note Permission
    Read
    Only me
    • Only me
    • Signed-in users
    • Everyone
    Only me Signed-in users Everyone
    Write
    Only me
    • Only me
    • Signed-in users
    • Everyone
    Only me Signed-in users Everyone
    Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # 1. GIT的基礎使用 使用Source Tree操作。 ---- ## 1.1. SourceTree安裝 至[SourceTree](https://www.sourcetreeapp.com/)官網下載。 SourceTree安裝檔附帶Git安裝,所以不用額外下載。 ---- ### 1.1.1. 步驟一 安裝第一步驟可以直接點選**Skip**略過登入Bitbucket服務。 ![](https://i.imgur.com/3ImvK6P.png) ---- ### 1.1.2. 步驟二 在選擇安裝項目中必定將**Git**項目勾選。 ![](https://i.imgur.com/Hf0XCEp.png) ---- ### 1.1.3. 步驟三 安裝完成。 ![](https://i.imgur.com/gzO1VKo.png) ---- ### 1.1.4. 步驟四 設定Git使用者資訊。 ![](https://i.imgur.com/VoD6dMC.png) ---- ### 1.1.5. 步驟五 接下來選擇是否匯入SSH Key,這個範例中先選擇No略過。 ![](https://i.imgur.com/32qG6Wd.png) ---- ## 1.2. SourceTree與Git的使用 ---- ### 1.2.1. 建立Repository 點選工具列的**Create**,依照表單要求資訊輸入後點選**Create**按鈕。 ![](https://i.imgur.com/RVMq5nE.png) ---- ### 1.2.2. 設定.gitignore 專案有許多無須加入版控的檔案,如`dll`檔案或`node_module`目錄,可透過`.gitignore`在git略過這些檔案。 在GitHub中的[github/gitignore](https://github.com/github/gitignore),其中包含了大多數常用的.gitignore設定檔。 ![](https://i.imgur.com/pWFQ9vH.png) ---- ### 1.2.3. 手動將檔案加入.gitignore 在SourceTree中切換至`WORKSPACE/File Status`,在要略過的項目點右鍵選擇`Ignore`。 ![](https://i.imgur.com/qZOmk76.png) ---- 在`Ignore`設定視窗中選擇`Ignore exact filename(s)`,或依自己需求調整。 ![](https://i.imgur.com/b09B80L.png) ---- ### 1.2.4. 加入Origin 首先選擇`Settings`後選擇`Remotes`標籤,最後點選`Add`。 ![](https://i.imgur.com/PUDAx5C.png) ---- 取得Git Server的Repository URL。 ![](https://i.imgur.com/gwLur51.png) ---- 在`Required Information`選項中點選Default remote並設定URL。點選OK。 ![](https://i.imgur.com/Tl4nzI6.png) ---- 完成。 ![](https://i.imgur.com/Avlio17.png) ---- ### 1.2.5. 初始化Git Flow 由於剛建立的Repository沒有第一個commit起始點,所以執行以下指令建立起使commit。 ```bash git commit -m "init" --allow-empty ``` ---- 點選`Git-flow`按鈕,之後直接點選OK。 ![](https://i.imgur.com/zhc9ZsX.png) ---- 完成。 ![](https://i.imgur.com/Ar1hTnF.png) ### 1.2.6. 建立Commit 在File Status標籤中將Unstaged的項目移動至Staged中,並在Commit message輸入本次修改的意圖,選擇Commit。 ![](https://i.imgur.com/6GgfyO0.png) ---- ### 1.2.7. Pull & Push 點選Push按鈕,勾選要推至Git Server的分支。 ![](https://i.imgur.com/1K5ET32.png) ---- ## 1.3. Git Flow ![](https://i.imgur.com/C9aTf0S.png) --- # 2. HTTP Methods ## 2.1. GET 最常見的行為,如瀏覽器輸入網址後瀏覽的行為。 幂等,每次請求客戶端接收結果應該一樣。 ---- ## 2.2. POST 可以用於建立與上傳行為。 非幂等,每次請求狀態不一。 ---- ## 2.3. PUT 用於更新資料與上傳行為。 幂等,每次請求客戶端接收結果應該一樣。 ---- ## 2.4. DELETE 常用於刪除資源。 非幂等,每次請求狀態不一。 ---- ## 2.5. RESTful REST 介面有三要素: 1. 名詞(Noun): 操作資源,像是https://xxx/api/User/user1。 2. 動詞(Verb): 操作指令,包含GET、POST、PUT、DELETE。 3. 表徵(Content Type):內容格式,像HTML。 > 參考自: https://medium.com/@jinghua.shih/%E7%AD%86%E8%A8%98-rest-%E5%88%B0%E5%BA%95%E6%98%AF%E4%BB%80%E9%BA%BC-170ad2b45836 --- # 3. ASP.NET Core ![](https://i.imgur.com/Di6fb80.png) ---- ## 3.1. Dependencty Injection 在ASP.NET Core專案中的Startup Class中的`ConfigureServices`區塊為定義DI項目用途。 ```csharp public void ConfigureServices(IServiceCollection services) { services.AddTransient<ClassA>(); services.AddScoped<ClassB>(); services.AddSingleton<ClassC>(); services.AddMvc(); } ``` ---- 在ASP.NET Core中的DI容器提供以下三種注入項目的生命週期 1. Transient: 瞬態,每次向DI提供者取得都會重新產生。 2. Scoped: 範圍,在ASP.NET Core中表示為一個Request至Response週期。 3. Singletion: 單例,整個應用程式中都共用同一個物件實例。 ---- ![](https://i.imgur.com/9X4Pwp4.png) 參考自: https://blog.johnwu.cc/article/ironman-day04-asp-net-core-dependency-injection.html ---- ## 3.2. Pipeline & Middleware ![](https://i.imgur.com/1oscNTG.png) ---- 在Startup Class的Configure方法定義Http Request至Http Response的整個流程。先進後出。 ![](https://i.imgur.com/8KHmzCA.png) ---- 常見的幾個Pipeline定義有以下幾個: 1. Use: pipeline的過程 3. Run: pipeline的終點 4. Map: 使用路由作為pipeline分岔依據 5. MapWhen: 使用條件作為pipeline分岔依據 ---- ## 3.3. Static Files ```csharp public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { // 使用狀態碼導引,如發生404則導引到/404.html app.UseStatusCodePagesWithRedirects("/{0}.html"); // 若未指定檔案名稱則預設使用index.html app.UseDefaultFiles(); // 讀取wwwroot目錄內的檔案 app.UseStaticFiles(); } ``` ---- ## 3.4. Configuration 在Startup中若需要讀取appsettings.json的設定,則可以在Startup建構式中加入`IConfiguration`類型的參數,並將其儲存至屬性如下: ```csharp public class Startup { public IConfiguration Configuration{get;private set;} public Startup(IConfiguration config){ Configuration = config; } } ``` ---- ```json { "ConnectionStrings":{ "Default": "xxxxx" } } ``` 若再設定DI或Pipeline中使用Configuration的參數,如要讀取其中的ConnectionStrings則可以如下兩種方法獲取。 ```csharp Configuration.GetConnectionStrings("Default"); Configuration["ConnectionStrings:Default"]; ``` ---- ## 3.5. SPA Routing 若網站為SPA,路由為ASP.NET Core負責,再對SPA的路由需要將404回應index.html的內容,以便S獲取路由。 ```csharp public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { app.Use(async (context, next) => { await next(); if (context.Response.StatusCode == 404) // 當404時,將原有Request路徑複寫重試 { context.Request.Path = "/"; await next(); } }); //app.UseStatusCodePagesWithReExecute("/"); //也可以直接使用這個方式 app.UseDefaultFiles(); app.UseStaticFiles(); } ``` ---- ## 3.6. Cookies & Session 使用Cookies與Session可以用來簡單的儲存使用者狀態或登入狀態等。 在使用Cookies時並不需要額外加入DI項目,直接於Middleware或HttpContext中調用Request或Response的Cookies屬性即可進行讀取與寫入操作。 ---- ```csharp app.Run(async (context) => { if (context.Request.Cookies.TryGetValue("Test", out string testValue)) { context.Response.Cookies.Append("Test", testValue + "x", new CookieOptions() { HttpOnly = true, Expires = DateTimeOffset.Now.AddDays(1) }); } else { context.Response.Cookies.Append("Test", "x", new CookieOptions() { HttpOnly = true, Expires = DateTimeOffset.Now.AddDays(1) }); } }); ``` ---- 若是要使用Session,則需補充以下兩個DI項目: ```csharp services.AddDistributedMemoryCache(); // 加入InMemory的分散式快取 services.AddSession(); // 加入Session服務 ``` ---- 加入DI項目後再Pipeline的範例如下: ```csharp app.UseSession(); // 這個Middleware之後才可用Session服務 app.Use(async (context, next) => { context.Session.SetString("TEST", "AAAA"); // 寫入Session await next(); }); ``` --- ## 3.7. 站台發佈 首先在要發佈的WEB專案點選右鍵/發佈 ![](https://i.imgur.com/ldMulrC.png) 我們先選擇資料夾的形式發行 ---- 使用預設路徑 ![](https://i.imgur.com/FR7oAT4.png) ---- ![](https://i.imgur.com/VQHf1Zj.png) ---- ### 3.7.1 自封裝 在某些形況下希望可以讓EndUser可以在不附加在IIS運行WEB服務,而不需要另外安裝.NET Core環境,這時候可以將整個WEB封裝獨立運行。 ![](https://i.imgur.com/PFnX7nx.png) ---- 以上述步驟產生的程式檔案中的dll數量繁多,使用者要在其中找到exe檔案稍嫌麻煩。 而在.NET Core 3中提供選項可以將眾多DLL與EXE封裝在同一個EXE中。 ![](https://i.imgur.com/8KbIvvk.png) ---- ### 3.7.2 IIS 若要將ASP.NET Core佈署於IIS上,則該SERVER需要安裝IIS的擴充(ASP.NET Core Module)。之後可以將帶有web.config的編譯結果直接放上去。 ![](https://i.imgur.com/OPX40g6.png) ---- #### 3.7.2.1 在IIS上的異常排除 ---- #### 3.7.2.2 掛載子應用程式 ---- ## 3.8. EntityFrameworkCore --- # 4. ASP.NET Core MVC ---- ## 4.1. 建立Controller與基本的RESTful API ---- ## 4.2. MVC Action路由 ---- ## 4.3. 建立View與View的載入順序 ---- ## 4.4. View的Layout ---- ## 4.5. 基本的Razor語法 ---- ## 4.6. 常見的ActionResult類型 ---- ## 4.7. 搭配EntityFrameworkCore撰寫API ---- ## 4.8. 搭配EntityFrameworkCore撰寫View ---- ## 4.9. MVC使用Session做登入驗證 ---- ## 4.10. RESTful API使用JWT做登入驗證 ### 4.10.1. 什麼是JWT ### 4.10.2. 簽發JWT ### 4.10.3. 驗證JWT ### 4.10.4. 綁定Action驗證

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password
    or
    Sign in via Google Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully