lundi 16 février 2009

what year was released C# language ?

I know that the C# language was released in 2001 but look at the header of the class "System.Web.UI.Page" code source:

//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//

//-----------------------------------------------------------------------------

// Uncomment out this line to display rare field statistics at the end of the page
//#define DISPLAYRAREFIELDSTATISTICS

/*
* Page class definition
*
* Copyright (c) 1998 Microsoft Corporation
*/

namespace System.Web.UI {

then 2001 or 1998??

vendredi 13 février 2009

Asp.Net Compilation: Generate C# Class file from "Aspx" Page

As you know, ASP.NET Works like This:



the Default.aspx page and is Code behind class Default.aspx.cs are compiled into One Class! because in page directives (the first line in Default.apsx) you find something like that:

1: CodeBehind="Default.aspx.cs" Inherits="AspxToCsharp._Default"

that means: "Default.aspx" page Inherits from "_Default.cs" C# Class

But how it's possible ?! Default.aspx it's a page that contain HTML & Script CODE!

How Asp.Net Do to Transform Default.aspx page to Default_aspx C# Class ?

I will show you ;)

Practice

+Create a simple web Project that contains one page "Default.aspx" :



+Run Web project (F5).

+Go to:
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root


you will find 2 directories, select a second one:


this Directory contains all Temporary files that asp.net Generate when Compiling Asp.net application!

we will focus on 2 C# class files:

  • App_Web_qtunxhs-.1.cs: The Factory Class of Default.apsx page
  • App_Web_qtunxhs-.0.cs (is the Main Part of this Article) : it represents the C# class generated from HTML&Script code on Default.aspx page, Open it on Visual Studio you will Find:
  1. Class Definition: As you see the Generated Class default_aspx inherits(1) from AspxToCsharp._Default
    public class default_aspx : global::AspxToCsharp._Default, System.Web.SessionState.IRequiresSessionState, System.Web.IHttpHandler {

    private static bool @__initialized;

    private static object @__fileDependencies;
  2. Constructor: set dependecies with Default.aspx page
  3. [System.Diagnostics.DebuggerNonUserCodeAttribute()]public default_aspx() {
    string[] dependencies;
    ((global::AspxToCsharp._Default)(this)).AppRelativeVirtualPath = "~/Default.aspx";
    if ((global::ASP.default_aspx.@__initialized == false)) {
    dependencies = new string[1];
    dependencies[0] = "~/Default.aspx";
    global::ASP.default_aspx.@__fileDependencies = this.GetWrappedFileDependencies(dependencies);
    global::ASP.default_aspx.@__initialized = true;
    }
    this.Server.ScriptTimeout = 30000000;
    }
  4. UI Methods (That Generate HTML Controls on Page):
  • Title
  1. HTML:
<title>Aspx To Csharp</title>

  1. C#:

  • Head
  1. HTML :

    <head runat="server">
    <title>Aspx To Csharp</title>
    <script type="text/javascript" >
    function toto()
    {
    alert('toto');
    }
    </script>
    </head>

  2. C#:

  • Input Button:
  1. HTML:
    <input id="Button2" type="button" value="button" onclick="Toto();"/>

  2. C#:

  • Asp.Net Button:
  1. HTML:
    <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />

  2. C#:

  • Form:
  1. HTML:
    <form id="form1" runat="server">
    <div>
    <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
    </div>
    <input id="Button2" type="button" value="button" onclick="Toto();"/>
    </form>
  2. C#:


  • Page(Default.aspx):
  1. HTML:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>Aspx To Csharp</title>
    <script type="text/javascript" >
    function toto()
    {
    alert('toto');
    }
    </script>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>
    <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
    </div>
    <input id="Button2" type="button" value="button" onclick="Toto();"/>
    </form>
    </body>
    </html>

  2. C#:


Now you know How Asp.Net Transform "Default.apsx" page into C# Class "Default_aspx" for Comple it with is Code behind class "_Default" to generate WebApplication DLL.

Conclusion:
P.S: The WebApplication DLL (AspxToCsharp.dll) is instantiated for each client request!

dimanche 8 février 2009

How to Implement Something Like "AJAX" in your ASP.Net Page!

In .Net framework 2.0 and upper, there's some AJAX controls that you can "DRAG&DROP" to your ASP.Net page, to have a Asynchrone communication with server IIS.

But you don't know how they communicate! the "Asynchrone communication procces" it's hidden of you and you want Understand it!

I will show you ;)

Practice
+Create a Aspx Page like this:


-each time you write something in inputText the keyup Event raise a callBack to Server .

+ in Aspx Page Code behind:
  • Page_Load():
in Page_Load we register the Ajax client script to the client's browser and create a list of string (the source) that contains some names.
The Page must implement ICallbackEventHandler to Catch CallBack Event from Client!
  • ICallbackEventHandler
when implementing ICallbackEventHandler, two methods are added:
  • RaiseCallbackEvent: Catch a CallBack event from Client.
  • GetCallbackResult: return a CallBack result to Client.

Now your page is Fully Ajax => Run & Test!

An FTP secure client library for C#

The purpose of this article is to create a C # FTP client in Secure mode, so if you don’t have much knowledge of FTPS, I advise you to take a look at this: FTPS.

In the .NET Framework, to upload a file in FTPS mode, we generally use the FtpWebRequest class, but you can not send commands with « quote » arguments, and even if you search on the web, you will not find a concrete example of a secured C# FTP client.

It’s for those reasons I decided to create this article.

How to implement an FTP secure connection with an SSL stream class


Rechercher dans ce blog