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

搜尋意見
文章分類-Bike
[所有文章分類]
  • ASP.NET (10)
  • ASP.NET2.0 (6)
  • ASP.NET4.0 (7)
  • JavaScript (11)
  • jQuery (9)
  • FireFox (0)
  • UW系統設定 (0)
  • SQL (10)
  • SQL 2008 (7)
  • mirror (0)
  • SVN (2)
  • IE (2)
  • IIS (9)
  • IIS6 (0)
  • 閒聊 (0)
  • W3C (0)
  • 作業系統 (1)
  • C# (0)
  • CSS (3)
  • FileServer (0)
  • HTML 5 (3)
  • CKEditor (2)
  • UW.dll (3)
  • Visual Studio (4)
  • Browser (2)
  • SEO (1)
  • Google Apps (0)
  • 網站輔助系統 (0)
  • DNS (0)
  • SMTP (1)
  • 網管 (1)
  • 社群API (0)
  • SSL (0)
  • App_Inventor (0)
  • URLRewrite (0)
  • 開發工具 (0)
  • JSON (0)
  • Excel2007 (0)
  • 試題 (3)
  • LINQ (0)
  • bootstrap (0)
  • Vue (0)
  • IIS7 (0)
  • foodpanda (0)
  • 編碼 (0)
  • 資安 (0)
  • Sourcetree (0)
  • MAUI (1)
  • CMD (0)
  • my sql (0)
所有文章分類
[Bike的分類]
  • 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
  • 用 Javascript 跨網頁讀取 cookie (Cookie cross page, path of cookie)
    ...more
  • IIS 配合 AD (Active Directory) 認証, 使用 .Net 6.0
    太感謝你了~~~你救了我被windows 認證卡了好幾天QQ...more
  • PostgreSQL 的 monitor trigger
    FOR EACH ROW 可能要改為 FOR EACH STATEMENT ...more
  • 用 Javascript 跨網頁讀取 cookie (Cookie cross page, path of cookie)
    ;;;;...more
  • 匯出 let's encryption的憑証
    1. win-acme 選擇 A: Manage renewals找到你要轉移的憑證名稱和密碼2. ...more
  • 資安問題 -- 存入 DB 後顯示內容
    伺服器隱碼問題1 寫入DB前不是當成字串就執行某些事情 (某些server 漏洞? 許功蓋?)2 寫...more
  • 匯出 let's encryption的憑証
    【注意】要打開 win-acme <<這個軟體匯出憑證...more
  • Swagger 的問題解決 (NSwag)
    DefaultController所產出的文建會讓Swagger讀不懂報錯[ApiExplorerS...more
  • 合併兩個 Expression -- Combining two expressions (Expression>)
    官方文件就有寫啊,這麼多方法不全部看個一遍說不過去吧~https://learn.microsoft...more
標籤
  • admin[t]
  • 974
  • complie
  • MathUtil
  • UbLCzwgH
  • gxfRZJS5
  • -2490
  • 5480
  • IDictionar
  • AD
  • [u2]
  • ?
  • 優缺點
  • minvalue[t
  • Z8Pq1DYd
  • 80
  • 懶惰
  • -3769
  • 置中
  • DBCC
  • iTextSharp
  • 662
  • 6682
  • 5218
  • ctcn
  • 854
  • 3072
  • 564
  • -8739 UNIO
  • bdodo
  • MSkvKiovQW
  • 230
  • 88.4rajb
  • 使用者對應
  • sys_log
  • 瘦身
  • iis2121121
  • 免費憑證
  • SVG
  • .
  • 202
  • viewstate
  • fdoug懶惰程式碼
  • 1194
  • i16nRbWe
  • @@casZ6
  • 授權
  • sing212112
  • User ORDER
  • CS21211211
搜尋 結果:
.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
304 和 200 (From Cache)
今天在觀察 Chrome 怎麼處理網頁中的 <script type="text/javascript" src="/scripts/unt.14.04.10.19.05.42.js"></script>  時,終於明白何時才會 200 (From Cache) (unt.14.04.10.19.05.42.js 是假的,實際會被重導到 scripts.aspx 來處理。)

1. 在網址列,同網址再按一下  Enter 載入時,Chrome 會對相同的網址再次送出 request。

2. 若是點選頁面中的連結或是在網址列輸入其它網址,才有可能看到 200 (From Cache)

在情況 1 時,若是有使用 Response.Cache.SetLastModified(Now) 則會看到 304 ,否則會把 Script 重新載入一次。

所以在 Server 最佳的(我覺得)寫法是:

Response.Cache.SetCacheability(HttpCacheability.Private)
Response.Cache.SetExpires(Now.AddYears(1))  '一年後才會到期,沒有這個就不會有 200 (From Cache)
Response.Cache.SetLastModified(Now)  '若是 Browser 送出了一個新的 Request, 有可能會回 304


不過有趣的是,在 scripts.aspx 收到帶有 ​If-Modified-Since 的 Request 時,是怎麼判斷要回應 304 的,我在 .vb 裡面沒有加上這個處理吔。
More...
Bike, 2014/4/10 下午 07:38:01
.Net 使用 System.Net.Mail.MailMessage 寄信時會鎖定附件
今天發現 uw.mail.sendmail 在寄信時,若是有附件,附件會被鎖住,直到下一次有人寄件信為止。

解決方法是一要把 System.Net.Mail.MailMessage 物件釋放掉 (做 dispose 的動做)。要記得更新 sendmail 這支程式哦。
More...
Bike, 2014/3/15 下午 04:48:59
VB 的日期常數
Optional TF As Date = #12/30/2000#
More...
Bike, 2012/11/21 下午 07:18:17
新增防止駭客的功能
在 Application_BeginRequest 可以加入 BlockHacker

    void Application_BeginRequest(object sender, EventArgs e)
    {
        UW.WU.BlockHacker();
    }

 

可以做一些基本的防駭.

在 Sys_Coonfig 中有兩個參數要設定: WEB_ERROR_ExceptionCountBeforeBlock, WEB_ERROR_ExceptionCountingIntervalInMinutes

另外還有一個參數: WEB_ERROR_DangerousKeywords, 內容請用逗號分隔, 若是發生 Exception 時, Form 或 QueryString 中含有指定的文字, 收到的警告信會標示為高重要性.
More...
Bike, 2012/6/9 上午 09:06:25
global.asax 的事件
從 http://blog.ie-soft.de/post/2007/12/globalasax-events.aspx  抄來的. 留作參考

HttpApplication Events:

Application_AcquireRequestState
Occurs when ASP.NET acquires the current state (for example, session state) that is associated with the current request. 

Application_AuthenticateRequest
Occurs when a security module has established the identity of the user. 

Application_AuthorizeRequest
Occurs when a security module has verified user authorization. 

Application_BeginRequest
Occurs as the first event in the HTTP pipeline chain of execution when ASP.NET responds to a request. 

Application_Disposed
Adds an event handler to listen to the Disposed event on the application. 

Application_EndRequest
Occurs as the last event in the HTTP pipeline chain of execution when ASP.NET responds to a request. 

Application_Error
Occurs when an unhandled exception is thrown. 

Application_PostAcquireRequestState
Occurs when the request state (for example, session state) that is associated with the current request has been obtained. 

Application_PostAuthenticateRequest
Occurs when a security module has established the identity of the user. 

Application_PostAuthorizeRequest
Occurs when the user for the current request has been authorized. 

Application_PostMapRequestHandler
Occurs when ASP.NET has mapped the current request to the appropriate event handler. 

Application_PostReleaseRequestState
Occurs when ASP.NET has completed executing all request event handlers and the request state data has been stored. 

Application_PostRequestHandlerExecute
Occurs when the ASP.NET event handler (for example, a page or an XML Web service) finishes execution. 

Application_PostResolveRequestCache
Occurs when ASP.NET bypasses execution of the current event handler and allows a caching module to serve a request from the cache. 

Application_PostUpdateRequestCache
Occurs when ASP.NET completes updating caching modules and storing responses that are used to serve subsequent requests from the cache. 

Application_PreRequestHandlerExecute
Occurs just before ASP.NET begins executing an event handler (for example, a page or an XML Web service). 

Application_PreSendRequestContent
Occurs just before ASP.NET sends content to the client. 

Application_PreSendRequestHeaders
Occurs just before ASP.NET sends HTTP headers to the client. 

Application_ReleaseRequestState
Occurs after ASP.NET finishes executing all request event handlers. This event causes state modules to save the current state data. 

Application_ResolveRequestCache
Occurs when ASP.NET completes an authorization event to let the caching modules serve requests from the cache, bypassing execution of the event handler (for example, a page or an XML Web service). 

Application_UpdateRequestCache
Occurs when ASP.NET finishes executing an event handler in order to let caching modules store responses that will be used to serve subsequent requests from the cache. 

Application_Init
This method occurs after _start and is used for initializing code. 

Application_Start
As with traditional ASP, used to set up an application environment and only called when the application first starts.

Application_End
Again, like classic ASP, used to clean up variables and memory when an application ends.

Session Events:

Session_Start
As with classic ASP, this event is triggered when any new user accesses the web site.

Session_End
As with classic ASP, this event is triggered when a user's session times out or ends. Note this can be 20 mins (the default session timeout value) after the user actually leaves the site.

Profile Events:

Profile_MigrateAnonymous
Occurs when the anonymous user for a profile logs in.

Passport Events:

PassportAuthentication_OnAuthenticate
Raised during authentication. This is a Global.asax event that must be named PassportAuthentication_OnAuthenticate.
 

Possibly more events defined in other HttpModules like:

System.Web.Caching.OutputCacheModule
System.Web.SessionState.SessionStateModule
System.Web.Security.WindowsAuthentication
System.Web.Security.FormsAuthenticationModule
System.Web.Security.PassportAuthenticationModule
System.Web.Security.UrlAuthorizationModule
System.Web.Security.FileAuthorizationModule
System.Web.Profile.ProfileModule

More...
Bike, 2012/6/9 上午 08:55:08
把 Hashtable 的 Keys 轉為 String Array
有點笨的問題, 但每次遇到都忘了要怎麼定義字串陣列 :P 在這裡記錄一下.. 以下的 HT 是一個 Hashtable
Dim arrKeys(HT.Count - 1) As String
HT.Keys.CopyTo(arrKeys, 0)
More...
Bike, 2012/6/6 下午 03:58:21
不要再用 IIf 函式,請改用 If
VB 不知何時多了一個 if 函式, 可以用來取代 iif.

使用 iif 時, true part 和 false part 都會執行.

改用 if 就不會有這個問題, 比較像 AndAlso 和 OrElse 的行為. 有短路(short circuit)的特性. 會依據判斷式的結果只執行部份的結果.
IIf(X IsNot Nothing, X.qty, 0) --> 會有 Error

If(X IsNot Nothing, X.qty, 0) --> OK


2012/6/3 補述:
發現一個問題, 在 VS2010 中, If(X IsNot Nothing, X.qty, 0) 會造成 Compile 錯誤, 但網站是可以正常執行的..

這是 VS2010 的 Bug 嗎 ?

More...
Bike, 2012/5/16 上午 09:42:57
在列印前把列印的內容使用圖檔存備份
主要是使用 Printing.PreviewPrintController 的產生預覽圖片的功能來儲存列印內容, 再把圖片送到印表機, 以保証列印內容和儲存的圖檔是一致的. 值得一提的是, 在預覽時可以使用不同的印表機, 以便讓產生較小的圖檔, 否則有時會發生 GDI+ 的錯誤.

Sample 如下:

Imports System.Drawing.Printing

Namespace X
    Partial Public Class PrintSomething
        Dim PD As PrintDocument

        Dim ppc As New Printing.PreviewPrintController()

        Dim TotalPage As Int32 = 0

        ''' <summary>
        ''' 第幾次列印, 用來控制寫出的圖檔
        ''' </summary>
        ''' <remarks></remarks>
        Dim PrintCount As Int32 = 1

        Dim PageCount As Int32 = 1

            :
            :
            :
      
        Sub New(ByVal oPM As DB.PackingListMain, ByVal dtDetail As DataTable, dtUsedCoupon As DataTable)
            '初始化資料
            :
            :
            :
        End Sub

        Sub InitPrintDocument()
            '在這裡設定 PrintDocument 的紙張, 印表機, 邊界, 橫印或直印

            PD = New PrintDocument

            :
            :
            :

        End Sub

        Sub print()
            InitPrintDocument()

            PD.PrintController = ppc

           
            ' 第一次先把列印結果存在 Printing.PreviewPrintController 中
            AddHandler PD.PrintPage, AddressOf GeneratePreview

            '再來儲存圖片
            AddHandler PD.EndPrint, AddressOf SaveImage

            PD.Print()
        End Sub


        Dim ppi() As Printing.PreviewPageInfo
        Dim PrintPage As Int32 = 0

        Sub SaveImage(ByVal sender As Object, ByVal ev As PrintEventArgs)

            PrintDebug("Save Image Start, " & Now.ToString("yyyy-MM-dd HH:mm:ss.fff"))

            '把圖檔存起來
            Dim TF As String = Now.ToString("yyyyMMddHHmmss") ' DB.SysConfig.Path.LocalDataRoot
            Dim PathLocal As String = "C:\PrintLog\" & TF.Substring(0, 4) & "-" & TF.Substring(4, 2) & "\"
            Dim PathPackingListSheetImage As String = DB.SysConfig.PackingListSheetImage & TF.Substring(0, 4) & "-" & TF.Substring(4, 2) & "\"

            System.IO.Directory.CreateDirectory(PathLocal)
            System.IO.Directory.CreateDirectory(PathPackingListSheetImage)

            Dim LatestImages As String = ""
            ppi = ppc.GetPreviewPageInfo()

            For x As Integer = 0 To ppi.Length - 1
                Dim Filename As String = TF & "_" & Me.oPM.Id & "_" & x & ".png"

                ppi(x).Image.Save(PathLocal & Filename, System.Drawing.Imaging.ImageFormat.Png)
            Next


            '把圖檔印出來
            For x As Integer = 0 To ppi.Length - 1
  '建立新的 PrintDocument
                InitPrintDocument()

                If CST.WebConfig.Server_NAME = "測試主機" Then
                    UW.WU.DebugWriteLine("PrinterName: " & Me.PD.PrinterSettings.PrinterName)
                    UW.WU.DebugWriteLine("PaperSize: " & PD.DefaultPageSettings.PaperSize.PaperName)

                    PD.DocumentName = "PackingList"
                    PD.PrinterSettings.PrintFileName = "C:\PDF\PackingList" & Now.ToString("yyyyMMddHHmmss") & "_" & PrintPage & ".prn"
                    PD.PrinterSettings.PrintToFile = True

                    'PD.PrinterSettings.
                End If

                '很奇怪, 這裡不會分頁, 所以要一張一張印   
                AddHandler PD.PrintPage, AddressOf pd_PrintPage2
                PD.Print()


               PrintPage += 1

            Next
        End Sub

        Private Sub pd_PrintPage2(ByVal sender As Object, ByVal ev As PrintPageEventArgs)
            '很奇怪, 這裡不會分頁, 所以要一張一張印           
            ev.Graphics.DrawImage(ppi(PrintPage).Image, 0, 0)
            ev.HasMorePages = False
        End Sub


        Private Sub GeneratePreview(ByVal sender As Object, ByVal ev As PrintPageEventArgs)
            ' 列印內容
        End Sub

        End Class
    End Class

End Namespace

More...
Bike, 2012/5/3 下午 04:00:38
Select with XLock
在 Select 指令後, 依據結果做一些工作, 即使有 Transaction, 但還是有可能發生一致性的問題:

Ex:

        Dim Conn As SqlConnection = UW.SQL.GetOpenedConnection
        Dim Tran As SqlTransaction = Conn.BeginTransaction

        Try
            Dim C As Int32 = UW.SQL.GetSingleValue("Select Counter From TableA Where Id = 1", Tran)
            C = C + 1
            UW.SQL.executeSQL("Update TableA Set Counter = " & C & " Where  Id = 1", Tran)
            Tran.Commit()
        Catch ex As Exception
            Tran.Rollback()
            UW.WU.DebugWriteLine(ex.ToString, True, True)

        Finally
            If Conn.State <> ConnectionState.Closed Then
                Conn.Close()
            End If

        End Try


以上的程式由兩個 Session 同時執行時, 並不能保証 Counter 會被加 2

若是要保証兩個 Session 都會把 Counter 加一(總共加 2), 要把以下這一行

Dim C As Int32 = UW.SQL.GetSingleValue("Select Counter From TableA Where Id = 1", Tran)

改為

Dim C As Int32 = UW.SQL.GetSingleValue("Select Counter From TableA With(XLock) Where Id = 1", Tran)
More...
Bike, 2012/5/3 下午 03:02:16
~ Uwinfo ~