<configuration>
<system.webServer>
<security>
<requestFiltering>
<hiddenSegments>
<add segment=".svn" />
</hiddenSegments>
</requestFiltering>
</security>
</system.webServer>
</configuration>
<compilation debug="true" defaultLanguage="c#" targetFramework="4.0">
<codeSubDirectories>
<add directoryName="VB_Code"/>
<add directoryName="CS_Code"/>
</codeSubDirectories>
</compilation>
<compilation debug="true" defaultLanguage="c#" targetFramework="4.0">
<codeSubDirectories>
<add directoryName="CS_Code"/>
<add directoryName="VB_Code"/>
</codeSubDirectories>
</compilation>
Response.Write(Convert.ToInt32("94"));
Response.Write("<br/>");
Response.Write(Convert.ToInt32(94.5)); //會四捨六入五成雙
Response.Write("<br/>");
Response.Write((94.5).ToString("N0")); //會四捨五入
Response.Write("<br/>");
Response.Write((95.5).ToString("N0")); //會四捨五入
Response.Write("<br/>");
Response.Write(Convert.ToInt32(null)); //會 return 0
Response.Write("<br/>");
Response.Write(Convert.ToInt32("94.55")); //會有 exception 要先轉成 double 之類的數值
Response.Write("<br/>");
<Item time="2016-01-11T05:39:01" page="/fr/iconic-bright-cushion-spf-50-pa-nude-perfection-compact-foundation/p/5490/c/30"
url="http://www.shopunt.com/fr/iconic-bright-cushion-spf-50-pa-nude-perfection-compact-foundation/p/5490/c/30?utm_source=edm&utm_medium=email&utm_content=20160107_cushion_4&utm_campaign=makeup&OutAD_Id=5825" username="Not Member" browserName="Chrome" browserVersion="34.0" userAgent="Mozilla/5.0 (Linux; Android 5.1.1; SAMSUNG SM-N915FY Build/LMY47X) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/2.1 Chrome/34.0.1847.76 Mobile Safari/537.36" RemoteIP="37.160.206.7" Ref="No Ref" RequestType="GET" Ver="3">
<ErrMsg>
</ErrMsg>
<ErrStack> 於 System.Web.CachedPathData.ValidatePath(String physicalPath)
於 System.Web.HttpApplication.PipelineStepManager.ValidateHelper(HttpContext context)</ErrStack>
<Post>
</Post>
<Cookie>
</Cookie>
</Item>
row["SDate"] = "2015-04-01";
row["EDate"] = "2015-04-01";
(row["SDate"] == row["EDate"]) ==> false
(row["SDate"].Equals(row["EDate"])) ==> true
(row["SDate"].ToString() == row["EDate"].ToString()) ==> true
網站開發,善用 Cached DataTable 可以使網站效能倍增,不必一直去資料庫抓資料。
但是使用 Cached DataTable 有一個地方要注意
就是他是 Shared 物件,表示同時有好幾個頁面都可以存取他
例如A網頁將資料抓出,然後變更裡面的DataRow資料,
另一個B網頁也會跟著變更
由於 Cached DataTable 在 Set DataRow Value 時
可能 Critical Section 沒有處理好,若真的同時多個thread 操作
會出現 Exception
(System.ArgumentOutOfRangeException: 索引超出範圍。必須為非負數且小於集合的大小。)
建議:
'這是 UNT FixPage 物件抓取單一資料的範例
Shared Function GetSpecialPage2FromCachedDT(ByVal Key As Int32) As DB.SpecialPage2
Dim DT As DataTable = GetAllDataFromBaseTableWithCache()
Dim Row As DataRow = DT.Rows.Find(Key)
If Row IsNot Nothing Then
'避免每個thread都共用table 寫入資料會出現問題
Dim newDT As DataTable = DT.Clone()
newDT.ImportRow(Row)
Return New SpecialPage2(newDT.Rows(0))
Else
Return Nothing
End If
End Function
'載入物件,bin/ 要放入 .dll
Imports HtmlAgilityPack
'*********************
Dim html As New HtmlDocument()
html.LoadHtml("...一大塊HTML,可以是整個網頁,也可以是html區塊...")
'找出所有img tag
Dim imgNodes As HtmlNodeCollection = html.DocumentNode.SelectNodes("//img")
For Each node As HtmlNode In imgNodes
Dim strUrl As String = node.GetAttributeValue("src", "")
......
Next
Dim intCount As Integer = If(Convert.IsDBNull(row("count")), 0, Convert.ToInt32(row("count")))
// C#
int intCount = Convert.IsDBNull(row("count")) ? 0 : Convert.ToInt32(row("count"));