2024年5月30日 星期四

Asp.net MVC Web.config導頁設定

以下筆記一下而已
<?xml version="1.0" encoding="utf-8"?>
<configuration>

<system.webServer>
	<httpProtocol>
		<customHeaders>
			<clear />
			<add name="X-UA-Compatible" value="IE=Edge" />
		</customHeaders>
	</httpProtocol>
	<httpErrors>
		<remove statusCode="502" subStatusCode="-1" />
		<remove statusCode="501" subStatusCode="-1" />
		<remove statusCode="500" subStatusCode="-1" />
		<remove statusCode="406" subStatusCode="-1" />
		<remove statusCode="412" subStatusCode="-1" />
		<remove statusCode="405" subStatusCode="-1" />
		<remove statusCode="404" subStatusCode="-1" />
		<remove statusCode="403" subStatusCode="-1" />
		<remove statusCode="401" subStatusCode="-1" />
		<error statusCode="401" prefixLanguageFilePath="" path="https://easyusingx.blogspot.com/" responseMode="Redirect" />
		<error statusCode="403" prefixLanguageFilePath="" path="https://easyusingx.blogspot.com/" responseMode="Redirect" />
		<error statusCode="404" prefixLanguageFilePath="" path="https://easyusingx.blogspot.com/" responseMode="Redirect" />
		<error statusCode="405" prefixLanguageFilePath="" path="https://easyusingx.blogspot.com/" responseMode="Redirect" />
		<error statusCode="412" prefixLanguageFilePath="" path="https://easyusingx.blogspot.com/" responseMode="Redirect" />
		<error statusCode="406" prefixLanguageFilePath="" path="https://easyusingx.blogspot.com/" responseMode="Redirect" />
		<error statusCode="500" prefixLanguageFilePath="" path="https://easyusingx.blogspot.com/" responseMode="Redirect" />
		<error statusCode="501" prefixLanguageFilePath="" path="https://easyusingx.blogspot.com/" responseMode="Redirect" />
		<error statusCode="502" prefixLanguageFilePath="" path="https://easyusingx.blogspot.com/" responseMode="Redirect" />
	</httpErrors>
</system.webServer>
</configuration>

2024年3月1日 星期五

Asp.net MVC Razor Page Url.Action編碼問題

在Razore Page的裡面使用Url.Action
在JS內會產生連結
連結怎麼點都會錯,仔細一看&被編碼了
外面包一層Html.Raw以免被編碼
這樣連結就會正常
參考資料
Url.Action puts an & in my url, how can I solve this?

2024年2月19日 星期一

c# Unix Timestamp轉換

近期專案接觸到很多API
發現目前大多數日期都是數字,查了一下是Unix Timestamp
寫了兩個Function來互轉
時間轉數字
public static double DateToDouble(DateTime? pNow = null)
{
    DateTime mNow = DateTime.Now;
    if (pNow != null && pNow.HasValue)
    {
        mNow = pNow.Value;
    }
    DateTimeOffset t = DateTimeOffset.Parse(mNow.ToString("yyyy-MM-dd HH:mm:ss"));
    return Convert.ToDouble(t.ToUnixTimeSeconds());
}
數字轉時間
  public static DateTime DoubleToDate(double? pDate = 0)
  {
      double d = 0;
      if (pDate != null && pDate.HasValue)
      {
          d = pDate.Value;
      }

      if (d > 9999999999)
          d = d / 1000;

      DateTime StartComputerFirstDay = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
      return StartComputerFirstDay.AddSeconds(d).ToLocalTime();
  }
參考資料
[C#] 時間轉換為Unix TimeStamp
Epoch (computing)
The Current Epoch Unix Timestamp

2024年1月25日 星期四

.Net Core The SSL connection could not be established, see inner exception.

在使用HttpClient時出現錯誤
The SSL connection could not be established, see inner exception.
網路上能找的解法都用上了都沒用
後來猜想是不是TLS支援度問題
所以將程式移至另一台OS較新的Server上就可以了
Server 2012 X > Server 2016 O
參考資料
The SSL connection could not be established, see inner exception.
Windows Server2012 R2不支持TLS1.3