잊지 않겠습니다.

.NET Assembly

.NET Framework 2009. 1. 7. 10:59

Assembly의 배포

모든 Assembly는 전용(private)와 공유(shared)로 배포가 가능하다.

1. Private Assembly

  • 정확한 버젼 관리를 하지 않는다.
    • Private Assembly의 경우, 해당 client application에서만 사용하기 때문에
  • 응용 프로그램 디랙토리 내에서의 파일 검색으로 행하게 된다.(Probing)
  • 공개 key token이 정해지지 않는 것으로 Private Assembly를 구별하게 된다.

2. Shared Assembly

  • Shared Assembly도 역시 Private Assembly와 마찬가지로 여러개의 모듈 안에 포함된 형식과 리소스로 이루어진다.
  • "강력한 이름(Strong Name)"이 반드시 시정되어야지 된다.
  • \%windir%\Assembly 하위 디랙토리에 위치되고, 실행된다.

Assembly Data

web.config, app.config에 있는 데이터를 외부에서 얻어가는 방법을 찾는다.

object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
Assembly.GetExecutingAssembly().GetName().Version.ToString();
Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCompanyAttribute), false);


Assembly의 각각의 정보들을 얻어오고,  그 정보들을 Display 시켜주는 함수들 자신의 Assembly를 얻어오는 방법에 대해서 염두해둘것!

Posted by Y2K
,

ADO .NET

.NET Framework 2009. 1. 7. 10:58

ADO .NET에서의 데이터 검색

   1. 기존의 Key를 기반으로 Row를 받는다면 DataTable.Rows.Find를 사용
   2. 검색조건을 만족하는 행을 컨트롤에 바인드 시켜야지 된다면 DataView를 사용
         1. 가장 중요한 내용은 컨트롤에 바인드 되는 내용에 대한 고려
         2. 컨트롤에 바인드를 목적으로 가지고 있다면 DataView를 필수적으로 이용
         3. 키열이 아닌 열의 조합에 대해서 반복적인 검색을 수행할것이라면 DataView.Find를 이용
         4. 그 외의 모든 경우, DataTable.Select 사용

DataSet에서의 데이터의 검색은 DataTable 이나 SELECT 구문에서의 값의 리턴을 통해서 얻어올수 있다.

그러나, Off_Line 데이터를 원칙으로 가지고 있으며, 매번 데이터의 검색시마다 Query문을 넘기게 되는 것은 DB Server에 매우 큰 부하를 가지고 오게 된다. 따라서, Off_Line으로 데이터를 가지고 온 후에, 데이터를 검색, 수정, 추가 후 최종적으로 업데이트 시키는 것이 보다 더 나은 데이터 이용 이라고 할 수 있다.[물론 대부분의 경우, 어떠한 특정한 경우에서는 맞지 않는 말이라고 할 수 있다.

.NET Framework에서의 데이터 검색과 필터링 방법은 다음과 같다.
1. DataTable 상에서의 객체의 검색과 필터링 기능 이용
2. DataView를 이용

* DataView를 이용하는 이유
1) DataView의 주요 기능은 Windows Form과Web Form 모두에서 데이터를 바인딩할 수 있도록 허용
2) 검색의 자유로운 변화[DataTable의 경우에는 Primary Key로만 검색이 가능하다]


CommandBuilder

사용자가 입력하는 텍스트 명령을 사용하는 쿼리 도구를 통해서와 같이 SelectCommand가 런타임에 동적으로 지정되는 경우에는 디자인 타임에 적절한 InsertCommand, UpdateCommand 또는 DeleteCommand를 지정할 수 없습니다. DataTable이 단일 데이터베이스 테이블에 매핑되거나 단일 데이터베이스 테이블에서 생성되면 CommandBuilder 개체를 사용하여 DataAdapter의 DeleteCommand, InsertCommand 및 UpdateCommand를 자동으로 생성할 수 있습니다.

자동 명령 생성이 작동하도록 하려면 최소한 SelectCommand 속성은 설정해야 합니다. SelectCommand에서 검색하는 테이블 스키마에 따라 자동 생성되는 INSERT, UPDATE 및 DELETE 문의 구문이 결정됩니다.

CommandBuilder 는 삽입, 업데이트 및 삭제 명령을 생성하는 데 필요한 메타데이터를 반환하기 위해 SelectCommand를 실행해야 합니다. 결과적으로 데이터 소스에 추가로 이동해야 하므로 성능이 떨어질 수 있습니다. 최적의 성능을 얻으려면 CommandBuilder를 사용하는 대신 명령을 명시적으로 지정합니다.

SelectCommand는 또한 기본 키 열이나 고유 열을 적어도 하나는 반환해야 합니다. 이러한 열이 없으면 InvalidOperation 예외가 생성되고 명령이 생성되지 않습니다.

CommandBuilder 는 DataAdapter와 연결될 때 DataAdapter의 InsertCommand, UpdateCommand 및 DeleteCommand 속성이 null 참조인 경우 자동으로 이러한 속성을 생성합니다. 속성에 대한 Command가 이미 있으면 기존 Command가 사용됩니다.

테이블을 두 개 이상 조인하여 만든 데이터베이스 뷰는 단일 데이터베이스 테이블로 간주되지 않습니다. 이 경우 CommandBuilder를 사용하여 명령을 자동으로 생성할 수 없으므로 사용자가 명령을 명시적으로 지정해야 합니다. DataSet에 대한 업데이트를 다시 데이터 소스에 적용하기 위한 명령을 명시적으로 설정하는 것에 대한 자세한 내용은 DataAdapter 및 DataSet을 사용하여 데이터베이스 업데이트를 참조하십시오.

출 력 매개 변수를 다시 DataSet의 업데이트된 행에 매핑하려는 경우도 있습니다. 자동 생성된 ID 필드의 값이나 타임스탬프를 데이터 소스에서 검색하는 작업은 일반적인 작업입니다. CommandBuilder는 기본적으로 출력 매개 변수를 업데이트된 행의 열에 매핑하지 않습니다. 이 경우 사용자가 명시적으로 명령을 지정해야 합니다. 자동 생성되는 ID 필드를 삽입된 행의 열에 다시 매핑하는 예제는 Identity 또는 Autonumber 값 검색을 참조하십시오.


 SQL Query를 자동으로 생성해주는 Class..

그런데, Query를 생성하기 위해서 다시 DB를 Access한다는 것이 좀 애매하다는 생각이 든다.


DataTable에서의 Data 검색

  1. 기존의 Key를 기반으로 Row를 받는다면 DataTable.Rows.Find를 사용
  2. 검색조건을 만족하는 행을 컨트롤에 바인드 시켜야지 된다면 DataView를 사용
  • 가장 중요한 내용은 컨트롤에 바인드 되는 내용에 대한 고려
  • 컨트롤에 바인드를 목적으로 가지고 있다면 DataView를 필수적으로 이용
  • 키열이 아닌 열의 조합에 대해서 반복적인 검색을 수행할것이라면 DataView.Find를 이용
  • 그 외의 모든 경우, DataTable.Select 사용

DataView에서의 Data 검색

 DataSet에서의 데이터의 검색은 DataTable 이나 SELECT 구문에서의 값의 리턴을 통해서
얻어올수 있다.

그러나, Off_Line 데이터를 원칙으로 가지고 있으며, 매번 데이터의 검색시마다 Query문을
넘기게 되는 것은 DB Server에 매우 큰 부하를 가지고 오게 된다. 따라서, Off_Line으로 데이터를
가지고 온 후에, 데이터를 검색, 수정, 추가 후 최종적으로 업데이트 시키는 것이 보다 더 나은
데이터 이용 이라고 할 수 있다.[물론 대부분의 경우, 어떠한 특정한 경우에서는 맞지 않는 말이라고
할 수 있다.]

.NET Framework에서의 데이터 검색과 필터링 방법은 다음과 같다.
1. DataTable 상에서의 객체의 검색과 필터링 기능 이용
2. DataView를 이용

* DataView를 이용하는 이유
1) DataView의 주요 기능은 Windows Form과Web Form 모두에서 데이터를 바인딩할 수 있도록 허용
2) 검색의 자유로운 변화[DataTable의 경우에는 Primary Key로만 검색이 가능하다]

Posted by Y2K
,

Access Permissions for Web Applications

Like any applications, Web applications need access to various system resources, such as files or databases. These resources are usually protected by access levels granted to different users and groups.

In a Web application, it might not be the application user who is requesting access directly. Instead, the user communicates to the Web application using a browser, and the Web application then requests the resource. This indirect access can introduce an issue of access permission.

There are several strategies for managing access permissions in a Web application. The sections below provide an overview of each option. Links in the topic will point you to topics that contain more information.

Access through Windows Integrated Security

If your Web application runs in an intranet environment — if all users will be running Windows and are behind the same firewall — the application can access resources using Windows integrated security. In this strategy, all users are authenticated as soon as they log on to Windows. The authentication process generates a token containing information for that user. (The token does not contain the user's credentials, only a code indicating that the user has been authenticated.) The Web application can use the token when requesting a local resource. For example, a logged-in user requests a Web Forms page in Internet Explorer. The request is passed to Internet Information Services (IIS) and then to ASP.NET, which can use the user's authentication token to request access to a file on the server computer.

Windows integrated security is generally the most secure option for Web access permissions. If it is practical in your application, you should configure the application to use this option.

For details, see ASP.NET Authentication.

Anonymous Access Using the ASP.NET User Account

In most applications, users typically access Web applications anonymously — that is, they do not initially provide authentication credentials. In that case, the Web application has to assume (impersonate) some identity that it can use to request resources.

By default, when ASP.NET allows anonymous access, the application runs in the context of a special local (not domain) account. The user context depends on the operating system. In Windows 2000 and Windows XP, applications run under the account called ASPNET. In Windows Server 2003, the user context is called NETWORK SERVICE. These user accounts are created during the .NET Framework installation process with a unique, strong password, and are granted only limited permissions. The ASPNET or NETWORK SERVICE user can access only specific folders that are required to run a Web application, such as the \bin directory in which a Web application stores compiled files.

Note   IIS has a similar mechanism for mapping anonymous users to a specific local or domain user. You can use the IIS facility to remap anonymous access for all files in your application, not just ASP.NET files (Web Forms pages and controls). For details, see Microsoft Internet Information Server Security Overview.

If your Web application requires access to other resources on the Web server computer, you can grant permissions to the ASPNET or NETWORK SERVICE user as needed. For example, if the application needs to write a file to a directory, you will need to explicitly grant write permissions to the ASPNET or NETWORK SERVICE account in that directory.

Alternatively, you can specify a different user identity for ASP.NET to use when requesting resources. You can specify a user name (a local or domain user) in whose name requests are made. For details, see ASP.NET Process Identity. For details, see <processModel> Element. Or you can specify that ASP.NET instead run in a system (administrator) context.

Caution   Running ASP.NET applications in the system context allows them to run with administration permissions on the server. If users can take control of your application, they will then have free access to many critical resources on the server.

There are some resources that you cannot by default access using the default user context, because they require access to resources that need administrative-level privileges. For example, if your application needs to create a new event log category using methods in the System.Diagnostics namespace, it cannot do so if it is running in the context of the ASPNET or NETWORK SERVICE user. In that case, you need to either change the application context or make changes that will make the event log accessible to the ASP.NET user account.

Caution   Setting the process identity to a specific user name in place of the ASPNET or NETWORK SERVICE user identity requires that you provide a user name and a password that are both stored in the machine.config file. Storing any credential information can represent a security threat, because if someone manages to get access to the machine.config or if they gain administrator privileges on the Web server computer, they might be able to read or change this private information. Make the machine.config file read-only for all but administrative users. For details about setting the username and password in the machine.config file, see <processModel> Element.

Access Using Provided Credentials

Your Web application can also request resources by providing credentials at run time. This is not possible to all resources, but can work for resources that accept a username and password, such as databases that accept a connection string.

Security Note   Accessing SQL Server using a connection string (known as "mixed mode") is less secure than using Windows integrated security. If the Web server and SQL server are running on the same computer, you can easily and securely use Windows integrated security.

You can get the credentials from the user directly, using Basic, Digest, or Forms authentication. For example, your application might prompt the user to supply a username and password when the user wants to access a restricted part of your site. For details about authentication, see IIS Authentication and ASP.NET Authentication.

Security Note   Prompting the user for a username and password in your application is a potential security threat. Credential information must be transferred from the browser to your server, and ordinary HTTP transfers are unencrypted. For best security when prompting users to provide credentials in your application, you should use secure sockets layer (SSL), which encrypts information before sending it from the browser to the server. For details, see Using Secure Sockets Layer.

After getting credentials from a user, you can pass them on when requesting the resource. For databases, you can usually plug the username and password into a connection string when opening a connection. For other resources, you can call a Windows API called LogonUser that establishes a user context for the information you provide and uses it to request access to a resource.

Sometimes it is more convenient to store credentials directly with your application. For example, it is possible to create a database connection string that hard-codes a user name and password into it. For details, see Accessing SQL Server with Explicit Credentials.

Security Note   Hard-coding credentials into an application is generally not advised, because the information can be read, even if it has been compiled. Even if you do hard-code any user credential information into an application, you should never use a user name that would give a user anything but the most minimal access privileges to a resource.

If you do choose to store credentials as part of an application, you should make an attempt to protect them. One possibility is to use the Data Protection API (DPAPI). For details, see the technical article Windows Data Protection on MSDN Online (http://msdn.microsoft.com/library/de...asp?frame=true).

Accessing Remote Resources (Delegation)

Sometimes the resource required by your application is on a computer other than the Web server. This is recommended for some resources, such as a database. In that case, the application must make a request to the remote computer on behalf of the user. This process is called delegation.

As with any request for resources, a request to a remote computer must include appropriate credentials. If your application allows anonymous access, IIS and ASP.NET do not have the user's credentials and therefore cannot use them during delegation to access remote resources. In that case, you can:

  • Get explicit user credentials by prompting for them. The application can then pass these on to the remote computer as needed. If you are working with a SQL Server, you can add the user credentials to a connection string. For an example, see Accessing SQL Server with Explicit Credentials.
  • Change the user context of the Web application from the ASPNET or NETWORK SERVICE user to a specific domain user whose credentials can be passed to the remote computer. For an example, see Accessing SQL Server Using a Mapped Windows Domain User.

Note   If you are running the browser and Web server on the same computer and you are logged on as a domain user, delegation to a remote computer is not a problem, since the IIS computer has your credentials. Although this is a common testing scenario, it is a very rare production scenario. If possible, always test access permissions by running the browser and Web server on separate computers.

Posted by Y2K
,