MyApp.vb:
Imports System.Web
Imports System.Web.SessionState
Public Class MyApp
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
Application("online_session") = 0
End Sub
Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
Application.Lock()
Application("online_session") = CInt(Application("online_session")) + 1
Application.UnLock()
End Sub
Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
Application.Lock()
Application("online_session") = CInt(Application("online_session")) - 1
Application.UnLock()
End Sub
End Class
5、我能否看到ASPX檔案在ASP.NET中產生的程式碼嗎?
可以看到的,當你的ASPX檔案中包含命令或Web.config中聲明了時,你就可以在系統目錄下的Microsoft.NET\Framework\v1.0.nnnn\Temporary ASP.NET Files中找到ASPX檔案在ASP.NET下產生的檔案。
10、Web控制項是否支援樣式表(CSS)呢? Yes. All Web controls inherit a property named CssClass from the base class System.Web.UI.WebControls.WebControl. The following example defines a CSS class named Input and uses it to modify a TextBox control to display text in red 10-point Verdana type:
可以,創作您自己的 ASP.NET 伺服器控制項很容易。建立簡單的自訂控制項時,您所要做的只是定義從 System.Web.UI.Control 派生的類並重寫它的 Render 方法。Render 方法採用 System.Web.UI.HtmlTextWriter 類型的參數。控制項要發送到用戶端的 HTML 作為字串參數傳遞到 HtmlTextWriter 的 Write 方法。
例如:
伺服器控制項代碼(簡單顯示字串):Simple.vb:
Imports System
Imports System.Web
Imports System.Web.UI
Namespace SimpleControlSamples
Public Class SimpleVB : Inherits Control
Protected Overrides Sub Render(Output As HtmlTextWriter)
Output.Write("<H2>歡迎使用控制項開發!</H2>")
End Sub
End Class
End Namespace
引用檔案Simple.aspx:
<%@ Register TagPrefix="SimpleControlSamples" Namespace="SimpleControlSamples" Assembly="SimpleControlSamplesVB" %>
在ASP.NET程式中發送郵件不再象ASP中那樣需要組件的支援了,在.NET的架構基類的System.Web.Mail名稱空間內包含的MailMessage和SmtpMail類可以實現這個功能。
例如:
Dim message As new Mail.MailMessage
message.From = "web3@163.com"
message.To = "web3@163.com"
message.Subject = "測試"
message.Body = "內容"
Mail.SmtpMail.SmtpServer = "localhost"
Mail.SmtpMail.Send(message)
14、我將如何通過ADO.NET讀取資料庫中的圖片並顯示它呢?
下面舉一個從Microsoft SQL Server的PUB資料庫讀取圖片並顯示它的例子:
下面舉一個從Microsoft SQL Server的PUB資料庫讀取圖片並顯示它的例子:
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Drawing.Imaging" %>
<%@ Import Namespace="System.IO" %>
<script language="VB" runat="server">
Sub Page_load(Sender as Object, E as EventArgs)
dim stream as new MemoryStream
dim connection as SqlConnection
connection=new SqlConnection("server=localhost;database=pubs;uid=sa;pwd=")
try
connection.Open()
dim command as SqlCommand
command = new SqlCommand ("select logo from pub_info where pub_id=’0736’", connection)
dim image as byte()
image = command.ExecuteScalar ()
stream.Write (image, 0, image.Length)
dim imgbitmap as bitmap
imgbitmap = new Bitmap (stream)
Response.ContentType = "image/gif"
imgbitmap.Save (Response.OutputStream, ImageFormat.Gif)
Finally
connection.Close()
stream.Clse()
End Try
End Sub
</script>