2025年9月1日 星期一

vb ping get domain

 Imports System.Net.NetworkInformation


Public Class Form1


    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click

        Dim url As String = "https://xxx/xxx/xxxx"

        Dim utl_Donaim = GetDomainFromUrl(url)

        'If My.Computer.Network.Ping("198.01.01.01") Then

        'End If

        Using pinger As New Ping()

            Dim reply As PingReply = pinger.Send(utl_Donaim, 5000)

            If reply.Status = IPStatus.Success Then

                MessageBox.Show("Ping to {targetHost} successful! Roundtrip time: {reply.RoundtripTime}ms", "Ping Result")

            Else

                MessageBox.Show("Ping to {targetHost} failed. Status: {reply.Status}", "Ping Result")

            End If

        End Using



    End Sub


    Public Function GetDomainFromUrl(ByVal urlString As String) As String

        Try

            Dim uri As New Uri(urlString)

            Return uri.Host

        Catch ex As UriFormatException

            Return String.Empty

        End Try

    End Function


2025年8月29日 星期五

ASP.NET System.Threading.ThreadAbortException: 執行緒已經中止

 參考引用來源:ASP.NET System.Threading.ThreadAbortException: 執行緒已經中止
---

發生錯誤:執行緒已經中止。     

於 System.Threading.Thread.AbortInternal()

於 System.Threading.Thread.Abort(Object stateInfo)

於 System.Web.HttpResponse.AbortCurrentThread()

於 System.Web.HttpResponse.Redirect(String url, Boolean endResponse, Boolean permanent)

---


解決方案:https://support.microsoft.com/zh-tw/kb/918181

<%@ Page Language="C#" Async="true"%>


當 HttpResponse.Redirect 方法 endResponse 參數不設為 false 時,就會發生這個問題。 根據預設值,endResponse 參數設定為 true。



轉貼連結:http://www.dotblogs.com.tw/boei/archive/2010/07/11/16485.aspx

將網頁轉出成word的時候,最後會來個Response.End()來結束它的輸出,但都會發生<System.Threading.ThreadAbortException> 執行緒已經中止,雖然不會造成系統上的什麼問題。

解決方法:

1.    繼續用Response.End(),外面用try – catch包住,但try – catch會比較消耗資源,所以不考慮。

2.    改用HttpContext.Current.ApplicationInstance.CompleteRequest(),可以跳過Application_EndRequest 事件的執行。

 

如果使用Response.Redirect 或 Server.Transfer 方法也發生一樣狀況的話,就可以使用Response.Redirect(String url, bool endResponse),endResponse就設為False,因為Response.Redirect內部會用到Response.End(),設為False就是要停用Response.End()方法。



2025年8月26日 星期二

webclient 無法建立 SSL/TLS 的安全通道

 在 framework 4.0 無法建立 tls12

只能自己新增:

in .net Framework 4.0 add

ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072; //TLS 1.2

2025年8月25日 星期一

ASP.NET C# URL 網址參數解析,取得網址參數

引用來源:ASP.NET C# URL 網址參數解析,取得網址參數 


  1.  底下分別列出解屬性及解析結果
參數結果
Request.ApplicationPath/
Request.Url.Hostmy.url.com
Request.Url.Port8080
Request.Url.Schemehttps
Request.Url.Authoritymy.url.com:8080
Request.Path/Detail/Page/List.aspx/showmore
Request.Url.LocalPath/Detail/Page/List.aspx/showmore
Request.PathInfo/showmore
Request.Url.Query?mid=20
Request.CurrentExecutionFilePath/Detail/Page/List.aspx
Request.FilePath/Detail/Page/List.aspx
Request.RawUrl/Detail/Page/List.aspx/showmore?mid=20
Request.Url.PathAndQuery/Detail/Page/List.aspx/showmore?mid=20
Request.Url.AbsoluteUrihttps://my.url.com:8080/Detail/Page/List.aspx/showmore?mid=20
Request.Url.AbsolutePath/Detail/Page/List.aspx/showmore

  1.  取得系統路徑
參數結果
Request.PhysicalPathC:\wwwroot\Detail\Page\List.aspx
System.IO.Path.GetDirectoryName(Request.PhysicalPath)C:\wwwroot\Detail\Page
Request.PhysicalApplicationPathC:\wwwroot\
System.IO.Path.GetFileName(Request.PhysicalPath)List.aspx

  1.  解析參數
參數結果
Request.Url.Segments/, Detail/, Page/, List.aspx/, showmore


2025年8月23日 星期六

跳轉頁面發生 RegisterForEventValidation 只能在 Render(); 期間呼叫

 跳轉頁面發生:

System.InvalidOperationException: 'RegisterForEventValidation 只能在 Render(); 期間呼叫'

這個問題,可以設定aspx原始檔中<%Page%>的以下兩個設定解決

EnableEventValidation = "false" AutoEventWireup="true"



2025年8月21日 星期四

windows 11 pdf 小圖示不見

 一、在C:\Users\ABC\AppData\Local的路徑下的IconCache.db刪除(其中ABC為你自己設定的使用者名稱)

二、然後在工作管理員中將「Windows檔案總管」重新啟動,或是重新開機即可恢復