Anh Tuấn's Weblog

Cambridge IELTS 6

Posted in IELTS by tuanva on November 3, 2009

Provides students with an excellent opportunity to familiarise themselves with IELTS and to practise examination techniques using authentic test material prepared by Cambridge ESOL. Each collection contains four complete tests for Academic candidates, plus extra Reading and Writing modules for General Training candidates. An introduction to these different modules is included in each book, together with an explanation of the scoring system used by Cambridge ESOL. A comprehensive section of answers and tapescripts makes the material ideal for self-study.

Download (included audio)

Cambridge IELTS 5

Posted in IELTS by tuanva on November 3, 2009

This book provides students with an excellent opportunity to familiarize themselves with IELTS and to practise examination techniques using authentic test material prepared by Cambridge ESOL. Each collection contains 4 complete tests for Academic candidates, plus extra Reading and Writing modules for General Training candidates. An introduction to these different modules is included in each book, together with an explanation of the scoring system used by Cambridge ESOL. A comprehensive section of answers and tapescripts makes the material ideal for self-study.

Download (included audio)

Cambridge IELTS 4

Posted in IELTS by tuanva on November 3, 2009

Cambridge IELTS 4 provides students with an excellent opportunity to familiarise themselves with IELTS and to practise examination techniques using authentic test material from Cambridge ESOL. This collection contains four complete tests for Academic candidates, plus extra Reading and Writing modules for General Training candidates. An introduction to these different modules is included in each book, together with an explanation of the scoring system used by Cambridge ESOL. A comprehensive section of answers and tapescripts makes the material ideal for students working partly or entirely on their own.

Download (included audio)

Cambridge IELTS 3

Posted in IELTS by tuanva on November 3, 2009

Cambridge IELTS 3 provides students with an excellent opportunity to familiarise themselves with IELTS and to practise examination techniques using authentic test material. This collection contains four complete tests for Academic candidates, including practice in the updated Speaking test (June 2001 syllabus), plus extra Reading and Writing modules for General Training candidates. The book includes an introduction to these different modules together with an explanation of the scoring system used by Cambridge ESOL. The inclusion of a comprehensive section of answers and tapescripts means that the material is ideal for students working partly or entirely on their own. The CDs contain material for the listening paper in the same timed format as the exam.

Download (included audio)

Cambridge IELTS 2

Posted in IELTS by tuanva on November 3, 2009

This collection of practice material for the International English Language Testing system (IELTS) has been specially prepared for publication by the University of Cambridge Local Examinations Syndicate. It provides students with an excellent opportunity to familiarise themselves with IELTS and to practise examination techniques using authentic test material. Cambridge IELTS 2 contains four complete tests for Academic candidates, plus extra Reading and Writing modules for General Training candidates. The book includes an introduction to these different modules together with an explanation of the scoring system used by Cambridge ESOL The inclusion of a comprehensive section of answers and tapescripts means that the material is ideal for students working partly or entirely on their own. The cassettes contain material for the listening paper in the same timed format as the exam.

Download (included audio)

Cambridge Practice Tests for IELTS I

Posted in IELTS by tuanva on November 3, 2009

Cambridge Practice Tests for IELTS I contains four complete practice tests for the Academic module of the International English Language Testing System examination, plus extra Reading and Writing papers for the General Training module. Written by experienced IELTS examiners, one based in Britain and one based in Australia. The Student’s Book contains an introduction to the different modules of the exam together with an explanation of the different IELTS question types and how to approach them. The inclusion of annotated keys and tapescripts for each test makes the book ideal for the purposes of self-study students. The cassettes contain listening material carefully chosen to reflect the reality of the exam in terms of timing, format and the types of speaker and accent used.

Download (included audio)

IELTS Writing: connective words (part 4)

Posted in IELTS by tuanva on October 29, 2009

 

Time

  • for instance
  • There are many schools in many countries you could go to study to, for instance the schools in London or Birmingham.

  • one example
  • One example of how to get better in cooking would be to start reading recipes.

  • for example
  • just as
  • I wanted to be home already just as much as a thirsty man in the desert wanted water.

  • in particular
  • I am referring to my exams, in particular, IELTS and TOEFL.

  • such as
  • namely
  • My friends, namely Andy and Cindy, have told me about this new exhibition in the city.

  • to illustrate
  • Reason

  • since
  • Since you ask, I’d like to tell you my story

  • because (of)
  • due to
  • Due to illness of the teacher, this lecture is canceled.

  • owing to
  • the reason why
  • in other words
  • leads to
  • This assumption leads us to believe that …

  • cause
  • The cause of this unfortunate accident was…

    Time

  • before
  • since
  • Since 2005 I have been working in …

  • as
  • until
  • Until now I wasn’t able to find anything like it.

  • meanwhile
  • Meanwhile, I would like to ask for your patience.

  • at the moment
  • At the moment I am experiencing financial difficulties.

  • when
  • whenever
  • Whenever I call him, he appears to be very busy.

  • as soon as
  • just as
  • ielts-blog

    IELTS Writing: connective words (part 3)

    Posted in IELTS by tuanva on October 29, 2009

    Continuing the topic of previous posts (part 1 and part 2), here are some more connective words to use in your IELTS essay, letter or report. The headings in bold are the purpose for which you are using the connective words.

    Certainty

  • obviously
  • I was very disappointed, obviously because my expectations were too high.

  • certainly
  • I will certainly let her know your opinion.

  • plainly
  • You are plainly wrong

  • of course
  • undoubtedly
  • She is undoubtedly very beautiful

    Condition

  • if
  • unless
  • I won’t be able to meet you, unless we schedule it in the morning.

  • whether
  • Whether you like it or not, this is the truth.

  • provided that
  • I can guarantee a good result, provided that you study.

  • so that
  • I can send you the documents so that you would have proof.

  • depending on
  • We can have a picnic this weekend, depending on the weather.

    Summary

  • in conclusion
  • in summary
  • lastly
  • finally
  • to sum up
  • To sum up, I strongly support the efforts of our society to help the environment.

  • to conclude
  • to recapitulate
  • in short
  • IELTS Writing: connective words (part 2)

    Posted in IELTS by tuanva on October 29, 2009

    Some examples with previous connective words …

    Addition

  • in addition
  • In addition, I would like to point out that my neighbor is disturbing me late at night.

  • and similarly
  • Your life will change forever and similarly, your whole family will feel the change.

  • likewise
  • Some people have little time for a hobby, and have likewise little will to get one.

  • as well as
  • Beauty, as well as smarts, is a remarkable quality

  • besides
  • We aren’t friends. Besides, I don’t feel it’s my place to set him straight.

  • furthermore
  • Computers are getting faster and faster these days; furthermore, their cost is getting lower and lower.

  • also
  • moreover
  • I’ve wanting a change for a long time, moreover, I feel I deserve one.

  • and then too
  • not only … but also
  • Not only this product is good for your hair, but also for the whole body.

    Sequence

  • first(ly) initially
  • Initially, you would start putting a plan together.

  • second(ly)
  • to begin with
  • To begin with, you will need to commit a portion of your time to studying.

  • then
  • next
  • earlier/later
  • Later on there comes a stage when your skills are put to a test.

  • after this/that
  • following this/that
  • Consequence

  • as a result
  • I studied well and as a result, I got a high score.

  • thus
  • so
  • therefore
  • I was younger and therefore, less experienced.

  • consequently
  • it follows that
  • thereby
  • I upset my friend, thereby causing her pain.

  • eventually
  • then in that case
  • admittedly
  • Admittedly, he is the smartest person I know.

    Contrast

  • however
  • The book is expensive, however it’s worth it.

  • on the other hand
  • She says she feels fine, on the other hand, her face is pale and she doesn’t look healthy.

  • despite
  • in spite of
  • In spite of the difficulties, the task was completed.

  • though
  • He still insists, though he knows that won’t do any good.

  • although
  • but
  • on the contrary
  • The music didn’t lift her spirit, on contrary, it made her feel weak and vulnerable again.

  • otherwise
  • yet instead of
  • He felt unwelcome, yet instead of leaving, he stayed.

  • rather
  • Eggs for breakfast is not a good idea, I would rather have some toast.

  • whereas
  • He was her true love, whereas for him she was just another girlfriend.

  • nonetheless
  • While they didn’t trust each other, nonetheless they worked together for many years.

  • even though
  • compared with
  • in contrast
  • alternatively
  • IELTS Writing: connective words (part 1)

    Posted in IELTS by tuanva on October 29, 2009

    Addition

    • in addition
    • and similarly
    • likewise as well as
    • besides further more
    • also moreover
    • and then too
    • not only … but even
    • besides

    Sequence

    • first(ly) initially
    • second(ly) etc.to begin with then
    • next earlier/later
    • after this/that
    • following this/that

    Consequence

    • as a result
    • thus
    • so
    • therefore
    • consequently
    • it follows that
    • thereby
    • eventually
    • then in that case
    • admittedly

    Contrast

    • however
    • on the other hand
    • despite
    • in spite of
    • though
    • although
    • but
    • on the contrary
    • otherwise
    • yet instead of
    • rather
    • whereas
    • nonetheless
    • even though
    • compared with
    • in contrast
    • alternatively

    via ielts-blog

    Check out Google Music Search Feature

    Posted in Uncategorized by tuanva on October 29, 2009

    Tagged with: ,

    Most common mistakes made by VN students in Task 2 Essay

    Posted in IELTS by tuanva on October 29, 2009

    1. Do not use (…) (etc) when writing a list. Instead, lists of examples should follow the pattern; (A and B)… (A, B, and C)… (A,B,C, and D). For example: phones, radios, televisions, and other forms of technology.
    2. Do not ask the reader any questions in your essays. For example; “How do you think we can solve the problem of over-crowding in cities?”
    3. Do not use exclamation points in your essays. For example; “In my opinion, it’s the best solution to over-crowding in cities!”
    4. Phrases like “more and more”, “bigger and bigger” are too informal. Instead use structures such as “much more”, “a great deal larger”. Also, “big” is too informal for reports and essays. Use “large” “sizeable” “significant”.
    5. Do not begin sentences with “And”, “But”, “Because”, “Or”. Instead use linking phrases such as “In addition”, “However”, “Since”, “Otherwise”.
    6. The first sentence of each body paragraph should be a topic sentence. It should define the content of the paragraph in general terms.
    7. “Most/almost”: “Most” is an adjective (usually) which means the greatest quantity, amount, measure, degree or number of something. It’s followed by a noun, prepositional phrase or adjective; “Most people”, the most popular” “Most of his time”.
    “Almost” is an adverb which means very nearly, all but, slightly short of, not quite. Examples: “We’re almost home.”, “almost finished”, “almost every house” “almost never”.
    8. Manage your time well. Task 1= 20 minutes. Task 2=40 minutes. A poorly written essay or report will receive a higher band score than an incomplete one. Task 1 = 150 words, Task 2 = 250 words. Make sure you write the minimum number of words.
    9. Subject-verb agreement: He, she, it….plays, does, receives, negotiates, etc. This is a rule you learned in elementary grammar. You cannot still be making this mistake on the IELTS test. If you make this mistake in your essay, you can forget about getting a good band score.
    10. Use the correct verb tense. This is another elementary mistake that will keep you from getting a good band score. Pay attention to every verb you write and consider what tense you should be using. In addition, memorize past forms of irregular verbs.
    11. Articles (a, an, the, no article): The last of the three biggest elementary mistakes. Review the rules about articles and apply them to every noun you write.
    12. Singular/Plural, Countable/Uncountable: When speaking in general about something, use the plural form. For example: “People use computers in their offices every day.”
    13. In essays, no opinions in the body paragraphs, only in the introduction or conclusion.
    14. Write your essays from a global perspective, because the questions are asked from a global perspective. Try to avoid relating the essay question only to Vietnam. It should be about the world in general.
    15. Use linking words and transition phrases at the beginning of all body paragraphs and the conclusion. For example: Firstly, On the other hand, In summary……
    16. No contractions. for example: “shouldn’t”= should not
    17. Keep pronouns out of the essay body paragraphs. Words such as, you, we, they, should be omitted or written as people, students, society…
    Active tense can be changed to passive tense to omit the pronoun.

    From  Mr Ken

    Tagged with: , , , ,

    Texturize Windows 7 Taskbar

    Posted in Uncategorized by tuanva on October 28, 2009

    Windows 7 had one of the major changes in the form of Taskbar. Windows 7 taskbar comes with lots of new features like jumplists, thumbnails etc. Here is a simple app which can add textures to your Windows 7 taskbar. Texturized Taskbar is a simple free application which texturize your Windows 7 taskbar with predefined color schemes. The application comes with more than 10 themes in build.

    TexturizeTaskbar

    Taskbartexturized

    This currently only work if your taskbar is set to the bottom. It should work fine with Windows 7, Vista and XP.

    Download Texturized Taskbar [Via]

    Ducati Streetfighter

    Posted in Uncategorized by tuanva on October 28, 2009

    Tagged with: ,

    10 câu lập trình viên hay nói khi chương trình không chạy được

    Posted in Programming by tuanva on October 27, 2009

    10. Lạ thật…
    9. Trước giờ nó đâu có vậy đâu.
    8. Hôm qua nó chạy mà.
    7. Anh cài sai phiên bản rồi.
    6. Nó chạy rồi đó, nhưng tại vì tui chưa test kỹ.
    5. Ai đó đã sửa code của tui rồi.
    4. Anh có quét virus chưa?
    3. Anh đang làm gì thì nó bị lỗi vậy?
    2. Tại sao lại anh lại chạy nó như vậy?
    và cuối cùng…
    1. Tui tưởng là tui sửa lỗi đó rồi chứ.

    Một số câu bổ sung:

    - Trên máy tui nó chạy mà.
    - Thử khởi động lại xem.
    - Chắc bị tường lửa rồi.

    và những câu mà lập trình viên di động thường nói:

    - Trên giả lập nó chạy được mà.
    - Samsung bị điên rồi, trên Nokia chạy bình thường.
    - Tui mới viết cho Nokia thôi.

    Tagged with:

    Windows 7: How to Dual Boot Windows 7 with XP or Vista

    Posted in Uncategorized by tuanva on January 11, 2009

    If you’re dying to try out Windows 7 but aren’t ready to give up your installation of XP or Vista, let’s take a look at how to dual boot Windows 7 with XP or Vista.

    Step 0: Download the Windows 7 Beta and Burn It to a DVD

    Assuming you’ve already downloaded a fresh copy of Windows 7, you’ll need to burn it to a DVD in order to do a fresh installation. To handle this task, grab a copy of the most popular CD and DVD burning tool ImgBurn, burn the ISO to a DVD, and move right along to step 1.

    Step 1: Partition Your Hard Drive

    Before you go installing Windows 7, the first thing you need to do is create a new partition on your hard drive to hold the new installation of Windows. Partitioning your hard drive will vary depending on whether you’re running XP or Vista—namely because Vista has a partition tool baked in, XP does not.

    Partition Your Hard Drive in XP

    To partition your hard drive in Windows XP, you’ll need to download some sort of third-party partitioning software. There are a lot of options available, but I prefer to stick with the previously mentioned GParted live CD, a free, open source boot CD that can handle all kinds of partitioning duties.

    To use it, just download the GParted Live CD, burn it to a CD, then reboot your computer (booting from the disc). You’ll boot right into the partitioning tool. HowtoForge’s previous guide to modifying partitions with GParted is a great place to start, but it’s a fairly basic procedure:

    1. Resize your current OS drive to free up enough space for a Windows 7 partition (the minimum system requirements ask for 16GB).
    2. Create a new partition from the newly freed space.
    3. Apply your changes.

    Partition Your Hard Drive in Vista

    The folks at Redmond were kind enough to include a disk partitioning tool in Vista if you know where to look. So go to Control Panel -> System and Maintainence (skip this one if you’re in Classic view) -> Administrative Tools -> Computer Management. Once you launch the Computer Management tool, click on Disk Management under the Storage heading in the sidebar. It’s partitioning time.

    Luckily we’ve already gone down this road before in step-by-step detail, complete with pictures, so check out our previous guide to creating a new partition in Vista. In a nutshell, you’ll need to shrink your current OS partition to free up at least 16GB of disk space (per the Windows 7 minimum system requirements), then create a “New Simple Volume” from the free space.

    Step 2: Install Windows 7

    Now that you’ve done all the heavy lifting, it’s time for the easy part: Installing Windows 7 on your new partition. So insert your Windows 7 disc and reboot your computer (you’ll need to have enabled booting from your DVD drive in your system BIOS, but most PCs will have this enabled by default).

    Once the DVD boots up it’s a simple matter of following along with the fairly simple installation wizard. When you’re choosing installation type, be sure to select Custom (advanced) and choose the partition you set up above. (Be careful here. Choosing the wrong partition could mean wiping your other Windows installation altogether, so make sure you pick the new partition you just created.)

    After you select the partition, go grab yourself a drink and let the installer do its work. Windows will run through some installation bits, restart a few times in the process. Eventually you’ll be prompted to set up your account, enter your license key, and set up Windows. Keep your eyes open for fun new Windows 7 features, like your new homegroup (and the accompanying password). When it’s finished, you’re up and rolling with your new Windows 7 installation.

    Congratulations! You should now have a new entry for Windows 7 on your boot screen when you first start up your computer. You’ve now got all the tools necessary to dual-boot Windows 7 and XP or Vista—or even to triple-boot Windows 7, Vista, and XP.

    This isn’t the only way to set up a multi-boot system by any means, but it’s how I pulled it off. If you’ve got a method of your own that you prefer, let’s hear it in the comments.

    [Lifehacker]

    Tagged with:

    Windows 7: Microsoft Extends Windows 7 Beta Availability Until January 24th

    Posted in Uncategorized by tuanva on January 11, 2009

    Microsoftie Brandon LeBlanc admits that the Windows 7 beta release scramble “was not ideal” and says the company will extend its availability beyond the 2.5M cap until January 24th.

    We have clearly heard that many of you want to check out the Windows 7 Beta and, as a result, we have decided remove the initial 2.5 million limit on the public beta for the next two weeks thru January 24th. During that time you will have access to the beta even if the download number exceeds the 2.5 million unit limit.

    Though their initial underestimation of demand did smack of cluelessness, it’s nice to see Microsoft making amends for a rocky couple of days. As of now you can get the download and the free product key to unlock it by visiting the Windows 7 Beta site straight on no secret direct download links required.

    Here’s where we stand [Lifehacker/Windows 7 Team Blog]

    Tagged with:

    BoA – Eat You Up

    Posted in Uncategorized by tuanva on December 30, 2008

    When I first saw you I knew nothing’s like it used to be
    Boy you have got to be the finest thing in history
    The way I feel inside is just so hard to understand
    You’d be my appetite in ways I can’t explain

    I’ll eat you up
    (Your love, your love)
    I’ll eat you up
    (Your love, your love)
    (Woah)
    I’ll eat you up
    (Woah)
    So yum yum
    (Woah)
    Can’t get enough
    (Woah oh oh)
    I think I’m in love

    If you move any closer boy there is no guarantee
    What I will do to you I fear it and it’s scaring me
    Like I’ve become some kind of demon in the night
    You look so tasty and I could eat you up alive

    I’ll eat you up
    (Your love, your love)
    I’ll eat you up
    (Your love, your love) (Woah)
    I’ll eat you up
    (Woah)
    So yum yum
    (Woah)
    Can’t get enough
    (Woah oh oh)
    I think I’m in love
    Eat You Up lyrics on

    http://music.yeucahat.com/song/Mobile-Ringtones/46092-Eat-You-Up~BoA.html

    I’ll eat you up
    (Your love, your love)
    I’ll eat you up
    (Your love, your love)
    (Woah)
    I’ll eat you up
    (Woah)
    So yum yum
    (Woah)
    Can’t get enough
    (Your love, your love)

    I think I’m in love

    Can’t stop thinking ’bout all the things I wanna do to you
    If you move any closer you’d be asking for it too
    I want your love
    I need your touch
    So much I think I’m in love

    I’ll eat you up
    (Your love, your love)

    (Woah)
    I’ll eat you up
    (Woah)
    So yum yum
    (Woah)
    Can’t get enough
    (Woah oh oh)
    I think I’m in love

    I wanna take you to my room
    Wanna take you to my room

    (Woah)
    I’ll eat you up
    (Woah)
    So yum yum
    (Woah)
    Can’t get enough
    (Your love, your love) 
    I think I’m in love

    (I’ll eat you up)
    (I’ll eat you up)
    (I’ll eat you up)
    (I’ll eat you up)

    Tagged with: , ,

    Developing a Module Using .NET : Runtime Extensibility : Extending IIS 7.0

    Posted in Programming by tuanva on December 29, 2008

    Introduction

    IIS 7.0 allows for extending the server by modules which are developed in two ways:

    • Using managed code, and the ASP.NET server extensibility APIs
    • Using native code, and the IIS 7.0 native server extensibility APIs

    In the past, ASP.NET modules were limited in functionality, as the ASP.NET request processing pipeline was separate from the main server request pipeline.

    In IIS 7.0, managed modules become virtually as powerful as native modules with the Integrated Pipeline architecture. Most important, the services that managed modules provide can now be applied to all requests to the server, not just to requests to ASP.NET content like ASPX pages. Managed modules are configured and managed in a consistent manner with native modules, and can execute in the same processing stages and orderings as native modules. Finally, managed modules can perform a wider set of operations to manipulate request processing via several added and enhanced ASP.NET APIs.

    This article illustrates extending the server with a managed module in order to add the ability to perform basic authentication against an arbitrary credential store, such as the provider-based credential infrastructure in the ASP.NET 2.0 Membership system.

    This allows replacing the built in basic authentication support in IIS 7.0, which is tied to the Windows credential store, with one that supports arbitrary credential stores, or any of the existing Membership providers shipped with ASP.NET 2.0 like SQL Server, SQL Express, or Active Directory.

    This article examines the following tasks:

    • Developing a managed module using ASP.NET APIs
    • Deploying a managed module on the server

    To learn more about the basics of developing IIS 7.0 modules and handlers, see Developing IIS7 modules and handlers with the .NET framework.

    You can also find lots of resources and tips on writing IIS 7.0 modules on the blog, http://www.mvolo.com/, as well as download existing IIS 7.0 modules for your applications. For some examples, see Redirecting requests to your application with the HttpRedirection module,  Nice looking directory listings for your IIS website with DirectoryListingModule, Displaying pretty file icons in your ASP.NET applications with IconHandler, and Stopping hot-linking with IIS and ASP.NET.

    Note: The code provided in this article is written in C#.

    Prerequisites

    To follow the steps in this document, you must have the following IIS features installed:

    ASP.NET

    Install ASP.NET via the Windows Vista Control Panel. Select “Programs” – “Turn on or off Windows features”. Then open “Internet Information Services” – “World Wide Web Services” – “Application Development Features” and check “ASP.NET”.

    If you have a Windows Server® 2008 build, open “Server Manager” – “Roles” and select “Web Server (IIS)”. Click “Add role services”. Under “Application Development” check “ASP.NET”.

    Background Information on Basic Authentication

    Basic authentication is an authentication scheme defined in the HTTP.1 protocol (RFC 2617). It uses a standard challenge-based mechanism that works as follows at a high level:

    • Browser makes request to a URL with no credentials
    • If the server requires authentication for that URL, it responds with a 401 Access Denied message, and includes a header that indicates that the basic authentication scheme is supported
    • Browser receives the response, and if configured, will prompt the user for a username/password that it will include in plain text inside a request header for the next request to the URL
    • Server receives the username / password inside a header, and uses them for authentication

    Note: While a detailed discussion of this authentication protocol is outside the scope of this article, its worth mentioning that the basic authentication scheme requires SSL to be secure, as it sends the username/password in plain text.

    IIS 7.0 and previous releases include support for basic authentication against the Windows accounts stored in the local account store or Active Directory for domain accounts. We want to enable our user to authenticate using basic authentication, but to validate credentials using ASP.NET 2.0 Membership service instead. This gives the freedom to store user information in a variety of existing Membership providers, such as SQL server, without being tied to Windows accounts.

    Task 1: Developing a Module using .NET

    In this task, we examine the development of an authentication module that supports the HTTP.1 basic authentication scheme. This module was developed using the standard ASP.NET module pattern available since ASP.NET v1.0. This same pattern is used to build ASP.NET modules that extend the IIS 7.0 server. In fact, existing ASP.NET modules written for previous versions of IIS can be used on IIS 7.0, and take advantage of better ASP.NET integration to provide more power to the web applications which use them.

    Note: The full code for the module is provided in Appendix A.

    A managed module is a .NET class that implements the System.Web.IHttpModule interface. The primary function of this class is to register for one or more events that occur within IIS 7.0 request processing pipeline, and then perform some useful work when IIS 7.0 invokes the module’s event handlers for those events.

    Lets create a new source file named “BasicAuthenticationModule.cs”, and create the module class (the complete source code is provided in Appendix A):

    public class BasicAuthenticationModule : System.Web.IHttpModule
    {
    void Init(HttpApplication context)
    {
    }
    void Dispose()
    {
    }
    }The primary function of the Init method is wiring the module’s event handler methods to the appropriate request pipeline events. The module’s class provides the event handle methods, and they implement the desired functionality provided by the module. This is discussed further in detail.

    The Dispose method is used to clean up any module state when the module instance is discarded. It is typically not implemented unless the module uses specific resources that require to be released.

    Init()

    After creating the class, the next step is to implement the Init method. The only requirement is to register the module for one or more request pipeline events. Wire up module methods, which follow the System.EventHandler delegate signature, to the desired pipeline events exposed on the provided System.Web.HttpApplication instance:

    public void Init(HttpApplication context)
    {
    //
    // Subscribe to the authenticate event to perform the
    // authentication.
    //
    context.AuthenticateRequest += new
    EventHandler(this.AuthenticateUser);

    //
    // Subscribe to the EndRequest event to issue the
    // challenge if necessary.
    //
    context.EndRequest += new
    EventHandler(this.IssueAuthenticationChallenge);
    }
    The AuthenticateUser method is invoked on every request during the AuthenticateRequest event. We utilize it to authenticate the user based on the credential information present in the request.

    The IssueAuthenticationChallenge method is invoked on every request during the EndRequest event. It is responsible for issuing a basic authentication challenge back to the client whenever the authorization module rejects a request, and authentication is needed.

    AuthenticateUser()

    Implement the AuthenticateUser method. This method does the following:

    • Extract the basic credentials if present from the incoming request headers. To see the implementation of this step, see the ExtractBasicAuthenticationCredentials utility method.
    • Attempts to validate the provided credentials via Membership (using the default membership provider configured). To see the implementation of this step, see the ValidateCredentials utility method.
    • Creates a user principal identifying the user if the authentication is successful, and associates it with the request.

    At the end of this processing, if the module was successfully able to obtain and validate the user credentials, it will produce an authenticated user principal that other modules and application code later use in access control decisions. For example, the URL authorization module examines the user in the next pipeline event in order to enforce the authorization rules configured by the application.

    IssueAuthenticationChallenge()

    Implement the IssueAuthenticationChallenge method. This method does the following:

    • Check the response status code to determine whether this request was rejected.
    • If so, issue a basic authentication challenge header to the response to trigger the client to authenticate.

    Utility Methods

    Implement the utility methods that the module uses, including:

    • ExtractBasicAuthenticationCredentials. This method extracts the basic authentication credentials from the Authorize request header, as specified in the basic authentication scheme.
    • ValidateCredentials. This method attempts to validate user credentials by using Membership. The Membership API abstracts the underlying credential store, and allows the credential store implementations to be configured by adding / removing Membership providers through configuration.

    Note: In this sample, the Membership validation is commented out, and instead the module simply checks whether the username and password are both equal to the string “test”. This is done for clarity, and is not intended for production deployments. You are invited to enable Membership-based credential validation by simply un-commenting the Membership code inside ValidateCredentials, and configuring a Membership provider for your application. See Appendix C for more information.

    Task 2: Deploy the module to the application

    After creating the module in the first task, we next add it to the application.

    Deploy to Application

    First, deploy the module to the application. Here, you have several options:

    • Copy the source file containing the module into the /App_Code directory of the application. This does not require compiling the module – ASP.NET automatically compiles and loads the module type when the application starts up. Simply save this source code as BasicAuthenticationModule.cs inside the /App_Code directory of your application. Do this if you do not feel comfortable with the other steps.
    • Compile the module into an assembly, and drop this assembly in the /BIN directory of the application. This is the most typical option if you only want this module to be available to this application, and you do not want to ship the source of the module with your application. Compile the module source file by running the following from a command line prompt:

      <PATH_TO_FX_SDK>csc.exe /out:BasicAuthenticationModule.dll /target:library BasicAuthenticationModule.cs

      Where <PATH_TO_FX_SDK> is the path to the .NET Framework SDK that contains the CSC.EXE compiler.

    • Compile the module into a strongly named assembly, and register this assembly in the GAC. This is a good option if you want multiple applications on your machine to use this module. To learn more about building strongly named assemblies, see this MSDN article .

    Before making configuration changes in the application’s web.config file, we must unlock some of the configuration sections that are locked at the server level by default. Run the following from an Elevated command prompt (Start > Right click on Cmd.exe and choose “Run as Administrator”):

    %windir%system32inetsrvAPPCMD.EXE unlock config /section:windowsAuthentication
    %windir%system32inetsrvAPPCMD.EXE unlock config /section:anonymousAuthentication
    After running these commands, you will be able to define these configuration sections in your application’s web.config file.

    Configure your module to run in the application. Start by creating a new web.config file, which will contain the configuration necessary to enable and use the new module. Start by adding the text below and saving it to the root of your application (%systemdrive%inetpubwwwrootweb.config if using the root application in the Default Web Site).

    <configuration>
    <system.webServer>
    <modules>
    </modules>
    <security>
    <authentication>
    <windowsAuthentication enabled=”false”/>
    <anonymousAuthentication enabled=”false”/>
    </authentication>
    </security>
    </system.webServer>
    </configuration>
    Before enabling the new basic authentication module, disable all the other IIS 7.0 authentication modules. By default, only Windows authentication and anonymous authentication are enabled. Because we do not want the browser to attempt authenticating with your Windows credentials or allow anonymous users, we disable both the Windows Authentication module and the Anonymous authentication module.

    Now enable the module by adding it to the list of modules loaded by our application. Open web.config once again and add the entry inside to the <modules> tag

    <add name=”MyBasicAuthenticationModule” type=”IIS7Demos.BasicAuthenticationModule” /> You can also deploy the module by using either the IIS 7.0 Administration Tool, or the APPCMD.EXE command line tool.

    The final contents of the application’s web.config file after these changes are provided in Appendix B.

    Congratulations, you have finished configuring the custom basic authentication module.

    Let’s try it! Open Internet Explorer, and make a request to the application at the following URL:

    http://localhost/

    You should see the basic authentication login dialog. Enter “test” in the “User name:” field and “test” in the “Password:” field to get access. Note that if you copy HTML, JPG, or any other content to your application, they too will be protected by your new BasicAuthenticationModule.

    Summary

    In this article, you learned how to develop and deploy a custom managed module for an application, and enable that module to provide services for all requests to the application.

    You also witnessed the power of developing server components in managed code. This allowed developing a basic authentication service that is decoupled from the Windows credential storage.

    If you are adventurous, configure this module to leverage the power of the ASP.NET 2.0 Membership application services to support pluggable credential stores. See Appendix C for more information.

    Find many resources and tips on writing IIS 7.0 modules in the blog, http://www.mvolo.com/, as well as download existing IIS 7.0 modules for your applications. For some examples, see Redirecting requests to your application with the HttpRedirection module,  Nice looking directory listings for your IIS website with DirectoryListingModule, Displaying pretty file icons in your ASP.NET applications with IconHandler, and Stopping hot-linking with IIS and ASP.NET.

    Appendix A: Basic Authentication Module Source Code

    Save this source code as BasicAuthenticationModule.cs inside the /App_Code directory to quickly deploy it to your application.

    NOTE: If you are using Notepad, make sure to set Save As: All Files to avoid saving the file as BasicAuthenticationModule.cs.txt.

    #region Using directives
    using System;
    using System.Collections;
    using System.Text;
    using System.Web;
    using System.Web.Security;
    using System.Security.Principal;
    using System.IO;
    #endregion

    namespace IIS7Demos
    {
    ///
    /// This module performs basic authentication.
    /// For details on basic authentication see RFC 2617.
    ///
    /// The basic operational flow is:
    ///
    ///     On AuthenticateRequest:
    ///         extract the basic authentication credentials
    ///         verify the credentials
    ///         if succesfull, create the user principal with these credentials
    ///
    ///     On SendResponseHeaders:
    ///         if the request is being rejected with an unauthorized status code (401),
    ///         add the basic authentication challenge to trigger basic authentication.
    ///
    ///

    public class BasicAuthenticationModule : IHttpModule
    {
    #region member declarations
    public const String     HttpAuthorizationHeader = “Authorization”;  // HTTP1.1 Authorization header
    public const String     HttpBasicSchemeName = “Basic”; // HTTP1.1 Basic Challenge Scheme Name
    public const Char       HttpCredentialSeparator = ‘:’; // HTTP1.1 Credential username and password separator
    public const int        HttpNotAuthorizedStatusCode = 401; // HTTP1.1 Not authorized response status code
    public const String     HttpWWWAuthenticateHeader = “WWW-Authenticate”; // HTTP1.1 Basic Challenge Scheme Name
    public const String     Realm = “demo”; // HTTP.1.1 Basic Challenge Realm
    #endregion

    #region Main Event Processing Callbacks
    public void AuthenticateUser(Object source, EventArgs e)
    {
    HttpApplication application = (HttpApplication)source;
    HttpContext context = application.Context;
    String userName = null;
    String password = null;
    String realm = null;
    String authorizationHeader = context.Request.Headers[HttpAuthorizationHeader];

    //
    //  Extract the basic authentication credentials from the request
    //
    if (!ExtractBasicCredentials(authorizationHeader, ref userName, ref password))
    return;
    //
    // Validate the user credentials
    //
    if (!ValidateCredentials(userName, password, realm))
    return;

    //
    // Create the user principal and associate it with the request
    //
    context.User = new GenericPrincipal(new GenericIdentity(userName), null);
    }

    public void IssueAuthenticationChallenge(Object source, EventArgs e)
    {
    HttpApplication application = (HttpApplication)source;
    HttpContext context = application.Context;

    //
    // Issue a basic challenge if necessary
    //

    if (context.Response.StatusCode == HttpNotAuthorizedStatusCode)
    {
    context.Response.AddHeader(HttpWWWAuthenticateHeader, “Basic realm =”" + Realm + “”");
    }
    }
    #endregion

    #region Utility Methods
    protected virtual bool ValidateCredentials(String userName, String password, String realm)
    {
    //
    //  Validate the credentials using Membership (refault provider)
    //
    // NOTE: Membership is commented out for clarity reasons.
    // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    // WARNING: DO NOT USE THE CODE BELOW IN PRODUCTION
    // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    // return Membership.ValidateUser(userName, password);
    if (userName.Equals(“test”) && password.Equals(“test”))
    {
    return true;
    }
    else
    {
    return false;
    }
    }

    protected virtual bool ExtractBasicCredentials(String authorizationHeader, ref String username, ref String password)
    {
    if ((authorizationHeader == null) || (authorizationHeader.Equals(String.Empty)))
    return false;
    String verifiedAuthorizationHeader = authorizationHeader.Trim();
    if (verifiedAuthorizationHeader.IndexOf(HttpBasicSchemeName) != 0)
    return false;

    // get the credential payload
    verifiedAuthorizationHeader = verifiedAuthorizationHeader.Substring(HttpBasicSchemeName.Length, verifiedAuthorizationHeader.Length – HttpBasicSchemeName.Length).Trim();
    // decode the base 64 encoded credential payload
    byte[] credentialBase64DecodedArray = Convert.FromBase64String(verifiedAuthorizationHeader);
    UTF8Encoding encoding = new UTF8Encoding();
    String decodedAuthorizationHeader = encoding.GetString(credentialBase64DecodedArray, 0, credentialBase64DecodedArray.Length);

    // get the username, password, and realm
    int separatorPosition = decodedAuthorizationHeader.IndexOf(HttpCredentialSeparator);

    if (separatorPosition <= 0)
    return false;
    username = decodedAuthorizationHeader.Substring(0, separatorPosition).Trim();
    password = decodedAuthorizationHeader.Substring(separatorPosition + 1, (decodedAuthorizationHeader.Length – separatorPosition – 1)).Trim();

    if (username.Equals(String.Empty) || password.Equals(String.Empty))
    return false;

    return true;
    }
    #endregion

    #region IHttpModule Members
    public void Init(HttpApplication context)
    {
    //
    // Subscribe to the authenticate event to perform the
    // authentication.
    //
    context.AuthenticateRequest += new
    EventHandler(this.AuthenticateUser);
    //
    // Subscribe to the EndRequest event to issue the
    // challenge if necessary.
    //
    context.EndRequest += new
    EventHandler(this.IssueAuthenticationChallenge);
    }
    public void Dispose()
    {
    //
    // Do nothing here
    //
    }
    #endregion

    }
    }

    Appendix B: Web.config for Basic Auth Module

    Save this configuration as web.config file in the root of your application:

    <configuration>
    <system.webServer>
    <modules>
    <add name=”MyBasicAuthenticationModule” type=”IIS7Demos.BasicAuthenticationModule” />
    </modules>
    <security>
    <authentication>
    <windowsAuthentication enabled=”false”/>
    <anonymousAuthentication enabled=”false”/>
    </authentication>
    </security>
    </system.webServer>
    </configuration>

    Appendix C: Configuring Membership

    The ASP.NET 2.0 Membership service enables applications to quickly implement credential validation and user management required by most authentication and access control schemes. Membership isolates the application code from the actual credential store implementation, and provides a number of options for integrating with existing credential stores.

    To take advantage of Membership for this module sample, uncomment a call to Membership.ValidateUser inside the ValidateCredentials method, and configure a Membership provider for your application. You can learn more about configuring Membership in this MSDN article.

    The Official Microsoft IIS Site

    Tagged with: , , ,

    Dynamically Loading ASP.NET User Controls with jQuery

    Posted in Programming by tuanva on December 29, 2008

    Live Demo | Download Sample Solution (52.77 kb)

    ASP.NET User Controls are pretty useful.  They allow functional modules of code and markup to be encapsulated in such a way that reuse is convenient and easy, without sacrificing the power or integration of the ASP.NET model.  As we move into an era of AJAX-driven websites, this modularity is still very important. Can the user controls that we all know and (mostly) love still help with this encapsulation, despite being engineered before AJAX techniques emerged?  I think they can.  But at this point in the ASP.NET timeline, user controls are in need of some help.

    The Fundamental Problem

    With AJAX, more and more content is being dynamically loaded by the client on demand, rather than being included in the original http response.  This fundamental change conflicts with the user control’s current usage model of being attached to the control heirarchy during the page lifecycle on the server–either through markup, or using the Page.LoadControl method in code.  For user controls to be useful in the world of AJAX and demand loading, we would need to find a way to load them outside of the normal page lifecycle, and use javascript to get the the rendered HTML and inject it into our page.  Luckily, this isn’t too difficult to accomplish.

    The following example illustrates a basic scenario in which we have a page that uses jQuery to load a user control when a button is clicked.  The calling page is pretty simple:

    As you can see, all I’ve done in jQuery’s ready event handler is wire up the click event of the button to make an ajax call to a web service.  The data result that is returned from the ajax call is then added into the content div on the page.  Let’s take a look at the web service that we are calling in that code:

    This is a pretty standard WCF Ajax service, which uses a utility class called UserControlUtility by calling its RenderAsString method, which looks like this:

    In the helper method above, I’m simply accepting a parameter called path, which allows us to use the LoadControl method in the usual way.  If you are worried about the potential baggage of instantiating a Page object for every User Control that is rendered, don’t lose too much sleep over it.  A page object that is instantiated like this is pretty lightweight, and doesn’t go through the heavy ASP.NET Page lifecycle that occurs on a normal page load.

    This is pretty nifty for simple scenarios, but big challenges arise when the application gets more complicated.  What happens when the user control has javascript of it’s own?  Well ordinarily you would have a few options.  One option that I defaulted to when starting out with jQuery was to write all the JavaScript in the calling page, and just apply it to the user control’s html when it has been loaded.  This is not the best solution, because you lose the encapsulation that we were trying to maintain with user controls in the first place.  The second solution is to include the javascript within the user control within another jQuery ready handler.  This works out much better, because the client functionality gets to be bundled with the markup for clean encapsulation.  Additionally, the included javascript will be excuted when the control is rendered on the parent page, thanks to jQuery.  But has this solved all of our problems?  Not quite.

    Mo Javascript, Mo Problems

    To illustrate how problems can arise with that last solution, let me give an example. Say you are developing a real-time stock-screening application.  In this application, you have a user control called StockItemRow.ascx that had quite a bit of javascript associated with it. You also have a page called Screener.aspx that periodically polls a web service for matching stocks, and adds those stocks to the grid via a rendered instance of StockItemRow.ascx.  And suppose the user control had a good deal of javascript bundled with it, and also a few nested user controls of its own (with their own javascript, of course).  What were to happen if you dynamically added 50 or 60 rows over a few minutes? You may see what I am trying to get at here.

    The problem is that the JavaScript is being loaded over and over on each successful new request for data, simply because it is bundled inside the rendered user control.  As you load more and more data onto the page, this becomes a bigger and bigger waste.  Plus, unless you write your javascript very carefully, each new dynamically loaded user control could end up applying it’s javascript to other user controls that have already been loaded.  Yuck!  In order to solve these problems, it is going to take a little more work.

    The first issue we need to solve is the repititious loading of unnecessary javascript.  To do this, we need to separate it out from the user control into it’s own js file.  Some may argue that we are losing encapsulation here, but I disagree.  I think just if an aspx page can have both a file for markup and a codebehind file, then a user control can have both a markup file and a js file (and it’s codebehind file, for that matter). After we have separated it out, we have freed ourselves to be able to load the javascript file once, while still rendering the user control multiple times.

    But just separating the javascript out doesn’t solve our problems. We need to somehow “register” a single instance of javascript on the page, and have any dynamically loaded user controls use just that instance.  Additionally, we need to make sure that the javascript is capable of being applied to individual user controls, without affecting other user controls that have already been wired up and loaded on the page.

    Enter jQuery.DynamicLoader

    jQuery.DynamicLoader is a simple jQuery plugin I wrote that allowed a parent page to dynamically load User Controls and their corresponding script files on demand. Here is the way it works:

    • You reference jQuery.DynamicLoader on your parent page.
    • Create an ajax service that renders user controls, similar to the example I showed earlier
    • Anytime you want to load a user control on that page, call $.dynamicLoader.loadUC() with the appropriate options.  This will fetch the rendered user control, and its corresponding javascript file. If the javascript is being loaded for the first time, DynamicLoader will register that instance as the singleton for all subsequent user controls of that same type.
    • The javascript instance is then invoked with the rendered user control as its UI context.

    Let’s jump into the sample project I’ve created as an example:

    DynamicLoader.zip (52.77 kb)

    The project contains a single page Default.aspx, and two user controls, TableWidget.ascx and CellWidget.ascx.   The purpose of the project is to demonstrate a page intitally with no content, and how we can dynamically load several tiers of user controls, each with their own scripts.  We start from a single button on Default.aspx that will dynamically load a new TableWidget every time it is clicked.  Inside each TableWidget is a button gets wired up to load its own user controls, this time CellWidgets.  Each CellWidget has its own javascript that needs to execute as well.

    Here is how the first button is wired up with jQuery:

    As you can see, it is calling DynamicLoader’s loadUC function, which takes a few options: ucName is the path to the user control to be loaded, queryString allows you to pass parameters to your UserControl to help render it on the server, and eventBindings allows you to handle events that are fired within the usercontrol.

    As I mentioned earlier, the javascript in your user control needs to be registered before it can be used.  Don’t get scared off now, it’s only two extra lines of code:

    We have a standard jQuery ready handler, and inside that we call DynamicLoader’s registerUC function.  This will only be loaded once, even if multiple TableWidgets are loaded afterwards.  Also notice the event triggers.  You can create as many different types of events as your heart’s desire, as long as the parent knows the name of the event (and references it in the eventBindings option).  I’ve included ready, busy, unbusy, and finished in the default options.  The ready event is one that I consider critical, because it is the event that the parent will use to attach the user control to the page.

    Here is a screenshot of the demo:

    Live Demo | Download Sample Solution (52.77 kb)

    You can see that there are buttons on the CellWidget that do some trivial javascript actions, and also a button that demonstrates an event being monitored by the parent user control.

    Room for Improvement

    DynamicLoader is more of a proof concept than a full-fledged plugin, and there are several areas in which it needs to be improved:

    • The event chaining needs some work.  I haven’t really tested it with events that bubble more than two layers up.
    • Right now it doesn’t look like jQuery’s $.getScript is caching the scripts.  I’d like to rewrite a version of getScript that does.
    • The registration system is very rigid at this point.  It expects you to pass in a user control’s path, and the script needs to register itself with that exact path as its key (without the extension).

    So there you have it. This technique allows you to treat your User Controls as neatly encapsulated modules that are loaded and configured on demand.  Plus, there is no limit to nesting your user controls, and they will load efficiently and within their own context.   Finally, you don’t have to break communication with your user controls.  The event binding allows a separation of concerns, while still being able to act on important things that happen within the user control.

    Sam Mueller’s Blog

    Tagged with: ,