mercredi 16 décembre 2009

Asp.net 2.0: ListControl Vs WebControl when (Page.IsCallback == True)

Hi,
In Asp.net 2.0 :

- you can catch asynch Event on implementing ICallBackEvent Handler.
- the Event LoadViewState is raised after a POSTPACK

So if you create 2 Custom web controls ( "WC1" and "WC2"):

-WC1: inherits from "WebControl" and implements " ICallBackEvent Handler"

-WC2: inherits from "ListControl" and implements " ICallBackEvent Handler"

-override the LoadViewstate in the 2 controls and put a breakpoints.

On the click event of WC1, you call a Javascript Method that send a Callback to the Server


Normally When you click on WC1, the LoadViewState event will be not raised because is not a POSTBACK event, BUT strangelly in the WC2 the LoadViewState method is raised!

So the conclusion is, All controls that inherits from "ListControl" raise the LoadViewState method evenif there is no postback!

WHY ?

dimanche 27 septembre 2009

"Code Project Associate" Status @ Code Project


Now i'm "The Code Project Associate" @ THE CODE PROJECT, Thanks all.

Code Project Member Types:

The Code Project Associate

Members who have their own websites with their high quality content and who choose to share their content with The Code Project community can be selected to be Code Project Associates.



vendredi 25 septembre 2009

Asp.Net : __VIEWSTATE Bug !

When you Try this on Asp.net 2.0 WebSite:

http://www.YouWebsite/default.aspx?__VIEWSTATE=COUCOU!

You will have something like that:



How can we exploit it ? and what we have to do, to resolve this Bug?!

Any Suggestions Are Welcome.


08/01/2010

I found the Solution: Remove "__VIEWSTATE" parameter From "Request.QueryString"

protected override void OnInitComplete(EventArgs e)
{
base.OnInitComplete(e);

if (Request.QueryString.ToString().Contains("__VIEWSTATE"))
{

// reflect to readonly property
PropertyInfo isreadonly = typeof(System.Collections.Specialized.NameValueCollection).GetProperty("IsReadOnly", BindingFlags.Instance | BindingFlags.NonPublic);

// make collection editable
isreadonly.SetValue(this.Request.QueryString, false, null);

// remove
this.Request.QueryString.Remove("__VIEWSTATE");


// make collection readonly again
isreadonly.SetValue(this.Request.QueryString, true, null);

}

}

lundi 9 mars 2009

Microsoft TechDays in Belgium, 10-12 March 2009


During 3 days, in 60 technical sessions, you’ll get a deep-dive on existing and future technologies of Microsoft:
  • Discoveries: Windows 7, Windows Azure, Cloud Computing, C# 4.0
  • Architecture and development: Visual Studio, Silverlight, SharePoint, web applications, …
  • Infrastructure and enterprise applications: SQL Server, WCF, Windows Server, virtualization, System Center, security, …
  • Personal and collective efficiency: Data access, desktop management, Unified Communications, remote office operations, SharePoint,…

But also:

  • Get your hands on a Microsoft Surface
  • Interact with the Microsoft partner network and the Microsoft linked applications and services
  • Discover our certification offerings
  • Share impressions with your peers and meet with internationally renowned professionals

vendredi 6 mars 2009

How to protect C# program from .Net Decompiler ?!

Hi,
As you know there is some .Net Decompiler as Reflector that allows getting .Net DLL Source Code!

Do you think it’s a real threat for all .Net Programs?! Or maybe the first Microsoft steps in the Open source world? Or a bad news for Microsoft because they did not expect that?

I found on the web some tools to protect C# programs…but they could affect the performance of the original program.

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