Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
CSharp_Prog_Guide.doc
Скачиваний:
16
Добавлен:
16.11.2019
Размер:
6.22 Mб
Скачать

Выполнение

Для запуска программы введите имя EXE-файла и два числа, как показано далее.

TestCode 1234 5678

Результат

------

Компиляция кода

Чтобы построить файл MathLibrary.DLL, скомпилируйте два файла Add.cs и Mult.cs при помощи следующей сроки команд:

csc /target:library /out:MathLibrary.DLL Add.cs Mult.cs

Параметр компилятора /target:library указывает компилятору создавать библиотеку DLL, вместо файла EXE. Параметр компилятора /out с именем файла используется для указания имени DLL-файла. В противном случае, компилятор использует первый файл (Add.cs) в качестве имени библиотеки DLL.

Для построения исполняемого файла TestCode.exe служит следующая строка команд:

csc /out:TestCode.exe /reference:MathLibrary.DLL TestCode.cs

Параметр компилятора /out указывает компилятору создавать EXE-файл и задает имя выходного файла (TestCode.exe). Этот параметр компилятора является необязательным. Параметр компилятора /reference указывает DLL-файл или файлы, используемые этой программой.

Security

Security is a necessary aspect of every C# application, and it must be considered at every phase of development, not only when design and implementation are completed.

C# Specific Security Recommendations

This list is not an exhaustive list of potential security problems. It highlights some common issues for C# developers.

  • Use the checked keyword to control the overflow-checking context for integral-type arithmetic operations and conversions.

  • Always use the most restrictive data type for parameters. For example, when you pass a value to a method that describes the size of a data structure, use unsigned integer rather than integer.

  • Do not make decisions based on file names. File names can be expressed in many different ways, and your test for a particular file may be bypassed.

  • Never, ever hardcode passwords or other sensitive information into your application.

  • Always validate input that is used to generate SQL queries.

  • Validate all inputs into your methods. The regular expression methods in the System.Text.RegularExpressions namespace are useful for confirming that input is of the correct form, such as an e-mail address.

  • Do not display exception information: it provides any would-be attacker with valuable clues.

  • Ensure that your application works while running with the least possible permissions. Few applications require that a user be logged in as an administrator.

  • Do not use your own encryption algorithms. Use the System.Security.Cryptography classes.

  • Give your assemblies strong names.

  • Do not store sensitive information in XML or other configuration files.

  • Check managed code that wraps native code carefully. Confirm that the native code is secure.

  • Use caution when you use delegates passed from outside your application.

  • Run the Visual Studio code analysis tool on your assemblies to ensure compliance with Microsoft .NET Framework Design Guidelines. This tool can also find and warn against over 200 code defects.

Безопасность

Безопасность является обязательным аспектом каждого приложения на языке C#, который должен учитываться на каждом этапе разработки, а не только после завершения разработки и реализации.