UWInfo Blog
發表新文章
[Join] | [忘記密碼] | [Login]
搜尋

搜尋意見
文章分類-#Author#
[所有文章分類]
所有文章分類
  • ASP.NET (48)
  • ASP.NET2.0 (15)
  • ASP.NET4.0 (34)
  • JavaScript (49)
  • jQuery (26)
  • FireFox (4)
  • UW系統設定 (3)
  • SQL (39)
  • SQL 2008 (25)
  • mirror (4)
  • SVN (4)
  • IE (9)
  • IIS (20)
  • IIS6 (1)
  • 閒聊 (7)
  • W3C (6)
  • 作業系統 (9)
  • C# (24)
  • CSS (12)
  • FileServer (1)
  • HTML 5 (11)
  • CKEditor (3)
  • UW.dll (13)
  • Visual Studio (16)
  • Browser (8)
  • SEO (1)
  • Google Apps (3)
  • 網站輔助系統 (4)
  • DNS (5)
  • SMTP (4)
  • 網管 (11)
  • 社群API (3)
  • SSL (4)
  • App_Inventor (1)
  • URLRewrite (2)
  • 開發工具 (6)
  • JSON (1)
  • Excel2007 (1)
  • 試題 (3)
  • LINQ (1)
  • bootstrap (0)
  • Vue (3)
  • IIS7 (3)
  • foodpanda (2)
  • 編碼 (2)
  • 資安 (3)
  • Sourcetree (1)
  • MAUI (1)
  • CMD (1)
  • my sql (1)
最新回應
  • Newtonsoft.Json.JsonConvert.DeserializeObject 失敗的情況
    test...more
  • dotnet ef dbcontext scaffold
    ...more
  • [ASP.NET] 利用 aspnet_regiis 加密 web.config
    ...more
  • IIS ARR (reverse proxy) 服務安裝
    ...more
  • [錯誤訊息] 請加入 ScriptResourceMapping 命名的 jquery (區分大小寫)
    ...more
  • 用 Javascript 跨網頁讀取 cookie (Cookie cross page, path of cookie)
    ...more
  • 線上客服 - MSN
    本人信箱被盜用以致資料外洩,是否可以請貴平台予以協助刪除該信箱之使用謝謝囉...more
  • 插入文字到游標或選取處
    aaaaa...more
  • IIS 配合 AD (Active Directory) 認証, 使用 .Net 6.0
    太感謝你了~~~你救了我被windows 認證卡了好幾天QQ...more
  • PostgreSQL 的 monitor trigger
    FOR EACH ROW 可能要改為 FOR EACH STATEMENT ...more
標籤
  • FB
  • list
  • javascript
  • windows
  • nelson
  • Cookie
  • JQ
  • HTML
  • IP
  • Domain
  • ef
  • ?
  • gmail
  • tim
  • server
  • 12
  • win
  • a
  • unt
  • sysconfig,
  • JsonConver
  • AD
  • TCP
  • AjaxUpload
  • PG
  • 檔案
  • 60 order b
  • -9649 UNIO
  • C
  • 問題
  • join
  • IE
  • window
  • 56 ORDER B
  • firefox
  • SKYPE
  • ti
  • CK
  • 15.1mqtn
  • ContainsAN
  • 複製自己
  • sing212112
  • innerhtml
  • GN
  • WU
  • 版本
  • en
  • ios
  • 992
  • Mirror
頁數 1 / 2 下一頁
搜尋 ssL 結果:
加密協定開關用的軟體
開關 tls, ssl 等等協定用

https://www.nartac.com/Products/IISCrypto/
More...
Bike, 2024/4/9 下午 02:58:54
.net Core環境變數加密方式
簡易執行方式
1. 確定Program.cs有加上Su.Encryption.AesEncryptor.InitAesPaddingEncryptor(secret , iv , encKey , dataRoot)
2. 確定appsettings.json有設定變數,DataRoot、EnvironmentEncKey
3. 先執行一次,會報錯誤,在dataRoot位置會產生一組$"{encKey}.ps1,裡面會放設定環境變數的指令
4. 設定完,記得把 $"{encKey}.ps1檔案刪除
===以上,設定完環境變數===
1. 確定Program.cs有加上Dictionary<string, string> encSetting = Su.Encryption.GetDecryptedSetting
2. 確定appsettings.json有設定變數,DataRoot、EnvironmentEncKey , ShowEncSetting 設定為 false
3. 在 $"{dataRoot}\Config\XXXX_dec.json"設定DBC連線,要注意連線字串要加上  "TrustServerCertificate=true;",因為.net Core一定要藥用SSL連線
4. 設定完之後,在執行一次,會自動產生XXXX.json
5. 刪除XXXX_dec.json
===以上,產生完加密DBC連線
備註,要取回解密連線字串,appsettings.json有設定變數 , ShowEncSetting 設定為 true

概念解說
原本  >> config大多是明文,駭客可以藉由偷到config來知道變數設定,例如  dbc連線資訊、某個APP Key
之後  >> 將重要資訊分成兩段,
appsettings.json  >>  放可公開資訊的設定,例如 DataRoot、EnvironmentEncKey

在環境變數加上一個 由本機產生的隨機變數
讓本機的所有


原理說明
1. .Net Core 啟動時最先執行檔案 Program.cs,在一開頭先檢查本機是否有設定環境變數
緯中用的function Su.Encryption.AesEncryptor.InitAesPaddingEncryptor(secret , iv , encKey , dataRoot)
進階加密標準(英語:Advanced Encryption Standard,縮寫:AES)

沒有的話,會在 dataRoot 這邊產生一個 encKey.ps1的檔案,裡面放有環境變數設定的指令
(encSecretAndIv = Su.Encryption.AesEncryptor.Encrypt(envSecret, envIv, Su.TextFns.GetRandomString(48));
var command = $"[Environment]::SetEnvironmentVariable('{variableName}', '{encSecretAndIv}', 'Machine')";)
(隨機產生48碼亂數,(前32碼為本機專用Secret、後16碼為iv),進行aes加密)




 
More...
Doug, 2023/6/17 下午 12:04:28
快速設定 SSL 協定的工具
文章參考: https://windowsreport.com/windows-server-enable-tls/

工具下載: https://www.nartac.com/Products/IISCrypto/Download
More...
Bike, 2022/5/5 下午 10:32:11
用 certbot 申請 wildcard SSL 憑証
1. 在這裡下載 https://certbot.eff.org/lets-encrypt/windows-other.html

2. 安裝下載的程式

3. 用 cmd (管理員模式, 執行以下指令)
certbot certonly --manual --agree-tos -d "*.bike.idv.tw" -d "bike.idv.tw" --email bikehsu@gmail.com --preferred-challenges dns --manual-public-ip-logging-ok --server https://acme-v02.api.letsencrypt.org/directory

4. 會需要在 DNS Server 上建立一個 TXT 記錄.

5. 下載的格式是 pem, 可以在這裡轉成 IIS 用的 pfx 格式. https://decoder.link/converter, 轉檔時, "不"要用 fullchain

6. 用這個指令可以顯示所有 certbot 申請的憑証 "certbot certificates"

7. "certbot renew" 可以 renew  certificate, 需要測試.
More...
Bike, 2020/7/19 下午 05:11:45
在 CentOS 上面啟動多個 .Net Core 的網站
1. 參考這裡設定第一個網站:
https://blog.johnwu.cc/article/centos-asp-net-core-neginx.html
注意, 文章中有一個錯誤:
/etc/nginx/conf.d/my-website.conf 的第 27 行, 應該是 include /etc/nginx/conf.d/default_proxy_settings;

2.  因為要避開 5000 port, 所以修改第二個網站的 appsettings.json, 讓第二個網站開在 5002 port, 如下.
{
"Logging": {
    "LogLevel": {
     "Default": "Information",
     "Microsoft": "Warning",
     "Microsoft.Hosting.Lifetime": "Information"
    }
},
"Kestrel": {
        "EndPoints": {
                "Http": {
                        "Url": "http://localhost:5002"
                }
        }
},
"AllowedHosts": "*"
}


3. 新增 /etc/nginx/conf.d/my-website2.conf, 要注意
    A. portal2
    B. server localhost:5002
    C. server_name coretest2.bike.idv.tw
    當然 SSL 憑証的檔名也要記得改.

upstream portal2 {
    # localhost:5000 改成 ASP.NET Core 所監聽的 Port
    server localhost:5002;
}

server {
    # 只要是透過這些 Domain 連 HTTP 80 Port,都會轉送封包到 ASP.NET Core
    listen 80;
    # 可透過空白區分,綁定多個 Domain
    server_name coretest2.bike.idv.tw;
    location / {
        proxy_pass http://portal2/;
        include /etc/nginx/conf.d/default_proxy_settings;
    }
}

# 用 HTTPS 必須要有 SSL 憑證,如果沒有要綁定 SSL 可以把下面整段移除
server {
    # 只要是透過這些 Domain 連 HTTPS 443 Port,都會轉送封包到 ASP.NET Core
    listen 443 ssl;
    server_name coretest2.bike.idv.tw;
    ssl_certificate /etc/nginx/ssl/coretest2.bike.idv.tw.crt;
    ssl_certificate_key /etc/nginx/ssl/coretest2.bike.idv.tw.key;

    location / {
        proxy_pass http://portal2/;
        include /etc/nginx/conf.d/default_proxy_settings;
    }
}


改完後就可以用了.

以下是 https://blog.johnwu.cc/article/centos-asp-net-core-neginx.html 抄過來的一些檔案, 作為備份:

setup-aspnet-core.sh
#!/bin/bash

main() {
    sudo yum -y install epel-release
    sudo yum -y update

    install_nginx
    install_dotnet

    sudo firewall-cmd --add-service=http --permanent
    sudo firewall-cmd --add-service=https --permanent
    sudo firewall-cmd --reload
}

install_nginx() {
    echo "###################################"
    echo "########## Install Nginx ##########"
    echo "###################################"
    sudo yum -y install httpd-tools nginx
    sudo setsebool -P httpd_can_network_connect on
    sudo sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
    sudo setenforce 0
    sudo systemctl enable nginx
    sudo systemctl restart nginx
}

install_dotnet() {
    echo "###########################################"
    echo "########## Install .NET Core 2.2 ##########"
    echo "###########################################"
    sudo rpm -Uvh https://packages.microsoft.com/config/rhel/7/packages-microsoft-prod.rpm
    sudo yum -y install aspnetcore-runtime-2.2
}

main "$@"


用以下指令執行:
sudo sh setup-aspnet-core.sh



/etc/systemd/system/my-website.service, (/bin/dotnet 有可能是 /usr/bin/dotnet)
[Unit]
# Description=<此服務的摘要說明>
Description=MyWebsite

[Service]
# WorkingDirectory=<ASP.NET Core 專案目錄>
WorkingDirectory=/usr/share/my-website

# ExecStart=/bin/dotnet <ASP.NET Core 起始 dll>
ExecStart=/bin/dotnet MyWebsite.dll

# 啟動若失敗,就重啟到成功為止
Restart=always
# 重啟的間隔秒數
RestartSec=10

# 設定環境變數,注入給 ASP.NET Core 用
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false

[Install]
WantedBy=multi-user.target


服務相關指令:
# 開啟,開機自動啟動服務
systemctl enable my-website.service

# 關閉,開機自動啟動服務
systemctl disable my-website.service

# 啟動服務
systemctl start my-website.service

# 重啟服務
systemctl restart my-website.service

# 停止服務
systemctl stop my-website.service

# 查看服務狀態
systemctl status my-website.service


/etc/nginx/conf.d/default_proxy_settings
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $http_connection;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Host $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_cache_bypass $http_upgrade;


/etc/nginx/conf.d/my-website.conf
upstream portal {
    # localhost:5000 改成 ASP.NET Core 所監聽的 Port
    server localhost:5000;
}

server {
    # 只要是透過這些 Domain 連 HTTP 80 Port,都會轉送封包到 ASP.NET Core
    listen 80;
    # 可透過空白區分,綁定多個 Domain
    server_name demo.johnwu.cc example.johnwu.cc;
    location / {
        proxy_pass http://portal/;
        include /etc/nginx/conf.d/default_proxy_settings;
    }
}

# 用 HTTPS 必須要有 SSL 憑證,如果沒有要綁定 SSL 可以把下面整段移除
server {
    # 只要是透過這些 Domain 連 HTTPS 443 Port,都會轉送封包到 ASP.NET Core
    listen 443 ssl;
    server_name demo.johnwu.cc;
    ssl_certificate /etc/nginx/ssl/demo.johnwu.cc_bundle.crt;
    ssl_certificate_key /etc/nginx/ssl/demo.johnwu.cc.key;

    location / {
        proxy_pass http://portal/;
        include /etc/nginx/conf.d/default_proxy_settings;
    }
}


Nginx 重新啟動:
# 檢查 Nginx 的設定是否有誤
nginx -t

# 若沒有錯誤,即可套用
nginx -s reload
More...
Bike, 2020/7/7 上午 08:01:43
在 IIS 安裝 Let's Encrypt 的 SSL, 且可以設定自動更新
可以在這裡下載 

https://pkisharp.github.io/win-acme/

或是到

https://github.com/PKISharp/win-acme/releases 

下載 x64.pluggable.zip 的檔案

執行 wacs.exe,  然後看說明就可以囉.

wacs.exe --renew 會自動設定更新排程..

.100 可以在這裡找到檔案.
C:\Users\Administrator\win-acme

.195 可以在這裡找到
C:\Users\Administrator\win-acme.v2.1.6.773.x64.pluggable
More...
Bike, 2019/12/13 下午 06:32:01
IIS 7.0 ClientIP() 會抓到 IPv6 而非 IPv4
IIS 7.0 之後 
用 HttpContext.Current.Request.UserHostAddress 抓的IP會是 
類似 fe80::b148:cddc:81cd:fd10%2 
這樣的IPv6 位址
如果要抓 IPv4 要特別改寫

參考
https://dotblogs.com.tw/hunterpo/2011/03/21/21991


HttpContext.Current.Request.UserHostAddress


暫時的替代方法
public static string GetClientIPv4() { string ipv4 = String.Empty; foreach (IPAddress ip in Dns.GetHostAddresses(GetClientIP())) { if (ip.AddressFamily.ToString() == "InterNetwork") { ipv4 = ip.ToString(); break; } } if (ipv4 != String.Empty) { return ipv4; } // 原作使用 Dns.GetHostName 方法取回的是 Server 端資訊,非 Client 端。 // 改寫為利用 Dns.GetHostEntry 方法,由獲取的 IPv6 位址反查 DNS 紀錄, // 再逐一判斷何者屬 IPv4 協定,即可轉為 IPv4 位址。 foreach (IPAddress ip in Dns.GetHostEntry(GetClientIP()).AddressList) //foreach (IPAddress ip in Dns.GetHostAddresses(Dns.GetHostName())) { if (ip.AddressFamily.ToString() == "InterNetwork") { ipv4 = ip.ToString(); break; } } return ipv4; } /// <summary> /// 取得客戶端主機位址 /// </summary> public static string GetClientIP() { if (null == HttpContext.Current.Request.ServerVariables["HTTP_VIA"]) { return HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]; } else { return HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; } }
More...
sean, 2019/6/27 下午 06:47:31
使用IntersectionObserver API 實作 Lazy load
過去都是使用 jquery lazy load js 來實作延遲載圖,
其運作原理是偵測scroll事件以及img物件的相對位置來決定要不要load圖片

現在有更簡單的方式,就是用 IntersectionObserver API 這個 Web標準
來偵測 img 物件是不是進入可視 webview 範圍
https://developers.google.com/web/updates/2016/04/intersectionobserver

document.addEventListener("DOMContentLoaded", function() {
var lazyImages = [].slice.call(document.querySelectorAll("img.lazy"));;

if ("IntersectionObserver" in window && "IntersectionObserverEntry" in window && "intersectionRatio" in window.IntersectionObserverEntry.prototype) {
    let lazyImageObserver = new IntersectionObserver(function(entries, observer) {
     entries.forEach(function(entry) {
        if (entry.isIntersecting) {
         let lazyImage = entry.target;
         lazyImage.src = lazyImage.dataset.src;
         lazyImage.srcset = lazyImage.dataset.srcset;
         lazyImage.classList.remove("lazy");
         lazyImageObserver.unobserve(lazyImage);
        }
     });
    });

    lazyImages.forEach(function(lazyImage) {
     lazyImageObserver.observe(lazyImage);
    });
}
//這裡可以加上else處理萬一瀏覽器不支援的狀況
});


網頁裡面只要用  <img data-src='圖片網址' class='lazy' />  就可以啦

IntersectionObserver API
目前 Can I Use 網站顯示大部分 browser 都支援,iOS safari 要 12.2 版才支援
應該可以放心使用


 
More...
darren, 2019/4/3 下午 07:48:07
透過 facebook 內建瀏覽器開啟網頁圖片無法出現問題
使用Android手機透過facebook開啟網頁
發現圖片無法出現的問題 如下圖:



使用IOS手機開啟卻是正常的

可能是因為開啟的網站為SSL加密的關係
圖片連結若為http的話會被Facebook擋掉
將圖片連結改為https後就正常了
More...
choco, 2018/7/18 下午 01:25:26
.Net 4.0 要強迫使用 TLS 1.2 抓資料
突然發現 yahoo 不支援 SSL3.0 或 TLS 1.0 了, 要改用 TLS 1.2 才抓的到網頁資料

​
            ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
            ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;


.Net 4.0 在抓網頁之前先加這兩行, 就可以了. 

.Net 4.5 支援 Tls12, 可以用 

​
            ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
​

 
More...
Bike, 2017/7/31 下午 09:35:43
|< 12 >|
頁數 1 / 2 下一頁
~ Uwinfo ~