14 ASP. NET basic knowledge questions and answers (C)

Source: Internet
Author: User
Tags mailmessage
Similar to this topic Article It has been circulating on the Internet for a long time, and a lot of information in it is outdated, and the earliest version is the vb version. I have organized it for the C # version. I would like to share it with you here.

1. Which systems can ASP. NET run?
Currently, Asp. net can only run in Microsoft Windows 2000, Windows XP, Windows 2003, and Windows. Of course, IIS is required. At first, Windows NT4.0 must support ASP. however, Microsoft may have some technical issues or market considerations and has not implemented ASP.. net.

2. Can I use more than one language in An ASPX file?
The answer is a bit disappointing. Although Microsoft provides a Common Language Runtime (CLR ),Programming LanguageClose integration between objects allows you to export the objects required by C # From a VB object, but An ASPX file can only use one language, just as you cannot export files in VB. net uses the same C # syntax, but projects in different languages or generated dll can call each other.

3. Which languages does aspx file server scripts support?
Currently, aspx files only support C #, Visual Basic. net, JScript. net, and J # (currently C # is popular in China), but you use code-ehind (CodeTo create an independent code file, you can use any language supported by the. NET compiler to implement the function.

4. Can code-behind (code separation) Be used in the global. asax file?
Of course. For example:
Global. asax:
And use code-behind (code separation) Technology
Global. asax:
MyApp. CS:

[Run code] [copy to clipboard] [±]

Code:

Using system. Web;
Using system. Web. sessionstate;
Public class MyApp {

Void application_start (Object sender, eventargs e ){
Application (& quot; online_session & quot;) = 0;
}

Void session_start (Object sender, eventargs e ){
Application. Lock ();
Application (& quot; online_session & quot;) = (Int. parse (Application (& quot; online_session & quot;) + 1 );
Application. Unlock (); // bbs.51aspx.com
}

Void session_end (Object sender, eventargs e ){
Application. Lock (); // 51 aspx
Application (& quot; online_session & quot;) = (Int. parse (Application (& quot; online_session & quot;)-1 );
Application. Unlock ();
}
}

5. Can I see the code generated by the aspx file in ASP. NET?
As you can see, when your Aspx file contains commands or web. when the config file is clear, you can go to the Microsoft. netframeworkvx .. nnnntemporary ASP. net files find the aspx file in ASP.. net.

6. How to comment in the aspx file?
C # similar to JS scripts, VB.net has the same syntax as ASP.

7. Can the aspx file contain more than one form tag on the server?
Yes, but there cannot be more than two form (runat = "server") servers at the same time ")

8. Can I use custom data types in web forms?
Yes. You can place the DLL files that contain Custom Data Types inProgramIn the bin directory under the root directory, ASP. NET loads 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
Events triggered when requests occur to programs (arranged in order of occurrence)
• Application_beginrequest
• Application_authenticaterequest
• Application_authorizerequest
• Application_resolverequestcache
• Application_acquirerequeststate
• Application_prerequesthandlerexecute
• Application_postrequesthandlerexecute
• Application_releaserequeststate
• Application_updaterequestcache
• Application_endrequest
Events triggered when a program has an error
• Application_error
• Application_disposed

10. Does the Web Control Support Style Sheets (CSS?

Yes. All Web controls inherit a property called cssclass from the base class system. Web. UI. webcontrols. webcontrol.
For example:

[Run code] [copy to clipboard] [±]

Code:

<HTML>
<Head>
<Style>
. Input {Font: 10pt verdana; color: red ;}
</Style>
</Head>
<Body>
<Form runat = & quot; server & quot;>
<Asp: textbox cssclass = & quot; input & quot; runat = & quot; server & quot;/>
</Form>
</Body>
</Html>

11. Which namespaces are imported by default in the aspx file?
By default, the imported namespace of aspx can be referenced directly, and Other Namespaces can be used for self-import.
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 controls?
Yes. You can easily create your own ASP. NET Server controls. When creating a simple custom control, all you have to do is define the class derived from system. Web. UI. Control and override its render method. The render method uses system. Web. UI. htmltextwriter parameters. The control sends the HTML to the client as a string parameter to the write method of htmltextwriter.
For example:
Server Control Code (simple display string): simple. CS:

[Run code] [copy to clipboard] [±]

Code:

Imports system
Imports system. Web
Imports system. Web. UI
Namespace simplecontrolsamples
Public class simplecsharp
{

Protected override void render (htmltextwriter output)
{
Response. Write ("<H2> welcome to Asp.net source code download professional site <H2> ");
}
}

Reference file simple. aspx:

[Run code] [copy to clipboard] [±]

Code:

<% @ Register tagprefix = "simplecontrolsamples" namespace = "simplecontrolsamples" assembly = "simplecontrolsamplescsharp" %>
<HTML>
<Body>
<Form method = "Post" Action = "Simple. aspx" runat = Server>
<Simplecontrolsamples: simplecsharp id = "mycontrol" runat = server/>
</Form>
</Body>
</Html>

13. How can I send emails in ASP. NET programs?
In ASP. in the. NET program, sending emails no longer requires the support of components as in ASP. net Framework base class system. web. the mailmessage and smtpmail classes in the mail namespace can implement this function.
For example:

[Run code] [copy to clipboard] [±]

Code:

Mail. mailmessage message = new mail. mailmessage ();
Message. From = "test@51aspx.com ";
Message. To = "test@51aspx.com ";
Message. Subject = "email sent to 51aspx ";
Message. Body = "content ";
Mail. smtpmail. smtpserver = "localhost ";
Mail. smtpmail. Send (Message );

14. How can I read and display images in the database through ADO. Net?
The following is an example of reading an image from the pub database of Microsoft SQL Server and displaying it:

[Run code] [copy to clipboard] [±]

Code:

<% @ Import namespace = "system. Data. sqlclient" %>
<% @ Import namespace = "system. Drawing" %>
<% @ Import namespace = "system. Drawing. Imaging" %>
<% @ Import namespace = "system. Io" %>
<Script language = "C #" runat = "server">
Void page_load (Object sender, eventargs e ){
Memorystream stream = new memorystream ();
Sqlconnection connection;
Connection = new sqlconnection ("Server = localhost; database = pubs; uid = sa; Pwd = ");
Try {
Connection. open ();
Sqlcommand command;
Command = new sqlcommand ("select logo from pub_info where pub_id = \ '000000'", connection );
Byte [] image;
Image = command. executescalar ();
Stream. Write (image, 0, image. Length );
Bitmap imgbitmap;
Imgbitmap = new Bitmap (Stream );
Response. contenttype = "image/GIF ";
Imgbitmap. Save (response. outputstream, imageformat. GIF );
}
Finally {
Connection. Close ();
Stream. clse ();
}
}

</SCRIPT>

Source: http://bbs.51aspx.com/showtopic-2635.html

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.