2022年4月29日 星期五

[研究][ASP.NET]MasterPage中ContentPlaceHolder內的 JavaScript「顯示密碼」功能

[研究][ASP.NET]MasterPage中ContentPlaceHolder內的 JavaScript「顯示密碼」功能

[研究][ASP.NET]JavaScript 抓取 ContentPlaceHolder 中 ASP.NET 控制項的 ID

2022-04-27

環境:Visual Studio 2022 + ASP.NET + WebForm + Web Application + C#

ASP.NET控制項(Control)的 ID,如果是在 MasterPage 架構的 ContentPlaceHolder1 中,在瀏覽器中看到的 ID 變更。

********************************************************************************

Site1.master

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site1.master.cs" Inherits="WebApplication1.Site1" %>

<!DOCTYPE html>

<html>
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
            </asp:ContentPlaceHolder>
        </div>
    </form>
</body>
</html>

Default.aspx
<%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master"
    AutoEventWireup="true" CodeBehind="Default.aspx.cs"
    Inherits="WebApplication1.Default" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script>
        function ShowPW() {
            var x = document.getElementById("ContentPlaceHolder1_TextBox1");
            if (x.type === "password") {
                x.type = "text";
            } else {
                x.type = "password";
            }
        }
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <asp:TextBox ID="TextBox1" required="required" TextMode="Password" 
        AutoComplete="Off" runat="server"></asp:TextBox>
    <br />
    <asp:CheckBox ID="CheckBox1" Text="顯示密碼" OnClick="ShowPW()" runat="server" />
    <br />
</asp:Content>


瀏覽器看到的 HTML Source

原來在 .aspx 中的 ID 是 TextBox1,現在變成了 ContentPlaceHolder1_TextBox1,所以 JavaScript 要抓取時,不能用 TextBox1,要用 ContentPlaceHolder1_TextBox1。

另外很多情況下 HTML 元素 (element) 的 ID 和 name 是相同的,但此時不同,不要錯用了 name 的 ctl00$ContentPlaceHolder1$TextBox1

<!DOCTYPE html>

<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>

</title>
    <script>
        function ShowPW() {
            var x = document.getElementById("ContentPlaceHolder1_TextBox1");
            if (x.type === "password") {
                x.type = "text";
            } else {
                x.type = "password";
            }
        }
    </script>
</head>
<body>
    <form method="post" action="./Default.aspx" id="form1">
<div class="aspNetHidden">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="zAE3P/7wt0M3uv/5llCSAr3yf1PYvO8mEmfl6tswaGanRIG/x4nfITMOV5YGUgeLMHwaNhnfWljHJTTBC2TZ45KhDzFigI1gv5UL8n6PYkKT/xzB4XP6NCz1FMeNwvEQ4ROBEG2cz4Ldmpz+AjDxzMXzThdSyXoXdkdLqMgJyBYupUKulNKCHi1ahgWWBU3s" />
</div>

<div class="aspNetHidden">

	<input type="hidden" name="__VIEWSTATEGENERATOR" id="__VIEWSTATEGENERATOR" value="CA0B0334" />
	<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="ESsA+ggMfjTJUH5bZ2Ix51c3ZJSrS30FLzobHXB//9f+pkaGPz/XpxMB0qtWzrGdAYXQO15QnOIwvAsrW3xORSbmc5iKMedbRkWkZzOg2aDJlloKooaor6L1rL71cB/6eP3190y1XdCMp7erjYcfGQ==" />
</div>
        <div>
            
    <input name="ctl00$ContentPlaceHolder1$TextBox1" type="password" id="ContentPlaceHolder1_TextBox1" required="required" AutoComplete="Off" />
    <br />
    <input id="ContentPlaceHolder1_CheckBox1" type="checkbox" name="ctl00$ContentPlaceHolder1$CheckBox1" onclick="ShowPW();" /><label for="ContentPlaceHolder1_CheckBox1">顯示密碼</label>
    <br />

        </div>
    </form>
</body>
</html>



(完)

相關

[研究][ASP.NET]MasterPage中ContentPlaceHolder內的 JavaScript「顯示密碼」功能
[研究][ASP.NET]JavaScript 抓取 ContentPlaceHolder 中 ASP.NET 控制項的 ID
https://shaurong.blogspot.com/2022/04/aspnetmasterpagecontentplaceholder.html

[研究][ASP.NET]登入畫面表單美工設計(一)
https://shaurong.blogspot.com/2022/04/aspnet.html

[研究][JavaScript]切換顯示和隱藏密碼
https://shaurong.blogspot.com/2019/02/javascript.html

[研究][JavaScript][C#][ASP.NET] Select2 v4.0.3 - jQuery Plugin 安裝 - 讓 DropDownList 可以輸入關鍵字,即時過濾顯示下拉選項
https://shaurong.blogspot.com/2017/01/caspnet-select2-v403-jquery-plugin.html


2022年4月25日 星期一

[研究][ASP.NET]執行緒已經中止。(ThreadAbortException)

[研究][ASP.NET]執行緒已經中止。(ThreadAbortException)

2022-04-25

環境:Visual Studio 2022 + ASP.NET + WebForm + Web Application + C#

在執行終止執行緒、Response.End、Response.Redirect等動作時,不能放在Try Catch中,因為 Thread 只要被停止(Abort)就會拋出例外 ThreadAbortException,應搬出 try catch 區塊,或終止執行緒的動作放到Finally執行。

在沒有使用 Thread 狀況,Response.Redirect 是可以放 Try Catch 中的。

(完)


[研究][ASP.NET]Session TimeOut是固定時間 or 閒置時間測試

[研究][ASP.NET]Session TimeOut是固定時間 or 閒置時間測試

2022-04-25

環境:Visual Studio 2022 + ASP.NET + WebForm + Web Application + C#

參考這篇

[研究][ASP.NET]使用 SQL Server 儲存 Session State 會談狀態(一)aspnet_regsql.exe
http://shaurong.blogspot.com/2022/04/aspnet-sql-server-session-state.html

資料庫會新增了2個資料表
dbo.ASPStateTempApplications
dbo.ASPStateTempSessions 

其中 dbo.ASPStateTempSessions 的 [Expires] 欄位可看過期時間。

登入後,先檢視一次時間;

放若干秒或分鐘後,隨便動一下滑鼠,再重新 SELECT 該值 ( 要找相同 SessionId 的,在自己開發電腦上測試,只有一個使用者登入,最好認),發現時間變更了,所以是 Session Time Out 是 閒置時間。

注意,[Created], [Expires], [LockDate], [LockDateLocal] 都是 UTC 時間,要加上 8 小時才是台灣時間。

(完)


2022年4月24日 星期日

[研究][C#]登出目前使用者

[研究][C#]Log Off the Current User

2022-04-24

環境:Visual Studio 2022 + WinForm + C# + Wndows Server 2019 排程

LogOffCurrentUser.cs  

using System.Runtime.InteropServices;

namespace LogOffCurrentUser
{
    internal class Program
    {
        [DllImport("user32.dll")]
        public static extern int ExitWindowsEx(int operationFlag, int operationReason);
        static void Main(string[] args)
        {
            ExitWindowsEx(0, 0);
        }
    }
}

但是實際測試,排程有啟動它,工作管理員有出現該程式,但使用者沒有被登出。

可改用下面方法。

[研究]排程 shutdown.exe 登出某使用者 (Windows Server 2019)
https://shaurong.blogspot.com/2022/04/shutdownexe-windows-server-2019.html

(完)

相關

How to Log Off the Current User - Win32 apps | Microsoft Docs
https://docs.microsoft.com/en-us/windows/win32/shutdown/how-to-log-off-the-current-user

.net - Log off a Windows user locally using c# - Stack Overflow
https://stackoverflow.com/questions/14466373/log-off-a-windows-user-locally-using-c-sharp

[研究]排程 shutdown.exe 登出某使用者 (Windows Server 2019)

[研究]排程 shutdown.exe 登出某使用者 (Windows Server 2019)

2022-04-24

被登出的使用者實際測試有一般權限即可。

設定到「工作排程器」前,可在「命令提示字元」模式先執行看看,執行 shutdown 不用切換目錄,也不用加上目錄,但是參數 /t 似乎用了反而沒執行,加上 秒數與否都沒用。










(下圖) 登出後,若使用者有帳號、密碼,仍可再次登入

此時可以每5分鐘登出該使用者,持續個一小時或其他時間





避免使用者立可登入,另外一種作法 

[研究] .BAT 限制使用者登入時間
https://shaurong.blogspot.com/2019/02/bat.html

本想結合兩種寫於 .BAT 中,登出立可變更登入時間,但後者需要系統管理員權限,但被登出的使用者無此權限可變更登入時間,所以放棄了。

(完)

[研究][ASP.NET]登入畫面表單美工設計(六)

[研究][ASP.NET]登入畫面表單美工設計(六)

2022-04-24

環境:Visual Studio 2022 + ASP.NET + WebForm + Web Application + C#

只是設計一個還可以看的畫面,筆記一下。

Login.html

<style>
	.css-form {
	color: #202124;
    font-size: 15px;
    line-height: 1.4286;
    padding: 20px 40px 36px;
    height: 340px;
	width: 370px;
	border-color:blue;
	border:1px solid blue;
	border-radius: 10px;
	margin:60px auto auto auto;	
	}
	.css-input {
     white-space: normal;
    border: 1px;
    display: block;
    line-height: 24px;
    min-width: 0%;
    outline: 1px;
    box-sizing: inherit;
    border-radius: 4px;
    color: #202124;
    font-size: 17px;
    height: 28px;
    margin: 1px 1px 0 1px;
    padding: 13px 15px 13px 15px;
    text-align: left;
	border: 1px solid;
    border-color:blue;
	width:330px;
	}
	.css-btn {
    font-size: 14px;
	border-color: #ffffff;
    background-color: #5555ff;
	color: #ffffff;
	width:117px;
	height:40px;
	border-radius:10px;	
	shadow:none;
	}
</style>
<div class="css-form">
	<h1><center>管理平台</center></h1>
	<div style="font-size: 17px; ">帳號</div>    
	<input id="userid" name="userid" type="email" class="css-input" placeholder="請輸入Email">
	<br \>
	<div style="font-size: 17px; ">密碼</div>    
	<input id="pw name="userid" type="password" class="css-input" placeholder="請輸入密碼">
	<br \><br \>
	<button type="submit" class="css-btn">登入</button>
	<button type="button" class="css-btn">忘記密碼</button>
	<button type="button" class="css-btn">註冊</button>
</div>

(下圖)結果


(完)

相關

[研究][ASP.NET]登入畫面表單美工設計(六)

[研究][ASP.NET]登入畫面表單美工設計(五)

[研究][ASP.NET]登入畫面表單美工設計(四)

[研究][ASP.NET]登入畫面表單美工設計(三)
https://shaurong.blogspot.com/2022/04/aspnet_14.html

[研究][ASP.NET]登入畫面表單美工設計(二)
https://shaurong.blogspot.com/2022/04/aspnet_12.html

[研究][ASP.NET]登入畫面表單美工設計(一)
https://shaurong.blogspot.com/2022/04/aspnet.html


[研究][ASP.NET]登入畫面表單美工設計(五)

[研究][ASP.NET]登入畫面表單美工設計(五)

2022-04-24

環境:Visual Studio 2022 + ASP.NET + WebForm + Web Application + C#

只是設計一個還可以看的畫面,筆記一下。

Login.html

<html>
<head>
<meta http-equiv=Content-Type content="text/html; charset="UTF-8">
<style>
.css-form {
    border: 2px solid rgb(211, 215, 236);
    border-radius: 42px;
    box-shadow: rgb(45 64 150 / 6%) 0px 6px 0px;
    padding: 24px;
    position: relative;
	width:500px;
	height:350px;
	margin-left:auto;
	margin-right:auto;
}
.css-input {
    box-sizing: border-box;
    outline: none;
    width: 95%;
    padding: 18px 18px;
    font-size: 18px;
    line-height: 1.3;
    letter-spacing: -0.25px;
    font-weight: 600;
    color: rgb(44, 42, 80);
    border-radius: 42px;
    border: 2px solid rgb(211, 215, 236);
	margin:10px;
}
.css-btn {
    box-sizing: border-box;
    outline: none;
    width: 28%;
    padding: 18px 24px;
    font-size: 18px;
    line-height: 1.3;
    letter-spacing: -0.25px;
    font-weight: 600;
    color: rgb(44, 42, 80);
    border-radius: 42px;
    border: 2px solid rgb(211, 215, 236);
	margin:10px;
}
</style>
</head>
<body>
<div class="css-form">
<center><h1>管理平台</h1></center>
<input type="text" placeholder="電子郵箱" class="css-input">
<input type="password" placeholder="密碼" class="css-input">
<center>
<input type="button" class="css-btn" value="登入">
<input type="button" class="css-btn" value="忘記密碼">
<input type="button" class="css-btn" value="註冊">
</center>
</div>
</body>
</html>



(下圖)結果



(完)

相關

[研究][ASP.NET]登入畫面表單美工設計(六)

[研究][ASP.NET]登入畫面表單美工設計(五)

[研究][ASP.NET]登入畫面表單美工設計(四)

[研究][ASP.NET]登入畫面表單美工設計(三)
https://shaurong.blogspot.com/2022/04/aspnet_14.html

[研究][ASP.NET]登入畫面表單美工設計(二)
https://shaurong.blogspot.com/2022/04/aspnet_12.html

[研究][ASP.NET]登入畫面表單美工設計(一)
https://shaurong.blogspot.com/2022/04/aspnet.html


[研究][ASP.NET]登入畫面表單美工設計(四)

 [研究][ASP.NET]登入畫面表單美工設計(四)

2022-04-24

環境:Visual Studio 2022 + ASP.NET + WebForm + Web Application + C#

只是設計一個還可以看的畫面,筆記一下。

Login.aspx

<%@ Page Language="C#" AutoEventWireup="true" 
    CodeBehind="Login.aspx.cs" Inherits="WebApplication1.Login" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
    <style>
        input {
            /*background:#F8F8F8;*/
            padding: 10px;
            margin:5px;
            border-radius:5px;
        }
        input[type="submit"]{
            background:#74AC00;
            border-color:#74AC00;
            margin:5px;
            padding: 5px 40px 5px 40px;
            border-radius:10px;
            color:white;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
        <center>
            <h1>登入</h1>
            <fieldset style="border-radius: 10px; width:1px; background-color: #eeeeee;">
                <legend>帳戶資訊</legend>
            <asp:TextBox ID="TextBox1" runat="server" PlaceHolder="帳號"></asp:TextBox><br />
            <asp:TextBox ID="TextBox2" runat="server" PlaceHolder="密碼"></asp:TextBox><br />
            <asp:Button ID="Button1" runat="server" Text="登  入" /><br />
            <asp:HyperLink ID="HyperLink1" style="text-decoration: underline;" 
                runat="server">忘記密碼</asp:HyperLink>
                </fieldset>
        </center>
    </form>
</body>
</html>



(下圖)結果


(完)

相關

[研究][ASP.NET]登入畫面表單美工設計(六)

[研究][ASP.NET]登入畫面表單美工設計(五)

[研究][ASP.NET]登入畫面表單美工設計(四)

[研究][ASP.NET]登入畫面表單美工設計(三)
https://shaurong.blogspot.com/2022/04/aspnet_14.html

[研究][ASP.NET]登入畫面表單美工設計(二)
https://shaurong.blogspot.com/2022/04/aspnet_12.html

[研究][ASP.NET]登入畫面表單美工設計(一)
https://shaurong.blogspot.com/2022/04/aspnet.html


[研究][HTML5][CSS3]placeholder-shown偽類實現輸入框浮動文字效果

[研究][HTML5][CSS3]浮動標籤 (Floating labels)

[研究][HTML5][CSS3]placeholder-shown偽類實現輸入框浮動文字效果

2022-04-24

HTML5 + CSS3

<head>
<style>
.LoginForm {
            padding: 10px;
            width: 500px;
            border: 4px solid #1199CD;
            margin-right: auto;
            margin-left: auto;
            background-color: #FFF;
            margin-bottom: 30px;
            border-radius: 12px;
            overflow: auto;
        }

.input-group {
  position: relative;
  margin: 20px;
  font-size: 16px;
}

.input-group>input {
  display: block;
  box-sizing: border-box;
  width: 100%;
  padding: 1em;
  font-size: 16px;
  line-height: 1.0;
  border: none; 
  border-bottom: 1px solid #cdcdcd;
  border-radius: 0.4em;
  transition: box-shadow 0.3s;
}

.input-group input::placeholder {
  font-style: italic;
  color: #cdcdcd;
}

.input-group>input:focus {
  outline: none;
  box-shadow: 0.2em 0.8em 1.6em #cdcdcd;
}

.input-group>label {
  position: absolute;
  bottom: 0;
  left: 1em;
  z-index: -1;

  visibility: hidden;
  color: #555555;
  opacity: 0;

  -webkit-transform-origin: 0 0;
  transform-origin: 0 0;
  -webkit-transform: translate3d(0, 0, 0) scale(0);
  transform: translate3d(0, 0, 0) scale(0);
  -webkit-transition:
    opacity 0.3s,
    visibility 0.3s,
    transform 0.3s,
    z-index 0.3s;

  transition:
    opacity 0.3s,
    visibility 0.3s,
    transform 0.3s,
    z-index 0.3s;
}

.input-group>input:focus ~ label {
  z-index: 1;
  visibility: visible;
  opacity: 1;
  -webkit-transform: translate3d(0, -2.4em, 0) scale(1);
  transform: translate3d(0, -2.4em, 0) scale(1);
}
</style>
</head>
<form id="form1" runat="server" class="LoginForm">
<h1 style="text-align:center">管理平台</h1><hr>
<div class="input-group">
  <input type="text" id="username" placeholder="請輸入賬號">
  <label for="username">賬號</label>
</div>
<!-- 密碼 -->
<div class="input-group">
  <input type="text" id="password" placeholder="請輸入6~8位密碼">
  <label for="password">密碼</label>
</div>

<div class="input-group">
  <input type="text" id="password" placeholder="驗證碼">
  <label style="z-index: 1;
  visibility: visible;
  opacity: 1;
  -webkit-transform: translate3d(0, -2.4em, 0) scale(1);
  transform: translate3d(0, -2.4em, 0) scale(1);" for="password">驗證碼</label>
</div>
<div class="input-group">
  <input type="submit" value="登入">
</div>
</form>

(完)



2022年4月21日 星期四

[研究][ASP.NET]讓超連結或 LinkButton 看起來像是按鈕

[研究][ASP.NET]讓超連結或 LinkButton 看起來像是按鈕

2022-04-21

環境:Visual Studio 2022 + ASP.NET + WebForm + Web Application + C#


Default.aspx

<%@ Page Language="C#" AutoEventWireup="true" 
    CodeBehind="Default.aspx.cs" Inherits="WebApplication1.Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <input id="Button1" type="button" value="button" /><br />
        <button>按鈕</button><br />
        <asp:Button ID="Button2" runat="server" Text="Button" /><br />
        <br />
        <asp:HyperLink ID="HyperLink1" NavigateUrl="xx"
            Style="border: 1px solid #000000; background-color: #efefef; 
            padding: 5px; margin: 5px; text-decoration: none; 
            border-radius: 5px;"
            runat="server">HyperLink</asp:HyperLink><br />
        <br />
        <asp:LinkButton ID="LinkButton1"
            Style="border: 1px solid #000000; background-color: #efefef; 
            padding: 5px; margin: 5px; text-decoration: none; 
            border-radius: 5px;"
            runat="server">LinkButton</asp:LinkButton>
    </form>
</body>
</html>



(完)

相關

[研究][ASP.NET]JavaScript alert對話盒視窗彈出位置測試

[研究][ASP.NET]JavaScript alert對話盒視窗彈出位置測試 

2022-04-21

環境:Visual Studio 2022 + ASP.NET + WebForm + Web Application + C#

因為之前這篇,使用不同的彈出方式,影響了版面美工,所以測試一下

[研究][ASP.NET]登入畫面表單美工設計(三)
http://shaurong.blogspot.com/2022/04/aspnet_14.html

Default.aspx

<%@ Page Language="C#" AutoEventWireup="true" 
    CodeBehind="Default.aspx.cs" Inherits="WebApplication1.Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /><br />
            <asp:Button ID="Button2" runat="server" Text="Button" OnClick="Button2_Click" /><br />
            <asp:Button ID="Button3" runat="server" Text="Button" OnClick="Button3_Click" /><br />
            <asp:Button ID="Button4" runat="server" Text="Button" OnClick="Button4_Click" /><br />
        </div>
    </form>
</body>
</html>

 

Default.aspx.cs


using System;
using System.Web.UI;

namespace WebApplication1
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            // 網頁不會空白
            Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", 
                "<script language='javascript' defer>alert('測試1。');</script>");
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            // 網頁會空白
            Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), 
                "message", "<script language='javascript' defer>alert('測試2。');</script>");
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            //轉向
            Page.ClientScript.RegisterStartupScript(Page.GetType(), 
                "message", "<script language='javascript' defer>alert('測試3。');
                window.location='Default2.aspx'</script>");
        }

        protected void Button4_Click(object sender, EventArgs e)
        {
            Response.Write("<script>alert('測試4。');</script>");
        }
    }
}

執行結果

HTML Source

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>
</title></head>
<body>
<form method="post" action="./Default.aspx" id="form1">
<div class="aspNetHidden">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="o9slSZhygiMVNvGkKm7W+AC6+Upc
xpuluNY9PxJ6uGlVm+ehQeKP8QRpNI+K6U9nur+OOzh5XxhxiBfLLisaobAvcFJWfEtFFX6uGA2SoVY=
" />
</div>
<div class="aspNetHidden">
<input type="hidden" name="__VIEWSTATEGENERATOR" id="__VIEWSTATEGENERATOR" value="CA0B0334" />
<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION"
  value="2YiTg3ryJ9ZjOyW5pJk8lCLyCR9oq8jPQ5Rqx/wsr4TFuFAufY8ae6bZsfYnTc+DVh9/GBUBE/Pif9gK6SZGJ
KL56dq1O49gFugO2t0nbRFqhFeS+yHfppLGsEiHOAaEcwdpDhhrSYZd7Ja6MbXcakAxKZz5brdMjeb64B/YwrbDdjh3
fYVjoearqWw6oEdb
" />
</div>
<div>
<input type="submit" name="Button1" value="Button" id="Button1" /><br />
<input type="submit" name="Button2" value="Button" id="Button2" /><br />
<input type="submit" name="Button3" value="Button" id="Button3" /><br />
<input type="submit" name="Button4" value="Button" id="Button4" /><br />
</div>
</form>
</body>
</html>


********************************************************************************

按鈕1執行結果

按下「確定」按鈕後,檢視HTML Source 

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>
</title></head>
<body>
<form method="post" action="./Default.aspx" id="form1">
<div class="aspNetHidden">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="V/URd1sI61D1R20GkaO2JMbyRBpYC
a3oyrpLmbHXV0l5TRB8YRPcCeoMW9bAdv7x+FqZENO7yC5HD26km+ESvjmaHyMj06upTT1WpHmtNjA=
" />
</div>
<div class="aspNetHidden">
<input type="hidden" name="__VIEWSTATEGENERATOR" id="__VIEWSTATEGENERATOR" value="CA0B0334" />
<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION"
  value="58gvSY0JmeL5tCExZ8oAcWDBnQYcIqhTp1CUDx/NUAlVjoVQ8Xe2MMd4QD4vW76eq/cAiqVHc5gRKM26D++uX
LsHKWi4Gs+JVX9las/jt0ULZ7K0i06eWGDdTWxkJBbmglMeSD0kAI8Blqh2Txu2DSDOw8QJuBukWhlKcRxxVc4f4Uqk
nNiMp/la8HtNw6UG
" />
</div>
<div>
<input type="submit" name="Button1" value="Button" id="Button1" /><br />
<input type="submit" name="Button2" value="Button" id="Button2" /><br />
<input type="submit" name="Button3" value="Button" id="Button3" /><br />
<input type="submit" name="Button4" value="Button" id="Button4" /><br />
</div>
<script language='javascript' defer>alert('測試1。');</script></form>
</body>
</html>


********************************************************************************

按鈕2執行結果


按下「確定」按鈕後,檢視HTML Source 

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>
</title></head>
<body>
<form method="post" action="./Default.aspx" id="form1">
<div class="aspNetHidden">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="4ME0Bu06b3I2m1E97XWIY58QhwN
Bd5+baNZV0a/t3DUD38liJGN9uBYsU4NjdjbZ+/6Nv4HPzjhmZj6sZnJuN0Ln+bNLi7pm3aIbO7RI8eY=
" />
</div>
<script language='javascript' defer>alert('測試2。');</script>
<div class="aspNetHidden">
<input type="hidden" name="__VIEWSTATEGENERATOR" id="__VIEWSTATEGENERATOR" value="CA0B0334" />
<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="hEZjvkte3Odzv9KOrHUh4TkVpfaXe9jONEzp57b6rAyoiFUzPlA8/GEpdwyV3zw62MwWmoT9FKlWuqc0tY
DSH0p4u4pjtb09piW8dgEGbOtYieCJt0WSjcSJzOM+DOm/kxiOohR1BcNeUI4TyNhp9lYC8Lz68GvKe44ioBp2SFr
K/r/+PqEpfVLSSLR+yAwj
" />
</div>
<div>
<input type="submit" name="Button1" value="Button" id="Button1" /><br />
<input type="submit" name="Button2" value="Button" id="Button2" /><br />
<input type="submit" name="Button3" value="Button" id="Button3" /><br />
<input type="submit" name="Button4" value="Button" id="Button4" /><br />
</div>
</form>
</body>
</html>


********************************************************************************

按鈕3執行結果,因為轉址到 Default2.aspx 了,不檢視


********************************************************************************

按鈕4執行結果

按下「確定」按鈕後,檢視HTML Source 

<script>alert('測試4。');</script>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>
</title></head>
<body>
<form method="post" action="./Default.aspx" id="form1">
<div class="aspNetHidden">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="h7NFRRI447D991l2ZQcy+9JFtiY
rPds9xYts5NmrhmiDnphRBshNVXvDXoJLtKkY1a/iJvDZIJDGqlrCtdweebYgaG13QzqqMJTRO5Rlflg=
" />
</div>
<div class="aspNetHidden">
<input type="hidden" name="__VIEWSTATEGENERATOR" id="__VIEWSTATEGENERATOR" value="CA0B0334" />
<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="7cdoDgcjEodG4L/ihUVTKy1F95vzm00YhJe7kC73m2hpB6V6WqiHO4b6/jeGFTAkl0C6iJonsXGFUTIHMom
Hi7dKcVZaEeQZCkxpjRSH2THwknHv3hYS9hmarSSWgmCIX+PeAkbYUSc1WbSETL7r5KNlxuISDz349vOtxc1zbv/Dt
9yDBw/o41z8bF8A41m3
" />
</div>
<div>
<input type="submit" name="Button1" value="Button" id="Button1" /><br />
<input type="submit" name="Button2" value="Button" id="Button2" /><br />
<input type="submit" name="Button3" value="Button" id="Button3" /><br />
<input type="submit" name="Button4" value="Button" id="Button4" /><br />
</div>
</form>
</body>
</html>

********************************************************************************

結論:

使用 Response.Write("<script>alert('測試4。');</script>"); 結果在 HTML Source 會出現在 <html> 之前,有點怪異,所以可能盡量避免這種。

(完)

相關

2022年4月20日 星期三

[研究][ASP.NET]判斷非上班時間

[研究][ASP.NET]判斷非上班時間

2022-04-20

環境:Visual Studio 2022 + ASP.NET + WebForm + Web Application + C#

Default.axpx

<%@ Page Language="C#" AutoEventWireup="true" 
    CodeBehind="Default.aspx.cs" Inherits="WebApplication2.Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:Button ID="Button1" runat="server" Text="Button" 
                OnClick="Button1_Click" /><br />
            <asp:Label ID="Label1" runat="server"></asp:Label><br />
        </div>
    </form>
</body>
</html>


Default.aspx.cs

using System;

namespace WebApplication2
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            //DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
            double nowMillisecond = DateTime.Now.TimeOfDay.TotalSeconds;
            //int nowMillisecond = DateTime.Now.Hour * 60 * 60
            //      + DateTime.Now.Minute * 60 + DateTime.Now.Millisecond;
            if (((nowMillisecond >= 21 * 60 * 60) || (nowMillisecond <= 7 * 60 * 60))
                || (DateTime.Now.DayOfWeek == DayOfWeek.Sunday)
                || (DateTime.Now.DayOfWeek == DayOfWeek.Saturday))
                Label1.Text = "非上班時間";
            else
                Label1.Text = "上班時間";
            //DateTime.Now.TimeOfDay.TotalSeconds;
        }
    }
}



(完)


2022年4月18日 星期一

[研究]變更建立帳戶的3個安全性問題(Security Questions) (Windows 10, 11)

[研究]變更建立帳戶的3個安全性問題(Security Questions) (Windows 10, 11)

2022-04-18

Windows 10, 11安裝時,會要求建立3個帳戶的安全性問題,那日後能否改呢?

********************************************************************************

根據下面這篇,是可以改的

How to enable reset local account password on Windows 10 April 2018 Update | Windows Central
https://www.windowscentral.com/how-add-security-questions-reset-local-account-password-windows-10-april-2018-update

Windows 10

In order to reset your local account password on Windows 10 using security questions, you must update your account settings using these steps:

  1. Open Settings.
  2. Click on Accounts.
  3. Click on Sign-in options.
  4. Under "Password," click the Update your security questions link.


根據下面這篇

How to Reset a Forgotten Password in Windows 10 or Windows 11 | PCMag
https://www.pcmag.com/how-to/how-to-reset-a-forgotten-windows-10-password

Windows 10

Settings > Accounts > Sign-in options. Click the option for password and then select the link for Update your security questions.



Windows 11

In Windows 11, there is no visible option for updating your security questions. However, there is an unofficial workaround using a manual command. Press the Win key + R. In the Open field of the Run as dialog box, type or paste the following command: ms-cxh://setsqsalocalonly. Click OK.

********************************************************************************

在Windows 10上實際測試 (使用 本機帳號)




(下圖)不館您是系統管理員或一般帳號,只要沒有被設定禁止變更密碼,就可以看到「更新您的安全性問題」選項

(下圖)被設定禁止變更密碼,您會看不到該選項



但不保證每個 Windows 10的版本都有提供該選項,或許早期有提供,後來不提供了?

或者電腦在AD網域,所以沒有提供。


********************************************************************************

Windows 11

該選項預設隱藏,請按下Win key + R,輸入ms-cxh://setsqsalocalonly,按下「確定」按鈕 ,再依據 Windows 10步驟進行。

(完)

Windows 登入選項和帳戶保護
https://support.microsoft.com/zh-tw/windows/windows-%E7%99%BB%E5%85%A5%E9%81%B8%E9%A0%85%E5%92%8C%E5%B8%B3%E6%88%B6%E4%BF%9D%E8%AD%B7-7b34d4cf-794f-f6bd-ddcc-e73cdf1a6fbf


[研究][ASP.NET]Visual Studio 2022 Just-In-Time Debugger 預設設定

[研究][ASP.NET]Visual Studio 2022 Just-In-Time Debugger 預設設定

2022-04-17



登錄機碼中有關 VsJITDebugger.exe 的設定

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\AppID\VsJITDebugger.exe]
"AppID"="{E62A7A31-6025-408E-87F6-81AEB0DC9347}"

[HKEY_CLASSES_ROOT\CLSID\{36BBB745-0999-4FD8-A538-4D4D84E4BD09}\LocalServer32]
@="\"C:\\Windows\\system32\\vsjitdebugger.exe\""

[HKEY_CLASSES_ROOT\CLSID\{BBE60DE4-551F-444A-81AB-70ADAF417C5D}]
"AppID"="{534E4CF4-3249-4842-8D65-A9BEAE0BBEAC}"
"LocalizedString"="@C:\\Windows\\system32\\vsjitdebugger.exe,-201"
@="CLSID_PrivJITDebuggingHost"

[HKEY_CLASSES_ROOT\CLSID\{BBE60DE4-551F-444A-81AB-70ADAF417C5D}\Elevation]
"Enabled"=dword:00000001

[HKEY_CLASSES_ROOT\CLSID\{BBE60DE4-551F-444A-81AB-70ADAF417C5D}\LocalServer32]
@="\"C:\\Windows\\system32\\vsjitdebugger.exe\" -PrivEmbedding"

[HKEY_CLASSES_ROOT\CLSID\{D40DAF26-8F39-4430-97B9-D3E1A42426C8}\LocalServer32]
"JitExeFilePath"="\"C:\\Windows\\system32\\vsjitdebugger.exe\""

[HKEY_CLASSES_ROOT\WOW6432Node\AppID\VsJITDebugger.exe]
"AppID"="{E62A7A31-6025-408E-87F6-81AEB0DC9347}"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\AppID\VsJITDebugger.exe]
"AppID"="{E62A7A31-6025-408E-87F6-81AEB0DC9347}"
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{36BBB745-0999-4FD8-A538-4D4D84E4BD09}\LocalServer32]
@="\"C:\\Windows\\system32\\vsjitdebugger.exe\""

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{BBE60DE4-551F-444A-81AB-70ADAF417C5D}]
"AppID"="{534E4CF4-3249-4842-8D65-A9BEAE0BBEAC}"
"LocalizedString"="@C:\\Windows\\system32\\vsjitdebugger.exe,-201"
@="CLSID_PrivJITDebuggingHost"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{BBE60DE4-551F-444A-81AB-70ADAF417C5D}\Elevation]
"Enabled"=dword:00000001

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{BBE60DE4-551F-444A-81AB-70ADAF417C5D}\LocalServer32]
@="\"C:\\Windows\\system32\\vsjitdebugger.exe\" -PrivEmbedding"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{D40DAF26-8F39-4430-97B9-D3E1A42426C8}\LocalServer32]
"JitExeFilePath"="\"C:\\Windows\\system32\\vsjitdebugger.exe\""

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\WOW6432Node\AppID\VsJITDebugger.exe]
"AppID"="{E62A7A31-6025-408E-87F6-81AEB0DC9347}"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework]
"Enable64Bit"=dword:00000001
"InstallRoot"="C:\\Windows\\Microsoft.NET\\Framework64\\"
"NGenTaskDelayStart"=dword:00000001
"NGenTaskDelayStartAmount"=dword:00000000
"UseRyuJIT"=dword:00000001
"DbgManagedDebugger"="\"C:\\Windows\\system32\\vsjitdebugger.exe\" PID %d APPDOM %d EXTEXT \"%s\" EVTHDL %d"
"DbgJITDebugLaunchSetting"=dword:00000010

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Low Rights\ElevationPolicy\{E62A7A31-6025-408E-87F6-81AEB0DC9347}]
"AppName"="vsjitdebugger.exe"
"AppPath"="C:\\Windows\\system32\\"
"Policy"=dword:00000023

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Components\91510DF5BDA6E2E4AAA3282A0C1CAB9F]
"00000000000000000000000000000000"="C:\\?Windows\\SysWOW64\\vsjitdebugger.exe"
"80637F3449C5F6341A6E0EA9EC863019"="C:\\?Windows\\SysWOW64\\vsjitdebugger.exe"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Components\91510DF5BDA6E2E4AAA3282A0C1CAB9F\80637F3449C5F6341A6E0EA9EC863019]
"PatchGUID"=""
"MediaCabinet"=""
"File"="VsJitDebuggerExe32"
"ComponentVersion"="17.0.114.0"
"ProductVersion"="17.0.114"
"PatchSize"="0"
"PatchAttributes"="0"
"PatchSequence"="0"
"SharedComponent"="0"
"IsFullFile"="0"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Components\91510DF5BDA6E2E4AAA3282A0C1CAB9F]
"00000000000000000000000000000000"="C:\\?Windows\\SysWOW64\\vsjitdebugger.exe"
"80637F3449C5F6341A6E0EA9EC863019"="C:\\?Windows\\SysWOW64\\vsjitdebugger.exe"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Components\91510DF5BDA6E2E4AAA3282A0C1CAB9F\80637F3449C5F6341A6E0EA9EC863019]
"PatchGUID"=""
"MediaCabinet"=""
"File"="VsJitDebuggerExe32"
"ComponentVersion"="17.0.114.0"
"ProductVersion"="17.0.114"
"PatchSize"="0"
"PatchAttributes"="0"
"PatchSequence"="0"
"SharedComponent"="0"
"IsFullFile"="0"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Components\A4141D667AB62A941B29D3943D5CC78F]
"00000000000000000000000000000000"="C:\\?Windows\\system32\\vsjitdebugger.exe"
"80637F3449C5F6341A6E0EA9EC863019"="C:\\?Windows\\system32\\vsjitdebugger.exe"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Components\A4141D667AB62A941B29D3943D5CC78F\80637F3449C5F6341A6E0EA9EC863019]
"PatchGUID"=""
"MediaCabinet"=""
"File"="VsJitDebuggerExe64"
"ComponentVersion"="17.0.114.0"
"ProductVersion"="17.0.114"
"PatchSize"="0"
"PatchAttributes"="0"
"PatchSequence"="0"
"SharedComponent"="0"
"IsFullFile"="0"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\SharedDLLs]
"C:\\Windows\\system32\\vsjitdebugger.exe"=dword:00000002
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug]
"UserDebuggerHotKey"=dword:00000000
"Debugger"="\"C:\\Windows\\system32\\vsjitdebugger.exe\" -p %ld -e %ld -j 0x%p"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug\AutoExclusionList]
"DWM.exe"=dword:00000001

[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Classes\AppID\VsJITDebugger.exe]
"AppID"="{E62A7A31-6025-408E-87F6-81AEB0DC9347}"

[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\.NETFramework]
"InstallRoot"="C:\\Windows\\Microsoft.NET\\Framework\\"
"NGenTaskDelayStart"=dword:00000001
"NGenTaskDelayStartAmount"=dword:00000000
"DbgManagedDebugger"="\"C:\\Windows\\system32\\vsjitdebugger.exe\" PID %d APPDOM %d EXTEXT \"%s\" EVTHDL %d"
"DbgJITDebugLaunchSetting"=dword:00000010

[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Internet Explorer\Low Rights\ElevationPolicy\{E62A7A31-6025-408E-87F6-81AEB0DC9347}]
"AppName"="vsjitdebugger.exe"
"AppPath"="C:\\Windows\\system32\\"
"Policy"=dword:00000023

[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\VisualStudio\Debugger\JIT]
".NET Debugger"="\"C:\\Windows\\system32\\vsjitdebugger.exe\" PID %d APPDOM %d EXTEXT \"%s\" EVTHDL %d"
"Native Debugger"="\"C:\\Windows\\system32\\vsjitdebugger.exe\" -p %ld -e %ld -j 0x%p"
"Default DbgJITDebugLaunchSetting"=dword:00000010
"Host Path"="C:\\Windows\\system32\\vsjitdebugger.exe"

[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\SharedDlls]
"C:\\Windows\\system32\\vsjitdebugger.exe"=dword:00000002

[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows NT\CurrentVersion\AeDebug]
"UserDebuggerHotKey"=dword:00000000
"Debugger"="\"C:\\Windows\\system32\\vsjitdebugger.exe\" -p %ld -e %ld -j 0x%p"

[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows NT\CurrentVersion\AeDebug\AutoExclusionList]
"DWM.exe"=dword:00000001

[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\EventLog\Application\VsJITDebugger]
"EventMessageFile"="C:\\Windows\\system32\\vsjitdebugger.exe"
"TypesSupported"=dword:00000007

[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet002\Services\EventLog\Application\VsJITDebugger]
"EventMessageFile"="C:\\Windows\\system32\\vsjitdebugger.exe"
"TypesSupported"=dword:00000007

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\EventLog\Application\VsJITDebugger]
"EventMessageFile"="C:\\Windows\\system32\\vsjitdebugger.exe"
"TypesSupported"=dword:00000007

(完)