ASP. NET 2.0 Reading Notes ide

Source: Internet
Author: User
Today's Reading Notes (not sorted ):
1. The tool that controls IIS to use 1.1 or 2.0 is called MMC snapin. At the same time, you can select "Edit configuration", even if you set web. config visually.
2. Repeat the aspnet_regiis command, and the-I parameter is very important. In addition, the sensitive information of Web. config and App. config is encrypted.
3. aspnet_regsql puts account registration in the unified SQL Server, and re-query the parameter configuration.
4. Comparison between ASP. NET 1.1 and 2.0: The field changes in Web. config, and the method for reading this value has also changed:
ASP. NET 1.1 mechanism: two reading Methods: Using system. configuration;

// Method 1
Appsettingsreader configurationappsettings = new appsettingsreader ();
String connectionstring = (string) (configurationetettings. getvalue ("connectionstring", typeof (string )));

// Method 2
String connectionstring = configurationsettings. etettings ["connectionstring"];

ASP. NET 2.0 mechanism, disused configurationsettings:/** // * for the same web. config, read the appsettings or connectionstrings
<Configuration>
<Deleetask>
<Add key = "connectionstring1" value = "connection string"/>
</Appsettings>

<Connectionstrings>
<Add name = "connectionstring2" connectionstring = "connection string 2" providername = "system. Data. sqlclient"/>
</Connectionstrings>
</Configuration>
*/

// Method 1
String connectionstring1 = configurationmanager. etettings ["connectionstring1"];

// Method 2
String connectionstring2 = configurationmanager. connectionstrings ["connectionstring2"]. connectionstring;

5. the encryption and decryption mechanism of Web. config, especially for database connection strings, is also applicable to app. config:
If the project name is "myconfiguration ",
Encryption: aspnet_regiis-pe "encryption field"-app "/myconfiguration"-prov "Specific encryption method provider"
Decryption: aspnet_regiis-Pd "encrypted field"-app "/myconfiguration"
Remember, when a programmer reads a field, no extra decryption is required. The system decrypts the field before you read it.
Another encryption mechanism is to use APIs in programs.

6. Special ASP. NET folders
App_browsers
App_code
App_data
App_globalresources
App_themes
Programs in these folders can only be accessed by applications, but cannot be accessed by requests ).
Each folder generates a DLL.

7. Code segment snippets
This is a good thing and will make me become lazy. I don't even need to knock on the for loop myself.
Remember the key combination (CTRL + k, CTRL + B). You can manage your code snippets.
8. refactoring
This is also a Bt thing, although it is not as good as resharper.
Abstract A piece of code as a methodBut you can only switch the selected code. If there is the same piece of code next to it, vs2005 will not be able to see it (I did it myself)
.
Rename any member(Fields, parameters, methods, etc ).
Encapsulate a field as a property(You can obtain the attribute name by yourself ).
Remove ParametersRemove the parameter from the method, indexer, or delegate. the parameter of the same name in the method will not be moved, so that there will be a syntax error.
Rearrange ParametersIs also limited to parameters in methods, indexers, or delegation.
Extraction InterfaceGenerate interface files based on non-static methods in the class.
Promote local variables to parametersFor example, move the cursor to variable I and run the following command:

// Before processing
Public static void methodb ()
{
// Invoke on 'I'
Int I = 0;
}

// After processing
Public static void methodb (int I)
{
// Invoke on 'I'

}

Note: I checked Microsoft's online msdn. He said so. In combination, I understood:
Upgrading local variables to parameters provides a simple method to move variables from local usage to methods, indexers, or constructor parameters while correctly updating the call site. When you call the "upgrade local variables to parameters" operation, the variables are added to the end of the member parameter list. All calls to modified members will be updated immediately with new parameters (replace the expression originally assigned to the variable) and the code will be retained, to make it work as normal as before the variable is promoted. When a constant value is assigned to the promoted variable, This refactoring operation has the best effect. The variable must be declared and initialized, but not declared or assigned only.

9. dynamically compile DLL Components
1.1 only supports aspx, ascx, and Web. config and global. the dynamic compilation of asax does not support DLL and WebServices. You need to manually compile and re-add DLL references -- 2.0 is now supported, but the DLL of your own project is not generated in the bin directory. The principle is that the system will automatically perform dynamic compilation as long as the user requests it. Therefore, adding a part of the code to a website in use does not require compilation. When the request performs dynamic compilation when this change or new function is used, the elasticity is much larger. You may say that the first time the speed will be very slow, because it is necessary to compile, but only new code blocks or modified parts are allowed. Other non-moving modules are not allowed to compile, so the speed will not be affected.

10. Pre-compile
This is the dll version after compilation, which is the same as the 1.1 Structure (although there is still a poor solution)
Three methods:
Use the command line method aspnet_compiler to add Parameters
"Publish Website" option in IDE
Through API programming, this is the actual operation of the above two methods, the Code is as follows: using system. Web. UI. htmlcontrols;

Clientbuildmanager CBM = new clientbuildmanager ("virtual directory name", "source location", "target location ");
CBM. precompileapplication ();

Note that the DLL generated after pre-compilation does not support dynamic compilation.

11. Use both C # and VB. NET in the same project:
The Web. config configuration is as follows: <configuration>
<System. Web>
<Compilation>
<Codesubdirectories>
<Add directoryname = "CS"/>
<Add directoryname = "VB"/>
</Codesubdirectories>
</Compilation>

Add CS and VB folder under app_code to store files in Cs and VB format respectively (this is not acceptable if no folder is added, because the two folder has been configured in Web. config)

In this way, the two DLL components, app_subcode_cs.dll and app_subcode_vb.dll, are generated in the bin directory after pre-compilation.

12. codebehind
The old codebehind version is as follows (Version 1.1): <% @ page Language = "C #" autoeventwireup = "true" codebehind = "~ /Default. aspx. cs "inherits =" namespace. Class "%>

New codebehind (Version 2.0, also known as codebeside): <% @ page Language = "C #" autoeventwireup = "true" codefile = "~ /Default. aspx. cs "inherits =" class "%>

We can see that the namespace is no longer required for Version 2.0, and the codebehind keyword is changed to codefile.

13. vs2005 SP1
That is, the upgrade package supports the generation of proj files, so that programmers in the vs2003 ERA can return to the previous style, rather than operating the file system, and the namespace is also back, in this way, the special folder of app_code loses its meaning, and the CS file under it needs to be placed again. In addition, the aspx file created under the upgrade package not only can be seen. CS file, which records logical operations and also has an Aspx. design. the CS file is only responsible for declaring the control variables-the two are a class divided into two parts (partial class), the former is used by developers, the latter is automatically generated, it is not recommended to change.

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.