[★] C # enterprise-level development case:

Source: Internet
Author: User
Tags sql injection attack sql injection attack example

C # enterprise-level development:

1. display the login form
DisplayCodeLocated in mainform_load, the load event processing function of the main form. This event is triggered before the form is displayed and is usually used to allocate resources used by the form and other tasks ..

2. Internationalization
To enable Windows Forms to support internationalization, set the localizable attribute of the form to true. The localizable attribute is set to generate an XML-based resource file for the form.

3. Access Level of controls in the form
By default, private is set to internal, indicating the entireProgramSet files are visible

4. Remember the password
Save the password to the Registry, write it to the registry, and read the registry.

5. Save the error record to the Windows System Log
EventLog. writeentry

6. When you need to wait, the mouse status will change.
Base. cursor = cursors. waitcursor;

7. Excel everywhere
The main file excel.exe is a COM component in the. Excel system. You can control the EXCEL function by referencing the excel.exe file in the. NET project.

The interaction with COM components is achieved through the use of Wrapper class and proxy-like mechanisms.
The packaging class allows the. Net program to identify the interfaces provided by the COM component, while the proxy class side provides access to the COM interface.

Using system;
Using system. Collections. Generic;
Using system. text;
Using system. Data;
Using system. Data. sqlclient;
Using system. Windows. forms;
Using Microsoft. Office. InterOP. Excel;

Namespace csharpprj
{
Class excelexport
{
Private object _ optionvalue = system. reflection. Missing. value;

// If Excel is installed on a computer, export the table content to excel.
Public void exporttesks (Dataset ds, dataview DV, datagridview dgv)
{

// Define the application object, which indicates the entire EXCEL program
Microsoft. Office. InterOP. Excel. Application excelapp;

// Define the workbook object, which indicates the working thin
Microsoft. Office. InterOP. Excel. Workbook WB;

// Defines the worksheet object, which represents a worksheet in Excel
Microsoft. Office. InterOP. Excel. worksheet ws;

// Defines the range object, which represents the cell area.
Microsoft. Office. InterOP. Excel. Range R;

Int ROW = 1;
Int cell = 1;
Int priorityheight, prioritynoraml, prioritylow;

Try
{
// Initialize the Application Object excelapp
Excelapp = new Microsoft. Office. InterOP. Excel. Application ();
// Create a task list on a worksheet in the workbook
WB = excelapp. workbooks. Add (xlwbatemplate. xlwbatworksheet );

// Reference the first column of the First row

Ws = (worksheet) WB. worksheets [1];
}< br>
catch (exception ex)
{< br> throw ex;
}< br> // name the worksheet "task managere"
ws. name = "task management";

// Set the value of the cell in the first column of the First row
WS. cells [row, 1] = "tasks as of" + system. datetime. Now. tow.datestring ();

// Reference the cells in the first column of the First row and convert them to the range type

R = (range) WS. cells [row, 1];

// Set the cell font to black
R. Font. Bold = true;

// Traverse all columns in the data table ...........
// Create a row and output the data to the corresponding Excel cell...

}
}
}

====================

C # enterprise-level development

1. The server is responsible for the database and intermediate layer components, the middle layer for data access and transaction processing, and the client is responsible for user interface interaction with users.

2: Web services include Authentication Web services and data web services. Offline services read data from local offline files.

3: Third-Party free controls

4. asynchronous web service calls improve the overall performance and scalability of the system.
Asynchronous web service calls allow threads that call methods to execute other code when returning the thread pool. In this way, one more thread can be executed in a thread pool with a limited number of threads, this improves the overall system performance.

5. Stored Procedure
Fast execution speed
Reduces network traffic
Can be modified in the centralized location without re-compiling the application
Prevents SQL insert attacks.

6. Save the error record to the Windows System Log
Public class logerror
{
Private const string c_eventsource = "love ";
Private const string c_logname = "application ";

Public static void write (string errormessage)
{
Try
{
// Determine whether the event source named "love" exists
If (! EventLog. sourceexists (c_eventsource ))
{
// Try to create an object if it does not exist
EventLog. createeventsource (c_eventsource, c_logname );
}
// Already exists. Write the error message to the log
EventLog MSG = new EventLog (c_logname );
MSG. Source = c_eventsource;
MSG. writeentry (errormessage, eventlogentrytype. Error );
}
Catch
{}
}
}
7. Obtain the username and password included in the Windows Registry
Registrykey regkey = registry. currentuser. opensubkey ("c_registerkey ");
If (regkey! = NULL)
{
// Obtain the key that is saved in the registry. It is not empty.
Username = (string) regkey. getvalue ("username ");
// The password stored in the registry must be encrypted.
Password = (string) regkey. getvalue ("password ");

// Close the opened registry key
Regkey. Close ();
}
8.
Registrykey regkey = registry. currentuser. createsubkey ("c_registrykey ");
If (checkbox1.checked)
{
Regkey. setvalue ("username", txtusername. Text. Trim ());
Regkey. setvalue ("password", txtpasswrod. Text. Trim ());
}
Else
{
Regkey. deletevalue ("username", false );
Regkey. deletevalue ("password", false );
}
Regkey. Close ();

9. Net also has specialized classes responsible for the encryption service. These classes are all in the system. Security naming control.

10. The web service does not belong to the. NET Framework. It is a cross-platform distributed technology supported by multiple parties.

11. Obtain encrypted tickets in the Authentication Web Service
String userid = 0; // query the corresponding id value in the database table based on the user name and password

// Create a user ticket
Formsauthenticationticket ticket = new formsauthenticationticket (userid, false, 1 );
// Encrypt the User Ticket
String encryptedticket = formsauthentication. Encrypt (ticket );

// Obtain the encrypted ticket timeout time
Appsettingsreader configurationappsettings = new appsettingsreader ();

Int timeout = (INT) configurationreceivetask. getvalue ("authenticationticket. Timeout", typeof (INT ));

// Cache the encrypted ticket
Context. cache. insert (encryptedticket, userid, null, datetime. Now. addminutes (timeout), timespan. Zero );

// If the ticket is successfully returned
Return encryptedticket;

12. the sqlhelper class is a sealed class contained in Microsoft Data Application blocks. It simplifies the database access encoding and provides high speed. this function encapsulates ADO. the SQL Server operation class in. Net does not need to define the relevant properties of parameters, and you do not need to open the database connection in advance.
The executesaclar function automatically opens the database connection when the database connection is not enabled.

13 SQL Injection Attack example select * from Admin where username = '@ username' and Password =' @ passwrod ';
If you enter 1' or '1' = '1 In the first text box, enter the second text box .. returns corresponding results. this is an SQL injection attack. to avoid SQL injection attacks, the solution can be solved in 2. One is to filter all illegal characters and strings, such as single quotes, double quotation marks, semicolons, commas, colons, and Connection Numbers, the strings include "Net user" and "net localgroup Administrators" to convert or filter them. however, this method has many limitations. If the input value contains these characters, it cannot be entered. the second method is to use parameters. The SQL parameter transmission method will prevent attacks by using single quotes and hyphens. and allow all illegal characters and strings in the previous method to be entered.

 

 

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.