Asp. NET related questions 14 Q

Source: Internet
Author: User
Tags mail microsoft sql server requires mailmessage root directory
Asp.net| problem 1, ASP. NET can run in those systems?

Currently, ASP. NET can only run on Microsoft Windows 2000, Windows XP and Windows 2003 systems, and requires Microsoft Internet Information Server (IIS) support, Microsoft is scheduled to let Windows NT4.0 also supports ASP.net, but it is possible that Microsoft has some technical issues or market considerations and has not yet implemented NT's asp.net support.

2. Is it possible to use more than one language in an ASPX file?

The answer is a bit disappointing, although Microsoft offers a common language runtime (Clr,common laguage Runtime) that enables tight integration between multiple programming languages, allowing you to export the objects needed for C # from a VB object, but only one language in an ASPX file Just as you can't use C # 's syntax in vb.net.

3. The server-side script for ASPX files support those languages?

Currently, ASPX files only support C #, Visual Basic.NET, JScript.NET, and J #, but you use Code-behind (code-separated) method to create a stand-alone code file, you can use any. NET compiler to enable the functionality of the language.

4, in the Global.asax file can use Code-behind (code separation) technology?

Of course you can, for example:
Global.asax:
<script language=vb "runat=" Server >
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
</script>
and using Code-behind (code separation) technology
Global.asax:
<%@ application inherits= "MYAPP"%>
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. Can I see the code generated by the aspx file in asp.net?

As you can see, when your ASPX file contains the <%@ Page debug= "true"%> command or Web.config declares <compilation debug= "true" >, You can find the files generated by the aspx file under ASP.net in the microsoft.net\framework\v1.0.nnnn\temporary asp.net files in the system directory.

6, in the ASPX file how to annotate it?

Same as the methods in ASP files.
<%--
Response.Write "Test! "
--%>

7. Can there be more than one server-side Form tag in the aspx file?

No

8. Can I use a custom data type in a Web form?

OK, you can put the DLL file containing the custom data type in the Bin directory under the program root directory, ASP. NET loads the DLL file when the data type is referenced.

9. Can I trigger those events in the Global.asax file?
The events that are triggered when the Application object is created and terminated are
application_start
application_end
The events that are triggered when the session object is created and ended are
Session_Start
Session_End
Events that are triggered when a request for a program occurs (in order of occurrence)
Application_BeginRequest
Application_AuthenticateRequest
Application_authorizerequest
Application_resolverequestcache
application_acquirerequeststate
Application_prerequesthandlerexecute
Application_postrequesthandlerexecute
application_releaserequeststate
Application_updaterequestcache
Application_EndRequest
An event that is triggered when a program has an error occurs
Application_Error
application_disposed
10. Does the Web control support style sheets (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-po int Verdana Type:

Support, all Web controls inherit a property called CssClass from the base class System.Web.UI.WebControls.WebControl.
For example:
<style>
. Input {font:10pt verdana; color:red;}
</style>
<body>
<form runat= "Server" >
<asp:textbox cssclass= "Input" runat= "Server"/>
</form>
</body>

11. Which namespaces are imported by default in ASPX files?

The ASPX default import namespace can be referenced directly and imported using other namespaces.

Default namespace
system
system.collections
system.collections.specialized
system.configuration
system.text
system.text.regularexpressions
system.web
system.web.caching
system.web.security
system.web.sessionstate
system.web.ui
system.web.ui.htmlcontrols
system.web.ui.webcontrols
12. Can I create my own server control?
You can, authoring your own ASP.net server control is easy. When you create a simple custom control, all you have to do is define a class derived from System.Web.UI.Control and override its Render method. The Render method takes parameters of the System.Web.UI.HtmlTextWriter type. The HTML that the control sends to the client is passed to the HtmlTextWriter Write method as a string parameter.
For example:
Server control code (simple display String): 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> Welcome to use control development!") </H2> ")
End Sub
End Class
End Namespace
Referencing file simple.aspx:
<%@ Register tagprefix= "simplecontrolsamples" namespace= "Simplecontrolsamples" assembly= "%>

<body>
<form method= "POST" action= "simple.aspx" runat=server>
<simplecontrolsamples:simplevb id= "MyControl" runat=server/>
</form>
</body>

13, how to send the mail in the ASP.net program?

Sending mail in a asp.net program no longer requires component support in the same way as an ASP, and the MailMessage and SmtpMail classes contained within the System.Web.Mail namespace of the. NET Framework base class can implement this functionality.
For example:
Dim message as New Mail.mailmessage
Message. from = "Web3@163.com"
Message. to = "Web3@163.com"
Message. Subject = "Test"
Message. BODY = "Content"
Mail.SmtpMail.SmtpServer = "localhost"
Mail.SmtpMail.Send (Message)

14. How will I read the picture in the database through ado.net and show it?

Here's an example of reading a picture from a pub database in Microsoft SQL Server and displaying it:
<%@ 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. Close ()
End Try
End Sub
</script>



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.