Home Backend Development C#.Net Tutorial Detailed explanations of some classic ASP.NET issues

Detailed explanations of some classic ASP.NET issues

Jul 03, 2017 pm 04:58 PM
asp.net Detailed explanation question


 1. In which systems can ASP.NET run?

At present, ASP.NET can only run on Microsoft's Windows 2000, Windows XP and Windows 2003 systems, and requires the support of Microsoft Internet Information Server (IIS). Microsoft originally planned to make Windows NT4. 0 also supports ASP.NET, but Microsoft may have some technical issues or market considerations and has not yet implemented support for ASP.NET under NT.

 2. Can more than one language be used in one ASPX file?

The answer will make you a little disappointed. Although Microsoft provides a common language runtime environment (CLR, Common Laguage Runtime), which achieves tight integration between multiple programming languages, allowing you to A VB object exports the objects required by C#, but only one language can be used in an ASPX file, just as you cannot use C# syntax in VB.NET.

 3. What languages ​​do the server-side scripts of ASPX files support?

Currently, ASPX files only support C#, Visual Basic.NET, Jscript.NET and J#, but if you use the code-behind (code separation) method to create an independent code file, you can use any . NET compiler supports the language to implement the function.

 4. Can code-behind (code separation) technology be used in the Global.asax file?

Of course, for example:
Global.asax:

And use code-behind (code separation) technology

 Global.asax:  
    
  MyApp.vb:  
  Imports System.Web  
  Imports System.Web.
Session
State  
  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
Copy after login

5. Can I See the code that an ASPX file generates in ASP.NET?

As you can see, when your ASPX file contains a command or is declared in Web.config, you can use Microsoft.NET\Framework\v1.0.nnnn\Temporary ASP in the system directory Find the ASPX file generated under ASP.NET in .NET Files.

 6. How to comment in ASPX files?

Same as the method in the ASP file.
 

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

No

8. Can I use custom data types in Web forms

Yes, you can include custom data The DLL file of the type is placed in the BIN directory in the program root directory. ASP.NET will load the DLL file when the data type is referenced.

 9. What events can I trigger in the Global.asax file?
The events triggered when the Application object is created and ended are
Application_Start
Application_End
The events triggered when the Session object is created and ended are
• Session_Start
• Session_End
Right The events triggered when the program has a request are (arranged in order of occurrence)
 •Application_BeginRequest 
 •Application_AuthenticateRequest 
 •Application_AuthorizeRequest 
 •Application_ResolveRequestCache 
 •Application_AcquireRequestState 
 •Application_PreRequestHandler Execute
 •Application_PostRequestHandlerExecute
 •Application_ReleaseRequestState 
 •Application_UpdateRequestCache 
 •Application_EndRequest 
 The events triggered when an error occurs in a program are
 •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-point Verdana type:

Supported, all Web controls inherit a property called CssClass from the base class System.Web.UI.WebControls.WebControl.
For example:

  
   <html>  
    <head>  
    <style>  
    .Input { font: 10pt verdana; color: red; }  
    </style>  
    </head>  
    <body>  
    <form runat="server">  
    <asp:TextBox CssClass="Input" RunAt="server" />  
    </form>  
    </body>  
    </html>
Copy after login

   11、在ASPX文件中默认导入那些名称空间?

  ASPX默认导入的名称空间可以直接引用了,使用其它的名称空间就的自行导入了。

  默认名称空间
   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、我是否可以自己创建服务器控件呢?

  可以,创作您自己的 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
Copy after login

引用文件Simple.aspx:

 <%@ Register TagPrefix="SimpleControlSamples" Namespace="SimpleControlSamples" Assembly="SimpleControlSamplesVB" %>  
    <html>  
    <body>  
    <form method="POST" action="Simple.aspx" runat=server>  
    <SimpleControlSamples:SimpleVB id="MyControl" runat=server/>  
    </form>  
    </body>  
    </html>
Copy after login

  13、如何在ASP.NET程序中发送邮件呢?

  在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)
Copy after login

  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=&#39;0736&#39;", 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>
Copy after login

The above is the detailed content of Detailed explanations of some classic ASP.NET issues. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1666
14
PHP Tutorial
1273
29
C# Tutorial
1253
24
Detailed explanation of obtaining administrator rights in Win11 Detailed explanation of obtaining administrator rights in Win11 Mar 08, 2024 pm 03:06 PM

Windows operating system is one of the most popular operating systems in the world, and its new version Win11 has attracted much attention. In the Win11 system, obtaining administrator rights is an important operation. Administrator rights allow users to perform more operations and settings on the system. This article will introduce in detail how to obtain administrator permissions in Win11 system and how to effectively manage permissions. In the Win11 system, administrator rights are divided into two types: local administrator and domain administrator. A local administrator has full administrative rights to the local computer

Detailed explanation of division operation in Oracle SQL Detailed explanation of division operation in Oracle SQL Mar 10, 2024 am 09:51 AM

Detailed explanation of division operation in OracleSQL In OracleSQL, division operation is a common and important mathematical operation, used to calculate the result of dividing two numbers. Division is often used in database queries, so understanding the division operation and its usage in OracleSQL is one of the essential skills for database developers. This article will discuss the relevant knowledge of division operations in OracleSQL in detail and provide specific code examples for readers' reference. 1. Division operation in OracleSQL

Detailed explanation of the linux system call system() function Detailed explanation of the linux system call system() function Feb 22, 2024 pm 08:21 PM

Detailed explanation of Linux system call system() function System call is a very important part of the Linux operating system. It provides a way to interact with the system kernel. Among them, the system() function is one of the commonly used system call functions. This article will introduce the use of the system() function in detail and provide corresponding code examples. Basic Concepts of System Calls System calls are a way for user programs to interact with the operating system kernel. User programs request the operating system by calling system call functions

Detailed explanation of the role and usage of PHP modulo operator Detailed explanation of the role and usage of PHP modulo operator Mar 19, 2024 pm 04:33 PM

The modulo operator (%) in PHP is used to obtain the remainder of the division of two numbers. In this article, we will discuss the role and usage of the modulo operator in detail, and provide specific code examples to help readers better understand. 1. The role of the modulo operator In mathematics, when we divide an integer by another integer, we get a quotient and a remainder. For example, when we divide 10 by 3, the quotient is 3 and the remainder is 1. The modulo operator is used to obtain this remainder. 2. Usage of the modulo operator In PHP, use the % symbol to represent the modulus

Detailed explanation of Linux curl command Detailed explanation of Linux curl command Feb 21, 2024 pm 10:33 PM

Detailed explanation of Linux's curl command Summary: curl is a powerful command line tool used for data communication with the server. This article will introduce the basic usage of the curl command and provide actual code examples to help readers better understand and apply the command. 1. What is curl? curl is a command line tool used to send and receive various network requests. It supports multiple protocols, such as HTTP, FTP, TELNET, etc., and provides rich functions, such as file upload, file download, data transmission, proxy

Learn more about Promise.resolve() Learn more about Promise.resolve() Feb 18, 2024 pm 07:13 PM

Detailed explanation of Promise.resolve() requires specific code examples. Promise is a mechanism in JavaScript for handling asynchronous operations. In actual development, it is often necessary to handle some asynchronous tasks that need to be executed in sequence, and the Promise.resolve() method is used to return a Promise object that has been fulfilled. Promise.resolve() is a static method of the Promise class, which accepts a

How to solve the problem that jQuery cannot obtain the form element value How to solve the problem that jQuery cannot obtain the form element value Feb 19, 2024 pm 02:01 PM

To solve the problem that jQuery.val() cannot be used, specific code examples are required. For front-end developers, using jQuery is one of the common operations. Among them, using the .val() method to get or set the value of a form element is a very common operation. However, in some specific cases, the problem of not being able to use the .val() method may arise. This article will introduce some common situations and solutions, and provide specific code examples. Problem Description When using jQuery to develop front-end pages, sometimes you will encounter

Detailed explanation of numpy version query method Detailed explanation of numpy version query method Jan 19, 2024 am 08:20 AM

Numpy is a Python scientific computing library that provides a wealth of array operation functions and tools. When upgrading the Numpy version, you need to query the current version to ensure compatibility. This article will introduce the method of Numpy version query in detail and provide specific code examples. Method 1: Use Python code to query the Numpy version. You can easily query the Numpy version using Python code. The following is the implementation method and sample code: importnumpyasnpprint(np

See all articles