.NET Framework ASPX
ASP.NET 2.0如何使用Login來存取自己的使用者資料庫
星期六, 2月 27th, 2010參考此教學
[Visual C#]Params的應用: Method傳入參數同時可以是陣列與Integer?
星期三, 7月 9th, 2008當我們在撰寫物件導向程式的時候, 難免會需要將參數傳入Method裡面, 若傳入的參數是陣列, 格式如下:
static void Main(string[] args)
{
int[] a = new int[2]{5,7};
Util util = new Util();
Console.WriteLine(util.Min(a));
}
class Util
{
public int Min(int[] param)
{
if (param == null || param.Length == 0)
{
throw new ArgumentException(”Util.Min: not enough arguments”);
}
int currentmin = param[0];
foreach (int i in param)
{
if (i < currentmin)
{
currentmin = i;
}
}
return currentmin;
}
}
這種寫法應該很直觀吧, 但如果傳入的參數是Integer豈不是出現Error? 要怎麼解決呢? 其實要解決這個問題非常簡單, 就是在Method的參數部分加入 “params”這個關鍵字, 寫法如下:
class Util
{
public int Min(params int[] param)
{
if [...]
.NET FRAMEWORK 為自己的程式設定Security Permission
星期三, 5月 7th, 2008為了避免使用者取得他們不應該存取的資料,
.NET FRAMEWORK提供了安全性的物件, 限制使用者的存取權限.
這跟Windows本身的帳戶安全性有些不同, 是針對程式而言.
SecurityAction 屬性有三種:
RequestMinimum(M) 正常執行的最小權限
RequestOptional(O) 可有可無的權限
RequestRefuse(R) 絕對不能有的權限
*P = Security Policy (也就是Enterprise, Machine, User三者的交集)
最終權限的決定放程式為: (P 交 ((M 聯 O) – R))
以下範例顯示:只允許使用者存取特定的資料表, 如果不是指定的資料表, 就無法執行程式:
注: RequestOptional, Unrestricted應設為False, 才表示不允許給予其他的權限; 如果設為True, 則表示沒有限制, 所有權限的給了(很危險, 容易造成駭客的入侵).
Imports System.Security.Permissions
Imports System.Data.SqlClient
<Assembly: UIPermission(SecurityAction.RequestMinimum, Window:=UIPermissionWindow.SafeTopLevelWindows)>
<Assembly: SqlClientPermission(SecurityAction.RequestMinimum, _
ConnectionString:=”server=.;database=pubs;integrated security=true”)>
<Assembly: SecurityPermission(SecurityAction.RequestOptional, Unrestricted:=False)>
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim cn As New [...]
.NET FRAMEWORK 寫一個WinForm程式來監控自己的電腦狀態(WMI)
星期三, 5月 7th, 2008使用Visual Studio 來開發程式, 不只在ASPX有很不錯的功能, 再WINFORM方面也是學幾年都學不完.
以下是一個簡單的範例程式, 作用是監控自己的電腦如果建立一個帳號了, 就會顯示一個對話框, 告訴你所建立的帳號名稱及SID.
當然如果你會舉一反三, 也可以寫類似的程式(利用System.Management的namespace)來玩很多的花樣.
WinForm 程式:
Imports System.Management
Public Class Form1
Dim watcher As ManagementEventWatcher
Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
Button2.PerformClick()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As [...]
ASP.NET 利用GDI+ 產生圖片,並附加文字
星期一, 4月 28th, 2008用程式碼產生圖片是很常用的需求,
這裡教你怎麼把版權宣告文字PRINT在圖片上,
再用IMG CONTROL把它抓出來, 然後不留垃圾在Server.
”Defautlt.aspx
<%@ Page Language=”VB” AutoEventWireup=”false” CodeFile=”Default.aspx.vb” Inherits=”_Default” %>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd“>
<html xmlns=”http://www.w3.org/1999/xhtml” >
<head runat=”server”>
<title>Untitled Page</title>
</head>
<body>
<form id=”form1″ runat=”server”>
<div>
<!– 用IMAGECONTROL把它抓出來 –>
<asp:Image ID=”Image1″ runat=”server” ImageUrl=”~/getImage.aspx” />
</div>
</form>
</body>
</html>
” getImage.aspx
Imports System.Drawing
Imports System.Drawing.Imaging
Partial Class getImage
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim s [...]
ASP.NET 建構自己的Culture
星期三, 4月 23rd, 2008
用.NET FRAMEWORK 2.0可以針對不同的語系去展示網頁.
而culture都是預設的zh-TW, en-US, 如果要自訂Culture呢? 方法如下, 使用Console 端做例子
Imports System.Globalization
Imports System.Threading
Module Module1
Sub Main()
CultureAndRegionInfoBuilder.Unregister(”zh-TW-adams”)
Dim DemoBuilder As New CultureAndRegionInfoBuilder(”zh-TW-adams”, CultureAndRegionModifiers.None)
Dim TWCulture As New CultureInfo(”zh-TW”)
Dim TWRegion As New RegionInfo(”zh-TW”)
DemoBuilder.LoadDataFromCultureInfo(TWCulture)
DemoBuilder.LoadDataFromRegionInfo(TWRegion)
Dim NumberInfo As New NumberFormatInfo()
NumberInfo.CurrencySymbol = “##”
NumberInfo.CurrencyDecimalDigits = “4″
DemoBuilder.NumberFormat = NumberInfo
Dim DateInfo As New DateTimeFormatInfo
DateInfo.DateSeparator = “.”
DemoBuilder.GregorianDateTimeFormat [...]
VB vs C#
星期四, 4月 17th, 2008不知道有沒有人像我一樣常常會去比較每個語言的差異性以及實用性,
有人跟我說Visual Basic很容易學, 比較快得到成就, 但他的發展空間有限.
也有人跟我說Visual C#很難學, 比較難得到成就, 但他可以做比較大的發展.
也有講師級的人說其實兩者可以做到的事情是一樣的.
最主要是看你比較喜歡甚麼..
既然Visual Studio 內兩種語言的CLASS是可以互相使用的,
那使用哪種語言就顯得沒那麼重要的了吧? 就完全看你個人的習慣囉…
但根據我的觀察, 似乎只要會其中一種, 另一種就比較容易上手吧~
這個網址列出了一些VB及C#語法的比較:
http://www.harding.edu/fmccown/vbnet_csharp_comparison.html
沒有說誰比誰好,
能夠幫你達成目的,解決方案的就是好物就對啦~
ASP.NET(VB) Cache, Log.txt 的寫法
星期三, 4月 16th, 2008為了讓資料存取的速度加快, 我們可以設定CACHE把資料站存在伺服器的記憶體.\
如下:
<%@ Page Language=”VB” %>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd“>
<script runat=”server”>
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Label1.Text = Now
End Sub
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs)
If Not IsNothing(Cache(”data”)) Then
Label2.Text = Cache(”data”).ToString()
Else
Label2.Text = “不存在…”
End If
End Sub
Protected Sub [...]
ASP.NET (VB) 用UserControl 建立快速查詢資料
星期一, 4月 14th, 2008UserControl是 .NET FRAMEWORK 2.0 非常好用的功能,
一旦物件建立之後, 包裝起來. 就可以重複使用.
—
testQuery.aspx
—
<%@ Page Language=”VB” %>
<%@ Register Src=”ucQueryCustomers.ascx” TagName=”ucQueryCustomers” TagPrefix=”uc1″ %>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd“>
<script runat=”server”>
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
UcQueryCustomers1.Visible = True
End Sub
‘3, 使用事件
Protected Sub UcQueryCustomers1_Selected(ByVal sender As Object, ByVal e As System.EventArgs)
TextBox1.Text = UcQueryCustomers1.CustomerID
UcQueryCustomers1.Visible = [...]
ASP.NET (VB) 如何存取,加解密 Web.Config 的 AppSettings
星期五, 4月 11th, 2008<%@ Page Language=”VB” %>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd“>
<script runat=”server”>
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Label1.Text = WebConfigurationManager.AppSettings(TextBox1.Text)
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
If Not Page.IsPostBack Then
DropDownList1.DataSource = WebConfigurationManager.AppSettings.Keys
DropDownList1.DataBind()
TextBox2.Text = WebConfigurationManager.AppSettings(DropDownList1.SelectedValue)
End If
End Sub
Protected Sub DropDownList1_SelectedIndexChanged(ByVal [...]

