Monday, October 30, 2006

ASP.NET and IIS security

d Windows authentication is used together with IIS authentication. When IIS authentication is complete, ASP.NET uses the authenticated identitiy to authorize access.

d In a Windows-based authentication model, the requests go directly to IIS to provide the authentication process. IIS first takes the user's credentials from the domain login. If this process fails, IIS desplays a pop-up dialog box so the user can enter his login information.

d Windows authenticaton is quite uesful in an intranet environment where you can let the server deal completely with the authentication process, especially in environments where users are already logged onto a network.

Dealing with IO in ASP.NET envirenment

d When your code is excuted by IIS, it executes under the context of ASP.NET Worker Process user account (ASP.NET) , therefore, your application may be restricted by that account's security rights.

d By deafult, the ASP.NET Worker Process does not have rights to write to the local disk.

^ What the ASP.NET Worker Process is allowed to do inside of the IO namespace?

Directory V.S. DirectoryInfo

d Someone said: Directory is a static class, while DirectoryInfo can be instantiated. Basically, both work the same.

d The Directory class exposes static methods you can use to create, move, and delete directories. The DirectoryInfo represents a specific directory and lets you perform many of the same actions as the Directory class on the specific directory. Additionally, it enumerates child directoreis and files.

Copying files and directories in .NET

Thursday, October 26, 2006

Using CheckBoxList in ASP.NET

e .NET Framework Class Library CheckBoxList Members

Tuesday, October 24, 2006

My Naming Conventions in .NET

^ 我想尽量兼顾VB.NET和C#。

^ Field/Class Variable: Pascal Case。Always indicate Private, do not use Dim.

^ Property: Pascal Case。

^ Parameter: Camel Case。在method body中,定义一个Local Variable,采用Pascal Case命名,除了首字母其他完全一致,然后把parameter赋值给相应的Local Variable。

^ Property和Method是给“外人”看的,命名要“好看”,所以就要规规矩矩地Pascal Case。Field是自己用的,所以命名可以有点儿“特色”。

d Field: Camel Case with Leading Underscore. In VB.NET, always indicate "Protected" or "Private", do not use "Dim".
Of all the items here, the leading underscore is really the only controversial one. I personally prefer it over straight underscore-less camel case for my private variables so that I don't have to qualify variable names with "this." to distinguish from parameters in constructors or elsewhere where I likely will have a naming collision. With VB.NET's case insensitivity, this is even more important as your accessor properties will usually have the same name as your private member variables except for the underscore.


d Properties: Pascal Case, no underscores. Try to avoid abbreviations. Members must differ by more than case to be usable from case-insensitive languages like Visual Basic .NET.
VB: Public Property RecordID As Integer
C#: public int RecordID

d Parameters: Camel Case. Try to avoid abbreviations. Parameters must differ by more than case to be usable from case-insensitive languages like Visual Basic .NET.
VB: ByRef recordID As Integer
C#: ref int recordID

d What are your thoughts on naming conventions that need to be used to distinguish the class variables, function local variables and method arguments?
d By class variables, I assume you mean fields. Those should be private (use properties for public exposure to provide a level of abstraction). For function locals, those are by definition private. For method arguments, those need to be camelCased. For the privates, I have seen two patterns in the .NET Framework: one is leading underscore, and the other is this.Foo. Either works for me.

d However, I then had to do some VB.NET development and the language isn't case sensitive. I've seen some examples that add a "Field" suffix in VB.NET . I think that is worse than a leading "_". So I came full circle and started using "_" again. :)

e Designing .NET Class Libraries: Naming Conventions (January 26, 2005)
e .NET Programming Standards and Naming Conventions

Monday, October 23, 2006

The 1st wave of Microsoft ASP.NET AJAX Control to master

There are and will be many and many AJAX controls, some of them are the essentials and the mostly used. 主要是关于Panel的“基层”control,我称之为“Panel Group”吧。Thus, learn to use them in the first wave:

d UpdatePanel

这个是最基本的。专门研究吧。

d PopupControl
PopupControl is an ASP.NET AJAX extender that can be attached to any control in order to open a popup window that displays additional content.
This popup window will probably be interactive and will probably be within an ASP.NET AJAX UpdatePanel, so it will be able to perform complex server-based processing (including postbacks) without affecting the rest of the page.
The popup window can contain any content, including ASP.NET server controls, HTML elements, etc..
Once the work of the popup window is done, a simple server-side call dismisses it and triggers any relevant script on the client to run and update the page dynamically.
^ 这是个基本的control,也是比较原始意义的AJAX功能,用途比较广泛。比如填写某个TextBox的时候,可以探出一个小Panel用于选择日期,计算某些数等等。

d HoverMenu
HoverMenu is an ASP.NET AJAX extender that can be attached to any ASP.NET WebControl, and will associate that control with a popup panel to display additional content.
^ 我觉得HoverMenu这个名字起得不好,不如叫HoverPopupPanel。这种功能倒是会用得挺多,比如用于当鼠标滑到某个位置的时候,弹出一个圆角小方框显示文字。

d CollapsiblePanel
The CollapsiblePanel is a very flexible extender that allows you to easily add Collapsible sections to your web page. This extender targets any ASP.NET Panel control.
The page developer specifies which control(s) on the page should be the open/close controller for the panel, or the panel can be set to automatically expand and/or collapse when the mouse cursor moves in or out of it, respectively.

d Accordion
The Accordion is a web control that allows you to provide multiple panes and display them one at a time. It is like having several CollapsiblePanels where only one can be expanded at a time.
The Accordion is implemented as a web control that contains AccordionPane web controls. Each AccordionPane control has a template for its Header and its Content. We keep track of the selected pane so it stays visible across postbacks.

d DynamicPopulate
DynamicPopulate is a simple extender that replaces the contents of a control with the result of a web service or page method call. The method call returns a string of HTML that is inserted as the children of the target element.
^ 这应该最原始意义上的AJAX功能。

Using the UpdatePanel Control

e UpdatePanel Overview
e Using the UpdatePanel Control in ASP.NET AJAX Applications

Microsoft ASP.NET AJAX 1.0 Beta Just Released!

非常高兴Microsoft ASP.NET AJAX 1.0 Beta终于发布了。虽然此前基于Altas写了不少代码,我还是很愿意告别Prince Atlas,修改到新的ASP.NET AJAX上来。

我认为,AJAX虽然目前看来似乎是一种新技术,有一点独立性,但最终而且不久就会完全融合进ASP.NET中,成为ASP.NET 3.0,的基本属性。我们不会再特意安装AJAX包,也不需要在aspx文件中特别声明什么,因为它已经是ASP.NET的native and default features。在开发中使用AJAX feature,我们也不会看到很特殊的AJAX的标签,因为提供AJAX功能的标签都会统一在asp下。

其实,在目前的ASP.NET 2.0中,我们就已经能够看到一些默认的AJAX feature了。比如GridView中的sorting,paging等feature。而且会在ASP.NET页面的Page命令中找到一个叫Async的attribute,这就是用来启动Asyncronous功能的。

在未来的版本(ASP.NET 3.0)中,我预计AJAX相关的功能和feature会被统一规划,完全融合进ASP.NET的血液中,消失得无影踪。你将不再能找到AJAX,你只会看到被注入新的血液的ASP.NET。

我非常喜欢Microsoft ASP.NET AJAX的另一个原因是其使用方式。不像Ruby on Rails那样需要在RHTML中写很多看起来有些奇怪的代码,也不需要像Google Web Toolkit那些通过写Java代码来获得AJAX功能。在Microsoft ASP.NET AJAX中,我们只需要通过写标签的方式通过Server Control来实现出色的AJAX功能。也就是通过Declarative Programming的方式来快速地实现AJAX,就如同使用普通的ASP.NET Server Control一样。当然,这个问题实质上是关于Declarative Programming和Imperetive Programming两种开发流派孰优何优。

总之,对于使用过Ruby on Rails,Google Web Toolkit和Microsoft ASP.NET AJAX的我来说,我更喜欢Microsoft ASP.NET AJAX,因为它符合我对Declarative Programming的倾向性以及我对productivity(高生产效率)的强烈需求。

Sunday, October 22, 2006

Using unmanaged code

^ What is Interoperation for?
There might be many lines of legacy code left for companies. If they had to rewrite and retest thiese codes prior to launching any new application developed in .NET, they would have never made the switch. Using an "all or nothing" approach with migrating to .NET is simply too expensive and time consuming for many companies with investments in legacy code.
By taking advantage of Interoperation, they are able to migrate their existing applications little by little, in a manner that was virtually transparent to clients. Were it not for Interoperation, they would have never made the migration.


^ Prior to advent of the .NET Framework, the COM Framework was the primary framework for developers to interact with the Windows operating system.

d The mechanism that serves as proxy so that the .NET runtime can communicate with a COM component is known as a Runtime Callable Wrapper (RCW), which handles the majority of the work between .NET and COM for you, including marshaling data types, handling events, and handling interfaces.

d Unlike pure .NET components, COM components must be registered before they can be used.
d Every COM components must have an entry in the Windows registry.

d After importing it, using an object contained in a given COM library is virtually identical to using ne created purely in .NET.

d What is Platform Invoke? and when to use it?

d Use Platform Invoke through the System.Runtime.InteropServices namespace:


  1. Create a static/shared external method with the name of the function you want to call.
  2. Decorate it with the DllImport attribute specifying the library that it should call.
  3. Call the method from your code.

Imports System.Runtime.InteropServices
Public Class InterExample


Private Shared Function GetForeWindow() As IntPtr
End Function

Public Shared Sub GetScreenDemo()
Dim DemoHandle = GetForeWindow()
End Sub

End Class
d Encapsulating DLL Functions: Because Platform Invoke calls is not elegant, it's often beneficial to create a class that exposes them and wraps this functionality. After all, much of the .NET Framework is composed of precisely this methodology.
@ You need to call an unmanaged function from your managed code by using Platform Invoke services. What should you do?
Create a class to hold DLL functions and then create prototype methods by using managed code.
 

StringBuilder V.S. String

Saturday, October 21, 2006

Code Access Security

CAS

@ When you run an unmanaged application in Windows 2003, XP or earlier, that code gets all the privileges your user account has. The application can do anything your user account has permissionos to do. so you are forced to log on with minimal privileges to restrict application permissions.

@ Code Access Security (CAS), a concept that .NET Framework introducted into Windows, enables users to restrict on a very granular level what managed application can do.

@ CAS allows administrators and developers to control applicatoin authorization similar to the way they have always been albe to authorize users.

@ Unfortunately, CAS can be applied only to managed applications that use the .NET Framework runtime. Unmanaged applications run without any CAS restrictions and are limited only by the operating system's RBS.

^ ASP.NET中的Membership和Role Management是对“人”(people, user)的权限管理(authentication和authorization);而CAS则是对“程序”(application,code)进行权限管理。

Evidence

@ Generally, a security system use the username, password, access control lists to identify users and determine what a user can and can't do. However, CAS identifies and assigns permissions to applications ratha than to people, thus, it identifies assembilies using evdience.
@ In CAS, evidence is used just like a person's passport, password, and PIN - information that proves identity and describes an individual as deserving a certain level of trust.

@ Each piece of evidence is a way that an assembly can be identified, such as the location (folder or website) where the assembly is stored and running, a hash of the assembly's code, or the assembly's digital signature.

@ There are 2 types of evidence: host evidence and assembly evidence:

  1. Host evidence describes the assembly's origin, such as the application directory, URL, or site; and also describes the assembly's identity, such as the hash, pulisher, or strong name.
  2. Assembly evidence are ones provided by custom user or developer.

^ I think evidence is the Authentication part of the security process for application or code, just like username and password are the Authentication for people or users.

Permission

@ A permission is a CAS access control entry.

^ A permission set is a CAS ACL (Access Control List).

Friday, October 20, 2006

What the fuck Callback is on earth? Define it!

To synchronize thread pool threads

@ Queue your task for execution by passing the WaitCallback delegate to ThreadPool.QueueUserWorkItem. Your callback method executes when a thread pool thread becomes available.

@ In many cases, creating your own thread is not necessary or suggested.
The threading system in .NET supports a built-in thread pool that can be used in many situations where you might expect to create your own threads.


e The Managed Thread Pool

Cleaning Up Unmanaged Resources

What you should NOT do in cleaning up unmanaged resoures!

  1. You should prevent users of your application from calling an object's Finalize method directly by limiting its scope to protected.
  2. You are strongly discouraged from calling a Finalize method for a class other than your base class directly from your application's code.

How to properly clean up unmanaged resources?

@ To properly dispose of unmanaged resources, it is recommended that you implement a public Dispose or Close method that executes the necessary cleanup code for the object.

@ The IDisposable interface provides the Dispose method for resource classes that implement the interface. Because it is public, users of your application can call the Dispose method directly to free memory used by unmanaged resources.
@ When you properly implement a Dispose method, the Finalize method becomes a safeguard to clean up resources in the event that the Dispose method is not called.

@ The IDisposable Interface defines a method to release allocated unmanaged resources.

Why do we need IDisposable?
  1. The garbage collector automatically releases the memory allocated to a managed object when that object is no longer used, however, it is not possible to predict when garbage collection will occur.
  2. Furthermore, the garbage collector has no knowledge of unmanaged resources such as window handles, or open files and streams.

@ Thus, we should use the Dispose method of this interface to explicitly release unmanaged resources in conjunction with the garbage collector.

@ The consumer of an object can call this method when the object is no longer needed.

@ When calling a class that implements the IDisposable interface, use the try-finally pattern to make sure that unmanaged resources are disposed of even if an exception interrupts your application.

@ Destructors are used to destruct instances of classes.

Using Destructors to Release Resources

@ In general, C# does not require as much memory management as is needed when developing with a language that does not target a runtime with garbage collection. This is because the .NET Framework garbage collector implicitly manages the allocation and release of memory for your objects.
When your application encapsulates unmanaged resources such as windows, files, and network connections, you should use destructors to free those resources. When the object is eligible for destruction, the garbage collector runs the object's Finalize method.

@ A class can only have one destructor.
@ Destructors cannot be inherited or overloaded.
@ Destructors cannot be called. They are invoked automatically.
@ A destructor does not take modifiers or have parameters.
@ Destructors cannot be defined in structs. They are only used with classes.

@ The programmer has no control over when the destructor is called because this is determined by the garbage collector.
The garbage collector checks for objects that are no longer being used by the application. If it considers an object eligible for destruction, it calls the destructor (if any) and reclaims the memory used to store the object.
Destructors are also called when the program exits.

e Implementing a Dispose Method

e Garbage Collection

e Cleaning Up Unmanaged Resources

Using MemberInfo of System.Reflection

@ You need to ascertain wheter a method named OneMethod is accessible to a derived class. What shoud you do?
^ Call the IsFamily property of the MethodInfo Class.

@ The IsFamily property gets a value indicating whether the visibility of this method or constructor is described by MethodAttributes.Family; that is, the method or constructor is visible only within its class and derived classes. (Inherited from MethodBase.)
^ Family Indicates that the method is accessible only to members of this class and its derived classes.

^ The MethodAttribute enumeration also contains:
Abstract Indicates that the class does not provide an implementation of this method.
Assembly Indicates that the method is accessible to any class of this assembly.
Final Indicates that the method cannot be overridden.
Private Indicates that the method is accessible only to the current class.
Virtual Indicates that the method is virtual
Static Indicates that the method is defined on the type; otherwise, it is defined per instance.

e You can read more about MethodAttributes's member here.

e About MethodInfo class

Thursday, October 19, 2006

Reflecting types

The Type class有什么用?

@ The Type class represents a single type, allowing you to look at the methods, properties, events, interfaces, and inheritance tree of a particular type in the system.

How to get the Type object?

@ You can get Type object in 4 ways:

  1. From the Assembly class
  2. From the Module class
  3. From the instance of an object
  4. Using keyword typeof in C# or GetType in VB.

@ 1st way: from the Assembly class:

Dim OneAssembly As Assembly = Assembly.GetExecutingAssembly()
Dim AssemblyTypes() As Type = OneAssembly.GetTypes()

@ 2nd way: from the Module class:

Dim AllModulesOfOneAssembly As [Module] = OneAssembly.GetModules()
Dim OneModuleOfOneAssembly As [Module] = AllModulesOfOneAssembly(0)
Dim AllTypesOfOneModuleOfOneAssembly () As Type = OneModuleOfOneAssembly .GetTypes()

@ 3rd way: get the type of the instance of an object by calling its GetType method:

Dim OneObject As New Object()
Dim TypeOfOneObject As Type = OneObject.GetType()

@ 4th way: create a Type object using C# typeof / VB GetType keywork:

Dim OneSpecificType As Type = GetType(Int32) 'VB

Type OneSpecificType = typeof(Int32) //C#

ASP.NET comment syntax, sever-side and client-side

<%-- content to comment --%>

@ Server-side comments allow developers to embed code comments in any part of an ASP.NET application file (except for within script code blocks).

@ Any content between opening and closing tags of server-side comment elements, whether ASP.NET code or literal text, will not be processed on the server or rendered to the resulting page.

@ A compilation error will occur if you use server-side comment blocks within <% %>blocks.

@ Server-side comment blocks cannot be nested.

Tuesday, October 17, 2006

The Literal control of ASP.NET 2.0

@ Add a Literal Web server control to your page when you want to set text programmatically without adding extra HTML tags. The Literal control is useful as a way to add text into a page dynamically without adding any elements that are not part of the dynamic text. For example, you can use the Literal control to display HTML that you read from a file or from a stream.

@ If you want to display static text, you can present it using HTML; you do not need a Literal control. Use a Literal control only if you need to render text programmatically.

@ You can use a Literal Web server control as a container for other content on the page. The Literal control is used most frequently when adding content dynamically to the page.

Comparing the Literal Control to Other Options
The Literal control represents one of several options for adding content to a page. For static content, you can add markup directly to a page as HTML, without using a container. However, if you want to add content dynamically, you must add the content to a container. Typical containers are the Label control, the Literal control, the Panel control, and the Placeholder control.
The Literal control differs from the Label control in that the Literal control does not add any HTML elements to the text. (The Label control renders a span element.) As a consequence, the Literal control does not support any style attributes, including position attributes. However, the Literal control allows you to specify whether content is encoded.
The Panel and Placeholder controls render as div elements, which create discrete blocks in the page, unlike rendering in-line the way the Label and Literal controls do.
In general, use a Literal control when you want to render text and controls directly into a page without any additional markup.

ASP.NET intergration with IIS7

e ASP.NET Integration with IIS7 Written by Mike Volodarsky

ASP.NET Enhancements on IIS7

Better ASP.NET integration in IIS7 both enhances existing applications, and allows new applications to take advantage of ASP.NET features in new ways:

  • ASP.NET services can be used for all content types.
    In the past, ASP.NET functionality such as Forms Authentication, Roles, Url Authorization, and Output Caching were only available to ASP.NET content types (ASPX pages, for example). Static files, ASP pages, and other content types could not benefit from these services.
    In IIS7, all ASP.NET services can be provided uniformly to all content. For example, you can protect all of your web content, including images and asp pages, with your existing ASP.NET 2.0 access control solution built on ASP.NET Forms Authentication, Membership and Login controls.
  • Fully extend IIS with ASP.NET.
    Previous versions of IIS frequently required server extensibility to be developed using the native ISAPI filter or extension extensibility mode, due to the runtime limitations of ASP.NET.
    IIS7 allows ASP.NET modules to plug in directly into the server pipeline, with the same runtime fidelity as modules developed with the native (C++) server API. ASP.NET modules can execute in all runtime stages of the request processing pipeline, and be executed in any order with respect to native modules. The ASP.NET API has also been expanded to allow more control over request processing then was previously possible.
  • Unified server runtime.
    Tighter ASP.NET integration also allows many of the features between IIS and ASP.NET to be unified. IIS7 features unified configuration for IIS and ASP.NET modules and handlers. Many other features, including custom errors, and tracing, have been unified to allow better management and cohesive application design.

ASP.NET Integration Architecture

In IIS7, the ASP.NET request processing pipeline overlays the IIS pipeline directly, essentially providing a wrapper over it instead of plugging into it.

A request arriving for any content type is processed by IIS, with both native IIS modules and ASP.NET modules being able to provide request processing in all stages. This enables services provided by ASP.NET modules like Forms Authentication or Output Cache to be used for requests to ASP pages, PHP pages, static files, and so on.

The ability to plug in directly into the server pipeline allows ASP.NET modules to replace, run before, or run after any IIS functionality. This enables, for example, a custom ASP.NET basic authentication module written to use the Membership service and SQL Server user database to replace the built in IIS basic authentication feature that works only with Windows accounts.

In addition, the expanded ASP.NET APIs take advantage of direct integration to enable more request processing tasks. For example, ASP.NET modules can modify request headers before other components process the request, inserting an Accept-Language header before ASP applications execute in order to force localized content to be sent back to the client based on user preference.

Because of the runtime integration, IIS and ASP.NET can use the same configuration for enabling and ordering server modules, and configuring handler mappings. Other unified functionality includes tracing, custom errors, and output caching.

Runtime Fidelity

In Integrated mode, the ASP.NET request processing stages exposed to modules are directly connected to the corresponding stages of the IIS pipeline. The complete pipeline contains the following stages, exposed as HttpApplication events in ASP.NET:

  1. BeginRequest. The request processing is starting.
  2. AuthenticateRequest. The request is being authenticated. IIS and ASP.NET authentication modules subscribe to this stage to perform authentication.
  3. PostAuthenticateRequest
  4. AuthorizeRequest. The request is being authorized. IIS and ASP.NET authorization modules check whether the authenticated user has access to the resource being requested.
  5. PostAuthorizeRequest
  6. ResolveRequestCache. Cache modules can check whether the response to this request exists in the cache, and return it instead of proceeding with the rest of the execution path. Both ASP.NET Output Cache and the new IIS Output Cache features execute here.
  7. PostResolveRequestCache
  8. MapRequestHandler. This stage is internal in ASP.NET, and is used to determine the request handler.
  9. PostMapRequestHandler
  10. AcquireRequestState. The state necessary for the request execution is being fetched. ASP.NET Session State, and Profile modules obtain their data here.
  11. PostAcquireRequestState
  12. PreExecuteRequestHandler. Any tasks before the execution of the handler can be performed here.
  13. ExecuteRequestHandler. The request handler executes here. ASPX pages, ASP pages, CGI programs, and static files are served here.
  14. PostExecuteRequestHandler
  15. ReleaseRequestState. The request state changes are saved, and the state is cleaned up here. ASP.NET Session State and Profile modules use this stage for cleanup.
  16. PostReleaseRequestState
  17. UpdateRequestCache. The response can be stored in the cache for future use here. The ASP.NET Output Cache and IIS Output Cache modules execute here to save the response to their caches.
  18. PostUpdateRequestCache
  19. LogRequest. This stage is used to log the results of the request, and is guaranteed to execute even if errors occur.
  20. PostLogRequest
  21. EndRequest. This stage is used to perform any final request cleanup, and is guaranteed to execute even if errors occur.

The ability to execute in the same stages as IIS modules makes many tasks previously only accessible to native ISAPI filters and extensions now possible in managed code, using the familiar ASP.NET APIs and the rich functionality of the .NET platform. For example, you can now write modules that do the following:

  • Intercept the request before any processing has taken place, for example for re-writing urls or performing security filtering.
  • Replace built in authentication modes.
  • Modify the incoming request contents, such as request headers.
  • Filter outgoing responses for all content types.

Monday, October 16, 2006

VB.NET v.s. C# v.s. Java

^ 有人说有经验的programmer在VB.NET和C#之间转换只需要一个星期的时间,我也觉得不需要费多久。我现在在一个咨询项目里使用这两种语言,经常是今天VB.NET,明天C#,需要做的就是偶尔查查MSDN上的Language Syntax Reference。写程序,关键的是编程思想,语法差别不是重要的。所以,我很乐意地说:VB.NET和C#我都用得挺好。
^ 我从前写了四五年Java,从Java到C#转换我没有感觉有多少困难。反正我写程序的方式、风格、思路还是一样。并且,我还是可以随时用Java编程。所以,我认为:
最重要的是deep understanding of Object-Oriented。
非常重要的是programming patterns and best practices。
很重要的是very familiar with class library
也很重要的是experienced with top IDEs。

e How popular is VB .NET versus C#?
e VB.NET and C# Comparison
e Java (J2SE 5.0) and C# Comparison
e VB.NET vs C#: The Great .NET Language Debate

What is Property, on earth?

@ Properties can be considered smarter fields in that they can be assigned to or read from (like a field), yet when this happens some code in the class executes, and therefore the author of the class can process the value being assigned or returned.

@ Inside the Property block, you write a Get…End Get block, which defines which value the property returns, and a Set…End Set block, which defines how values are assigned to the property.

@ In most cases, a property simply maps to a Private field, so the code for these two blocks often looks like this:

Dim m_BirthDate As Date
Public Property BirthDate() As Date
Get
Return m_BirthDate
End Get
Set(ByVal value As Date)
m_BirthDate = value
End Set
End Property

Sun Microsystems Talks With Li Moore of Google

By Robert Eckstein, September 27, 2005

Thinking of migrating to the Java 2 Platform, Standard Edition (J2SE) 5.0, code-named Tiger? You're not alone. Thousands of companies all over the world are giving J2SE 5.0 a try, and they like what they see. New language features, enhanced class libraries, better tool support, and desktop enhancements are just some of the reasons why many companies are making the switch.

In this article, we talk with Li Moore, software engineer at Google, Inc., about his company's switch from J2SE version 1.4 to 5.0.


Thanks for talking with me today, Li. Google is, of course, the worldwide search engine of choice. How does Google use Java technology?
Google makes extensive use of the Java platform. Large parts of popular Google products are written in Java. We also use Java in many internal systems and products under development.

Which core and enterprise APIs or technologies are critical to your work?
We make heavy use of core Java APIs including the Collections API, java.util.concurrent, and java.nio. We also make heavy use of the Servlet API.

Did you expect that any changes with the 5.0 version of the JDK might be detrimental to your Java applications at Google?
Nope. Everyone was excited about the new language features, the new concurrency libraries, and the new monitoring and management facilities.

Were there any Tiger features that made you say, "Oh, this is great! We needed this a while ago"?
We've wanted enums and generics at Google for years. Like everyone else, we wrote our own thread pool and work queue classes years ago.

Tell us about the migration process. What sort of issues and surprises did you encounter?
I learned about Tiger in the fall of 2004. I liked what I saw and took it upon myself to convert all of our Java development to JDK 5.0. I worked on the migration as a 20 percent project: Google lets its engineers devote 20 percent of their time to any project that they think is cool and in the company's interest.
We migrated to Tiger in stages. First, we tried it on existing code without using any of the new features. Of course, we ran into the same problem that everyone does -- enum is now a reserved word. That's an easy, if tedious, one to fix. Then we tested the performance of some key applications. We were pleasantly surprised when they ran significantly faster on the new release.
I met with key people from various projects and got buy-in for the transition. We came up with a schedule that culminated in a flag day, when everyone felt comfortable switching. I mapped out a transition plan for each project and created documentation to help people with the transition. We had a little difficulty getting all the tests to pass. We discovered a few minor compatibility issues with the new release, which we reported back to Sun, which has since fixed them.
When it came time to make the actual switch, we had no problems. We were pleasantly surprised by how easy it was. Developers were enthusiastic about the transition and quickly followed flag day with changes that upgraded existing code to use the new language features.

If you could make one change to the Java core or enterprise APIs right now, what would it be? If you could add one feature, what would it be?
It would be nice to add a clone() method to Cloneable, but unfortunately that's not possible at this point. Also, it would be nice to make the byte type unsigned. More realistically, I'd like to see a pluggable file system API like the one that Sun proposed in JSR 203.

Have you tested your applications against the prerelease of Mustang?
No, but we have started using some of the forthcoming concurrency utilities that are already available for use on the JSR 166 interest site.

Is there anything you would like to add?
Our developers were already excited about J2SE 5.0 several weeks before the transition. As soon as we switched, use of the new features just took off. Even something as simple as the new for-each loop makes it so much more fun to write Java programs.
This release is purely an improvement, in terms of language features, libraries, stability, performance, and tools. I can't imagine why anyone would use the 1.4 release at this point.

Article Origine: http://java.sun.com/developer/technicalArticles/J2SE/google/limoore.html

Auto searching and merging cells of same value.



///
/// 把指定栏中的相同内容的cells合并成一个cell。
///

///
///
public void MergeIdenticalCells(int _rowIndexOfStartCell, int _columnIndexOfStartCell)
{
// 首先把returnedEndCell设为与startCell一样。
int rowIndexOfReturnedEndCell = _rowIndexOfStartCell;
int columnIndexOfReturnedEndCell = _columnIndexOfStartCell;

int rowIndexOfWholeColumn = _rowIndexOfStartCell - 1 + oSheet.UsedRange.Rows.Count;
try
{
while(rowIndexOfReturnedEndCell < rowindexofendcell =" _rowIndexOfStartCell;" columnindexofendcell =" _columnIndexOfStartCell;" rangeofstartcell =" (Range)(oSheet.Cells[_rowIndexOfStartCell," i =" _rowIndexOfStartCell;" selectedcell =" (Range)(oSheet.Cells[i," rowindexofendcell =" i;" rangeofendcell =" (Range)(oSheet.Cells[rowIndexOfEndCell," valueofendcell =" rangeOfEndCell.Value2.ToString();" themergedrange =" oSheet.get_Range(rangeOfStartCell," value2 =" Type.Missing;" value2 =" valueOfEndCell;" _rowindexofstartcell =" rangeOfEndCell.Row">


Sunday, October 15, 2006

Displaying images in Grid or Cloud with ASP.NET


e 4GuysFromRolla Scott Mitchell Using the TreeView Control and a DataList to Create an Online Image Gallery
e 4GuysFromRolla A Robust Image Gallery for ASP.NET

Storing images with SQL Server Database

e Inserting Images to SqlServer in ASP .NET
e Retrieving Images from SqlServer and displaying in a DataGrid

Resizing & Scaling images in .NET


e 4GuysFromRolla Scott Mitchell Displaying a List of Scaled Images
e 4GuysFromRolla Scott Mitchell True Image Resizing, Part 1
e 4GuysFromRolla Scott Mitchell True Image Resizing, Part 2 : About thumbnail

e SmartThumbnail.Net Component

Implementing CAPTCHA in ASP.NET

e CAPTCHA Image
e Generating ASP.NET Images on the Fly

Manipulating Image with .NET

e Rob's Image Shrinker : Scaling image file.
e Flickr-ing about with .NET
e Generating ASP.NET Images on the Fly

Authentication in an ASP.NET application

@ The Membership service convered all the details of authentication for an applications, whereas the Role Management service covers authorization.

@ To allow forms authentication in your web application, the 1st step is to turn on this Membership service in the web.config file.

How to display HTML/XML tags code in webpage?

Method 1: Use the <xmp>tage to surround the HTML or XML code to be displayed as plain text. For example:

<xmp>system><display><name>Someone</name></display></system>

Method 2: Convert the <> to &lt;>.
To display a simple link as code: &lt;a href="http://www.simplelink.com&quot;>Here</a>
Would show as : <a href="http://www.simplelink.com">Here</a>

@ Simple Code Encoder SUPER great tool, i.e.
<system.web>
      <urlMappings enabled="true">
            <add url="~/About.aspx" mappedUrl="~/Site_Common/About.aspx"/>
            <add url="~/Legal.aspx" mappedUrl="~/Site_common/Legal.aspx"/>
      </urlMappings>
</system.web>


e Display Code In Entries

Saturday, October 14, 2006

URL Mapping in ASP.NET 2.0

When URL mapping is useful?
URL mapping comes handy in number of situations:

  • You want to hide a big URL from the end user and present an easy to remember shorter URL
  • You want to pass query string parameters to a page but do not want them to be displayed to the user
  • You have changed web form names after the application is deployed
    How this works?

In ASP.NET 2.0 there is a configuration section called urlMappings that maps one URL to the other. The following markup shows how this section can be used:


<br /><system.web><br /><urlmappings enabled="true"><br /><add mappedurl="~/Site_Common/About.aspx" url="~/About.aspx"><br /><add mappedurl="~/Site_common/Legal.aspx" url="~/Legal.aspx"><br /></urlmappings><br /></system.web><br />

The enabled attribute of section enables or disables the URL mapping feature.
The sub section allows you to specify the actual mapping.
The url attribute of section specifies the URL as seen by the end user. It can be from browser address bar, hyper link or Response.Redirect statements.
The mappedUrl attribute species the URL that is actually served in place of the URL specified by url attribute.

You can specify as many URL mappings as you wish using multiple tags.

About Microsoft .NET Framework 3.0

The Microsoft .NET Framework version 3.0 (formerly known as WinFX) is the new managed-code programming model for Windows. It combines the power of .NET Framework 2.0 with new technologies for building applications that have a visually compelling user experience, seamless communication across technology boundaries, and support for a wide range of business processes.

All of the classes that represent the new components (WPF, WF, WCF, and CardSpace) are part of the System namespace. The core classes of the .NET platform, such as the common language runtime (CLR) and base class libraries (BCL) remain as they are in .NET Framework 2.0.



How .NET Framework 3.0 Relates to .NET Framework 2.0 and Earlier
The .NET Framework 3.0 adds new technologies to the .NET Framework 2.0, which makes the .NET Framework 3.0 a superset of the .NET Framework 2.0. You can think of .NET Framework 3.0 as an "additive" release to the .NET Framework 2.0, as contrasted with a generational release where software is revised across the board. (For example, the .NET Framework 2.0 was a generational release over the .NET Framework 1.0.)

Because .NET Framework 3.0 is an additive release and uses the core run-time components from .NET Framework 2.0, it is completely backward compatible with the earlier version. Your existing .NET Framework 2.0 based-applications will continue to run without any modifications and you can safely continue your investments using the technologies that shipped with .NET Framework 2.0.

Installing the .NET Framework 3.0
The .NET Framework 3.0 is installed by default on Microsoft Windows Vista. On Microsoft Windows Server code-named "Longhorn", you can install the .NET Framework as a Windows Feature using Roles Management tools. On Windows XP and Windows Server 2003, installing .NET Framework 3.0 also adds any .NET Framework 2.0 components that are not already installed.
If .NET Framework 2.0 is already installed, the .NET Framework 3.0 installer adds only the files for Windows Presentation Foundation (WPF), Windows Workflow Foundation (WF), Windows Communication Foundation (WCF), and Windows CardSpace.

Components shared with .NET Framework 2.0 are installed in the following location:%windir%\Microsoft.NET\Framework\V2.0.50727
Components that are new to .NET Framework 3.0 are installed in the following location: %windir%\Microsoft.NET\Framework\V3.0
All components of the .NET Framework 3.0 reference assemblies are installed in the following location: %programfiles%\Reference Assemblies\Microsoft\Framework\v3.0

Uninstalling .NET Framework 3.0 will not remove the components shared with .NET Framework 2.0. To remove those components, you must first uninstall .NET Framework 3.0 and then separately uninstall .NET Framework 2.0.

Version Numbers for .NET Framework Assemblies
The .NET Framework 3.0 shares many components with .NET Framework 2.0, and the common language runtime (CLR) and base class libraries are the same as those in .NET Framework 2.0. Therefore, these shared components stay at version 2.0.

The version number 3.0 applies to all runtime and reference assemblies for Windows Communication Foundation (WCF), Windows Presentation Foundation (WPF), Windows Workflow Foundation (WF), and Windows CardSpace.

^ 基本上对我没有什么影响,因为我目前只关心Internet Application。所以,用好ASP.NET 2.0就是首要的。集中力量,先不去管.NET Framework 3.0的其他部分。

Friday, October 13, 2006

SQL Subqueries

INSERT INTO TableA (PosID, PosValue, DataDate) SELECT PosID, PosValue, DataDate FROM TableB WHERE DataDate = '2006-10-6' AND PosID = 'TAEE1'

^ Values (A,B,C)部分替换成一个SELECT A,B,C语句便可。


UPDATE TableA SET PosValue = (SELECT PosValue FROM TableB WHERE
DataDate = '2006-10-6' AND PosID = 'TAEE1' ) WHERE PosID = 'TAEE1' AND DataDate = '2006-10-6'


^
SELECT OUID, (SELECT ID, OUName FROM Accounts_OU WHERE ID = A.OUID ORDER BY ID) AS OUName FROM BizMgtStationOrder A WHERE PipeLineID = " & XXX & " ORDER BY OUID"


d Subquery Fundamentals

A subquery is a SELECT query that returns a single value and is nested inside a SELECT, INSERT, UPDATE, or DELETE statement, or inside another subquery. A subquery can be used anywhere an expression is allowed. In this example a subquery is used as a column expression named MaxUnitPrice in a SELECT statement.

SELECT Ord.OrderID, Ord.OrderDate,
(SELECT MAX(OrdDet.UnitPrice)
FROM Northwind.dbo.[Order Details] AS OrdDet
WHERE Ord.OrderID = OrdDet.OrderID) AS MaxUnitPrice
FROM Northwind.dbo.Orders AS Ord

A subquery is also called an inner query or inner select, while the statement containing a subquery is also called an outer query or outer select.

Many Transact-SQL statements that include subqueries can be alternatively formulated as joins. Other questions can be posed only with subqueries. In Transact-SQL, there is usually no performance difference between a statement that includes a subquery and a semantically equivalent version that does not. However, in some cases where existence must be checked, a join yields better performance. Otherwise, the nested query must be processed for each result of the outer query to ensure elimination of duplicates. In such cases, a join approach would yield better results. This is an example showing both a subquery SELECT and a join SELECT that return the same result set:

/* SELECT statement built using a subquery. */
SELECT ProductName
FROM Northwind.dbo.Products
WHERE UnitPrice =
(SELECT UnitPrice
FROM Northwind.dbo.Products
WHERE ProductName = 'Sir Rodney''s Scones')

/* SELECT statement built using a join that returns
the same result set. */
SELECT Prd1.ProductName
FROM Northwind.dbo.Products AS Prd1
JOIN Northwind.dbo.Products AS Prd2
ON (Prd1.UnitPrice = Prd2.UnitPrice)
WHERE Prd2.ProductName = 'Sir Rodney''s Scones'

A subquery nested in the outer SELECT statement has the following components:
A regular SELECT query including the regular select list components.
A regular FROM clause including one or more table or view names .
An optional WHERE clause.
An optional GROUP BY clause.
An optional HAVING clause.

The SELECT query of a subquery is always enclosed in parentheses. It cannot include a COMPUTE or FOR BROWSE clause, and may only include an ORDER BY clause when a TOP clause is also specified.

A subquery can be nested inside the WHERE or HAVING clause of an outer SELECT, INSERT, UPDATE, or DELETE statement, or inside another subquery. Up to 32 levels of nesting is possible, although the limit varies based on available memory and the complexity of other expressions in the query. Individual queries may not support nesting up to 32 levels. A subquery can appear anywhere an expression can be used, if it returns a single value.
If a table appears only in a subquery and not in the outer query, then columns from that table cannot be included in the output (the select list of the outer query).

Statements that include a subquery usually take one of these formats:


WHERE expression [NOT] IN (subquery)
WHERE expression comparison_operator [ANY ALL] (subquery)
WHERE [NOT] EXISTS (subquery)

In some Transact-SQL statements, the subquery can be evaluated as if it were an independent query. Conceptually, the subquery results are substituted into the outer query (although this is not necessarily how Microsoft® SQL Server™ actually processes Transact-SQL statements with subqueries).
There are three basic types of subqueries, those that:
Operate on lists, introduced with IN or those that a comparison operator modified by ANY or ALL.
Are introduced with an unmodified comparison operator and must return a single value.
Are existence tests introduced with EXISTS.


Wednesday, October 11, 2006

Label and Label Cloud / Tag and Tag Cloud

Making and sending HTML email

@ The Process of Creating and Sending an E-mail Message: To create and send an e-mail message, follow these steps:

  1. Create a MailMessage object. MailMessage and other mail-related classes are in the System.Net.Mail namespace.
  2. If you did not specify the recipients in the MailMessage constructor, add them to the MailMessage object.
  3. If you need to provide multiple views (such as plain text and HTML), create AlternateView objects and add them to the MailMessage object.
  4. If necessary, create one or more Attachment objects and add them to the MailMessage object.
  5. Create an SmtpClient object, and specify the SMTP server.
  6. If the SMTP server requires clients to authenticate, add credentials to the SmtpClient object.
  7. Pass your MailMessage object to the SmtpClient.Send method. Alternatively, you can use SmtpClient.SendAsync to send the message asynchronously.

How to create a MailMessage

^ 一定要首先创建空的MailMessage,然后把MailMessage.ToMailMessage.FromMailMessage.SubjectMailMessage.Body四个property依次添加到MailMessage中。还可以添加MailMessage.CcMailMessage.Bcc

^ 因为每次发送邮件不一定会发给多少个人,所以写程序时不区分发给单人还是多人的情况。把所有得到的收件人地址都放进一个MailAddressCollection中。

@ BCC stands for "blind carbon copy".

@ The problem with BCC is that spam filters frequently block messages that do not have the recipient's email address in the From header, Therefore, if you use BCC, the message will very likely be filtered.

How to create HTML email?

@ To create an HTML email message, supply HTML-tagged content for MailMessage.Body and set MailMessage.IsBodyHtml attribute to True.
Dim OneMailMessage = New MailMessage
String OneMailMessageHtmlBody = "XHTML codes ..."
OneMailMessage.IsBodyHtml = True
OneMailMessage.Body = OneMailMessageHtmlBody

@ Most email clients will ignore the head section, and will ignore any client-side scripts, and will not automatically download images from Web sites.

@ To embed images into an HTML message so that they appear when the user clicks the message (without requiring the user to explicitly choose to download images): first creat an HTML message using AlternateView and then add images using LinkedResource classes.

^ 因为有的邮件客户端或者服务器会阻止图片内容,或者只支持普通文本格式的邮件,或者用户设定只接受文本邮件,所以需要提供alternate view以根据情况显示邮件内容。

e 4guysfromrolla.com Sending Email in ASP.NET 2.0
e 4guysfromrolla.com Sending Email in ASP.NET 2.0: HTML-Formatted Emails, Attachments, and Gracefully Handling SMTP Exceptions

e Complete FAQ for the System.Net.Mail namespace found in .NET 2.0

Globalization: Culture, Region, Date, Number

@ How to detect a user's current culture information?
Using the CurrentCulture property of the executing thread's CurrentThread property. i.e.,
Dim UserCulture As CultureInfo = Thread.CurrentThread.CurrentCulutre
Console.WriteLine("The current culture of this application is : " & UserCulutre.Name)

@ How to set the current culture?
Just specify a different value to the CurrentCulture property of the CurrentThread property of the Thread class. i.e.,
Thread.CurrentThread.CurrentCulutre = New CultureInfo("es-VE")

@ The RegionInfo class provides specific information about a particular country or region.

@ The DateTimeFormatInfo class provides a comprehensive set of methods and properties to handle and respond to the dates of different culutres.
Dim UserCulture As CultureInfo = New CultureInfo("zh-CN")
Dim Days() As String = UserCulture.DateTimeFormat.DayNames
For Each Day As String In Days
Console.WriteLine("Culture : " & UserCulture.Name)
Console.WriteLine("Day Name : " & Day)
Next

Shared Method V.S. Instance Method

@ Shared means "shared between all instances of a class", which is also called static.

Tuesday, October 10, 2006

Declarative Language V.S. Imperetive Language

@ The ASP.NET markup language (that is, the ASPX language) is increasingly being recognized as a declarative programming language.

@ Declarative programming is quite a different programming model.
@ When you program with an imperative language, you reach a desired goad by providing the specific operations required to reach the goal. (That is, you tell the computer how to reach your goal.)
@ When you program with a declarative language, you specify your goal and a compiler or interpreter uses its predefined algorithms to determine the appropriate operations to reach that goal. (That is, the computer find a way to reach your goal.)

^ 这就像我曾经说过的,我只在乎是否实现了一个function,而不在乎这个function是怎么被实现的。

e The Right Way to do Ajax is Declaratively
e Declarative V.S. Imperative Programming
e Declarative programming
e del.icio.us/tag/declarative

Manipulating Microsoft Office

Excel How to
Office Wiki
Joe Andreshak (MS) http://blogs.officezealot.com/joe/
Clinick's Clinic http://weblogs.asp.net/andrewclinick/
John Durant (MS) http://blogs.msdn.com/johnrdurant
Mark Harrison (MS) http://blog.markharrison.co.uk/
Laura John (MS) http://blogs.msdn.com/lauraj
Eric Lippert (MS) http://blogs.msdn.com/ericlippert
Andrew May (MS): http://blogs.msdn.com/andrew_may
Chris Kunicki http://blogs.officezealot.com/chris
Charles Maxson http://blogs.officezealot.com/charles
Office Zealot Blogz http://www.officezealot.com/BlogHome.aspx
Frank Rice (MS) http://blogs.msdn.com/frice
Peter's Blog: http://blog.jausovec.net/
Peter Torr: http://weblogs.asp.net/ptorr/

About VB.NET Procedure / Method

@ A procedure is a block of Visual Basic statements enclosed by a declaration statement (Function, Sub, Operator, Get, Set) and a matching End declaration. All executable statements in Visual Basic must be within some procedure.

@ Types of Procedures
Visual Basic uses several types of procedures:
· Sub Procedures perform actions but do not return a value to the calling code.
· Event-handling procedures are Sub procedures that execute in response to an event raised by user action or by an occurrence in a program.
· Function Procedures return a value to the calling code. They can perform other actions before returning.
· Property Procedures return and assign values of properties on objects or modules.
· Operator Procedures define the behavior of a standard operator when one or both of the operands is a newly-defined class or structure.
· Generic Procedures in Visual Basic define one or more type parameters in addition to their normal parameters, so the calling code can pass specific data types each time it makes a call.

Reflection到底是个啥东西?

@ Code in the CLR is packaged in an assembly. Even though it is often thought of as a file, an assembly is actually a logical container for different parts of the data the CLR needs to execute code.

@ These parts of data of an assembly include: Assembly metadata, Type metadata, Intermediate Language code, and Resources.

@ Assembly Metadata includes data that defined the assembly, such as the name, version, strong name, and culture information. Assembly metadata is also called manifest.

@ Type Metadata is the information describes what a type looks like, including the namespace, class name, members (methods, properties, constructors, etc.), and parameters.

@ Most of the time, all these parts of an assembly are compiled into a single file.

@ Assemblies are containers for modules, and modules are containers for types.

^ 我啥时候会用的上Reflection呀?

e C-sharp reflection: Save development time throughout the project life-cycle

Web API V.S. Web Services

@ Web APIs are application programming interfaces that can be called over standard Internet protocols.

@ It is helpful to think of a Web API as a series of Web services, each of which has one or more procedures that can be called using the Internet.

@ Web APIs are typically a related collection of Web services.

Monday, October 09, 2006

Callback

Saturday, October 07, 2006

Page.IsPostBack

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

'Page.IsPostBack是用来检查目前网页是否为第一次加载,
'当使用者第一次浏览这个网页时page.ispostback 会传回false,不是第一次浏览这个网页时就传回true;
'所以当我们在page_load 事件中就可以使用这个属性来避免做一些重复的动作。
'此处,如果是第一次加载,则要执行下列代码,否则就不执行,所以要保证If true Then
If Not Page.IsPostBack Then
......
End If
End Sub

The constructor method of VB.NET

A constructor is a method that runs when a new instance of the class is created.
In Visual Basic, the constructor method is always named Sub New:


Class Person
Private CreateTime As Date
Sub New()
' Display a diagnostic message.
Console.WriteLine("A new instance of Person is being created.")
' Remember when this instance was created.
CreateTime = Now
' Perform other initialization chores.

End Sub
End Class

Cross Page Postback in ASP.Net 2.0

Exporting Data to Excel

Original Address: http://www.developer.com/net/asp/article.php/3633891

A common request of users is to be able to download data for use in Microsoft Excel. This is actually fairly easy to accomplish without a lot of extra work.

I do most of my database work with DataTable objects, as I don't need the overhead of a DataSet. I also have a Database wrapper class that is able to easily retrieve data from a SQL Server database. Once I use my function to get my DataTable, I can start exporting the data. For this example, however, I'll use the traditional SqlDataAdapter method to retrieve the data initially.

There are a few tricks to making this work.
First, you have to create an ASPX page with no HTML content in it. The only thing that should be in the ASPX page is the Page directive at the top.
The second trick is to clear the existing content and send down a new content type. For Excel, you use a content type of application/vnd.ms-excel. This tells your Web browser to expect something that can be handled within Excel.
The third trick is to send down the data tab-delimited per column and a newline at the end of each row.
After that, Excel does the rest of the work for you.

Tuesday, October 03, 2006

ASP.NET Inline Data-Binding Syntax

@ One-way data binding:

Eval("", "")

第一部分是Item的名称;第二部分是一个Formatter。

@ Two-way data binding:
<%# Bind("Name", "{0:mm dd yyyy}") ) %>
第一部分是Item的名称;第二部分是一个Formatter。

Sunday, October 01, 2006

.NET Framework Application Domain

@ How to create an Application Domain?
@ To create an AppDomain, call static AppDomain.CreateDomain("YourAppDomain") method.
@ To load an assembly in an application domain, call AppDomain.ExecuteAssembly("TheAssemblyName.exe") method.
@ To unload an application domain, call static AppDomain.Unload(YourAppDomainReference) method.

Dim OneAppDomain As AppDomain = AppDomain.CreateDomain("MyFirstDomain")
Console.WriteLine(" Host domain: " + AppDomain.CurrentDomain.FriendlyName)
Console.WriteLine("Child domain: " + OneAppDomain.FriendlyName)

@ Create an application domain anytime you want to launch an assembly.