Monday, April 21, 2008

ASP.NET page lifecycle (.NET 3.0)

ASP.NET page lifecycle (.NET 3.0) - for non post back request

  • Page Request
  • Start
  • Initialize
  • Load
  • Render
  • Unload
Reference: ASP.NET page lifecycle (MSDN)
public partial class Index : Page
    {
        protected override void Construct() { base.Construct(); }
        /// 
        /// Page Request
        /// 
        public override void ProcessRequest(HttpContext context) { base.ProcessRequest(context); }
        /// 
        /// Start
        /// 
        protected override void FrameworkInitialize() { base.FrameworkInitialize(); }
        protected override void InitializeCulture() { base.InitializeCulture(); }
        protected override ControlCollection CreateControlCollection() { return base.CreateControlCollection(); }
        protected override System.Collections.Specialized.NameValueCollection DeterminePostBackMode() { return base.DeterminePostBackMode(); }
        /// 
        /// Initialize
        /// 
        protected override void OnPreInit(EventArgs e) { base.OnPreInit(e); }
        protected override void OnInit(EventArgs e) { base.OnInit(e); }
        protected override void TrackViewState() { base.TrackViewState(); }
        protected override void OnInitComplete(EventArgs e) { base.OnInitComplete(e); }
        /// 
        /// Load
        /// 
        protected override void OnPreLoad(EventArgs e) { base.OnPreLoad(e); }
        protected override void OnLoad(EventArgs e) { base.OnLoad(e); }
        protected void Page_Load(object sender, EventArgs e) { }
        protected override void OnLoadComplete(EventArgs e) { base.OnLoadComplete(e); }
        protected override void EnsureChildControls() { base.EnsureChildControls(); }
        protected override void CreateChildControls() { base.CreateChildControls(); }
        /// 
        /// Render
        /// 
        protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); }
        protected override void OnPreRenderComplete(EventArgs e) { base.OnPreRenderComplete(e); }
        protected override void OnSaveStateComplete(EventArgs e) { base.OnSaveStateComplete(e); }
        protected override HtmlTextWriter CreateHtmlTextWriter(System.IO.TextWriter tw) { return base.CreateHtmlTextWriter(tw); }
        public override void RenderControl(HtmlTextWriter writer) { base.RenderControl(writer); }
        protected override void Render(HtmlTextWriter writer) { base.Render(writer); }
        protected override void RenderChildren(HtmlTextWriter writer) { base.RenderChildren(writer); }
        /// 
        /// Unload
        /// 
        protected override void OnUnload(EventArgs e) { base.OnUnload(e); }
        public override void Dispose() { base.Dispose(); }
    } 

Wednesday, April 16, 2008

Promotion

Promoted as a web developer from previous post of junior web developer

Sunday, March 23, 2008

ASP.NET Authentication

About

Securing location of an asp.net website with password protection while allowing anonymous users to the rest of the site.
The application can then call FormsAuthentication.Authenticate, supplying the username and password, and ASP.NET will verify the credentials. Credentials can be stored in cleartext, or as SHA1 or MD5 hashes, according to the following values of the passwordFormat attribute:

Hash Type Description
Clear Passwords are stored in cleartext
SHA1 Passwords are stored as SHA1 digests
MD5 Passwords are stored as MD5 digests

Usage

<authentication>
  <credentials;passwordformat="SHA1">
    <user name="Mary" password="GASDFSA9823598ASDBAD">
      <user name="John" password="ZASDFADSFASD23483142">
  </credentials>
</authentication>


if (FormsAuthentication.Authenticate(this.Login1.UserName, this.Login1.Password))
    FormsAuthentication.RedirectFromLoginPage(this.Login1.UserName, false);
Web.config
<configuration>
  <system.web>
    <compilation batch="false" debug="true" defaultlanguage="c#">
      <authentication mode="Forms">
        <forms name="cornerstone" 
               defaulturl="admin/admin.aspx" 
               timeout="20" 
               protection="All" 
               loginurl="admin/login.aspx" 
               path="/">
          <credentials passwordformat="Clear">
            <user name="user1" password="password1">
              <user name="user2" password="password2">
        </credentials>
        </forms>
      </authentication>
      <authorization>
        <allow users="*">
    </authorization>
    </system.web>
  <location path="admin">
    <system.web>
      <authorization>
        <deny users="?">
      </authorization>
    </system.web>
  </location>
  <configuration>

Thursday, November 29, 2007

Reading and writing to Windows.Registry.

using System.Configuration;
using System.Web.Security;
using System.ComponentModel;
using System.Diagnostics;
using System.Configuration.Install;
using Microsoft.Win32;
 
namespace Install.NameSpace
{
    [RunInstaller(true)]
    public class InstallHelper : Installer
    {
 
    #region Public Static Methods
 
    public static void SaveLocalRoot(String value)
    {
        try
        {
            RegistryKey key = Registry
                .LocalMachine.OpenSubKey(ConfigurationManager
                .AppSettings["LocalRootRegKey"]
                .ToString(), true);
            if (key == null)
            Registry.LocalMachine.CreateSubKey(ConfigurationManager
                .AppSettings["LocalRootRegKey"].ToString());
            key.SetValue("DefaultLocalRoot", value);
        }
        catch (Exception e)
        {
            throw e;
        }
    }
 
    #endregion
 
    }
} 

Monday, November 26, 2007

XML Serialization and Deserialization in .NET

/// <summary>
/// Serialize
/// </summary>
/// <param name="clientList">List of objects</param>
/// <returns>success/fail (bool)</returns>
private static bool SaveClientAttributes(List clientList)
{
    try
    {
        XmlSerializer serializer = new XmlSerializer(typeof(List));
        StreamWriter writer =
        new StreamWriter((Server.MapPath(string.Empty)) 
            + "\\ClientData.xml");
        List ClientList = new List();
        serializer.Serialize(writer, clientList);
        return true;
    }
    catch (Exception ex)
    {
        return false;
    }
 
}
/// <summary>
/// Deserialize
/// </summary>
/// <returns>List of objects</returns>
private static List LoadClientAttributes()
{
    List clientList = new List();
    try
    {
        XmlSerializer serializer = new XmlSerializer(typeof(List));
        FileStream fileStream =
        new FileStream((Server.MapPath(string.Empty))
            + "\\ClientData.xml", FileAccess.Read);
        clientList = (List)serializer.Deserialize(fileStream);
    }
    catch (Exception ex)
    {
        //Do nothing
    }
    return clientList;
}

Wednesday, November 14, 2007

List.IndexOf(Object o) .NET 3.0

this.ddlCourier.SelectedIndex = affiliatecouriers.IndexOf(affiliatecouriers
        .Find(delegate(Courier courier)
        {
            return courier.ID ==
                int.Parse(iOrder.Supplementary.DeliveryCode);
        }));

References http://msdn2.microsoft.com/en-us/library/x0b5b5bc.aspx

Tuesday, November 13, 2007

Overriding Index of a Generic List

using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
namespace Application.DomainModel.Collections
{
    public class Couriers<Courier> : List<Courier>
    {
        public Courier this[string courierCode]
        {
            get
            {
                return this.Find(delegate(Courier courier)
                { return (string.Compare(courier.CourierCode, courierCode) == 0); });
            }
        }
    }
    public class Courier
    {
        public string CourierCode { getset; }
    }
}

Friday, November 09, 2007

ORA-24338: statement handle not executed

This happens when you try to read a cursor after fetching data from it. Try to read the cursor before you fetch data from it

PROCEDURE GetAffiliateCouriers(paffiliate_id number, io_cursor IN OUT appCursor)
IS
vcursor appCursor; tcursor appCursor; retCursor appCursor;
affiliate_id INTEGER; t_allow_courier_selection INTEGER;
v_row AFFILIATE%ROWTYPE; t_row AFFILIATE_COURIER%ROWTYPE;
BEGIN
vcursor := NULL;
tcursor := NULL;
affiliate_id := paffiliate_id;
LOOP
OPEN vcursor FOR SELECT * FROM affiliate WHERE id = affiliate_id AND allowcourierselection = 1;
FETCH vcursor INTO v_row;
IF (vcursor%FOUND) THEN
OPEN tcursor FOR SELECT * FROM affiliate_courier WHERE affiliate_courier.fk_affiliate_id = affiliate_id;
FETCH tcursor INTO t_row;
IF (tcursor%FOUND) THEN
OPEN retCursor FOR SELECT * FROM affiliate_courier WHERE affiliate_courier.fk_affiliate_id = affiliate_id;
io_cursor := retCursor;
RETURN;
END IF;
END IF;
SELECT fk_parent_id INTO affiliate_id FROM affiliate WHERE affiliate.id = affiliate_id;
EXIT WHEN affiliate_id IS NULL;
END LOOP;
io_cursor := retCursor;
END GetAffiliateCouriers;

Wednesday, October 31, 2007

Update set of tuples with new values : Oracle

declare
rCount integer;
j integer;
cursor cur_my_cursor is select * from my_table_name;
tRecordSet cur_my_cursor%Rowtype;
begin
rCount := 0; j:=1;
select count(id) into rCount from my_table_name;
dbms_output.put_line(rCount ' Records to be updated');
open cur_my_cursor; for j in 1..rCount
loop
fetch cur_my_cursor into tRecordSet;
update my_table_name mtn set mtn.unique_key = j
where mtn.field_one = tRecordSet.field_one
and mtn.field_two = tRecordSet.field_two
and mtn.field_three = tRecordSet.field_three
and mtn.field_four = tRecordSet.field_four
and mtn.field_five = tRecordSet.five;
dbms_output.put_line('Record id ' tRecordSet.field_one ' has been associated with an unique key of ' j );
end loop;
close cur_my_cursor; end;

Tuesday, June 05, 2007

New job at 2020Mobile Group

I have started a new era of my career with 2020 Mobile Group of Crewe as a Junior web developer.

http://www.2020mobile.com/

Azure Storage Account Types

Defferent Types of Blobs Block blobs store text and binary data. Block blobs are made up of blocks of data that can be managed individually...