1. Is there a way to make JavaScript comments invisible on the client? The answer is simple: javascript comments + server comments!
Line comment:
// <% -- Write a line comment here -- %>
Block comment writing:
/* <% --
Write the comment statement block here,
Multiple rows.
-- %> */
Our own developers can read the complete annotations, And the compiled ASP.. NET page will ignore the comments in <% -- to -- %>. Malicious attackers will not see these comments on the client. You can only see: // or /**/
2. C # the fastest way to retain N decimal places
. Tostring ("FN ")
Replace N with a number. For example, tostring ("F2") can retain two decimal places, which is quite convenient.
3. Obtain the database connection information in the configuration section.
Code
StringConnstring= String
. Empty;
Connectionstringsettings settings=Configurationmanager. connectionstrings ["Databaseconnection"
];
If(Settings! = Null
)
{
Connstring=
Settings. connectionstring;
}
4. operate databases
Code
Public Dataset executedataset ( String SQL, String Connectionstring)
{
Using (Sqlconnection connection = New Sqlconnection (connectionstring ))
{
Dataset DS = New Dataset ();
Sqldataadapter da = New Sqldataadapter (SQL, connectionstring );
Da. Fill (DS );
Return DS;
}
}
Public Int Executenonquery ( String SQL, String Connectionstring)
{
Using (Sqlconnection connection = New Sqlconnection (connectionstring ))
{
Connection. open ();
Sqlcommand cmd = New Sqlcommand (SQL, connection );
ReturnCmd. executenonquery ();
}
}
Public Object Executescalar ( String SQL, String Connectionstring)
{
Using (Sqlconnection connection = New Sqlconnection (connectionstring ))
{
Connection. open ();
Sqlcommand cmd = New Sqlcommand (SQL, connection );
ReturnCmd. executescalar ();
}
}
5. modify configuration information
Code
Public Void Saveconfig ( String Key, String Value)
{
Try
{
String Filename = " Web. config " ;
Xmldocument document = New Xmldocument ();
Document. Load (filename );
(Xmlelement) document. selectsinglenode ( @" // Deleetting/Add [@ key =' " + Key + " '] " ). Setattribute ( " Value " , Value );
Document. Save (filename );
}
Catch (Exception ex)
{
Throw New Exception (ex. Message );
}
}