Friday, May 30, 2008

External Tables - Oracle 10.2E

Note: We have to create PRODUCTS directory and data.csv file should be avaible in the PRODUCTS directory
CREATE TABLE "PRODUCTDATA"."PRODUCTS"
(
"COL1" NUMBER(19,0),
"COL2" CLOB,
"COL3" VARCHAR2(25 BYTE),
"COL4" VARCHAR2(10 BYTE),

)
ORGANIZATION EXTERNAL
(

TYPE ORACLE_LOADER
DEFAULT DIRECTORY "PRODUCT"
ACCESS PARAMETERS
(

records delimited by newline
fields terminated by ','
missing field values are null

)
LOCATION
(

'data.csv'

)

);

Wednesday, May 28, 2008

Search Engine Optimization(SEO) and URL Rewriting using HTTPModules - Microsoft ASP.NET

Implement IHttpModule interface, which has Initialization(public void Init(HttpApplication context)) methods. In there we attach URL Rewrite method to AuthorizeRequest (for windows authorization)
Note:This is a simplified version. For more information please see references at the end of this post.
namespace Root.Client.SEOHandler
{
    public class SEOModule : IHttpModule
    {
        public void Init(HttpApplication context)
        {
            context.AuthorizeRequest += new EventHandler(SEOModuleAuthorizeRequest);
        }
        public void SEOModuleAuthorizeRequest(object sender, EventArgs e)
        {
            HttpApplication app = (HttpApplication)sender;
            /// 
            ///we must implement switches collection in CustomConfiguration as a property. 
            ///See complete description of how to implement a custom configuration 
            ///section in web.config please see 
            ///Adding new section to web.config - Microsoft ASP.NET
            ///
            List<Switch> switches =((CustomConfiguration) HttpContext.Current.Cache ["customConfiguration"]).Switches;
            for (int i = 0; i < switches.Count; i++)
            {
                string lookFor = string.Format("{0}/{1}",app.Context.Request.ApplicationPath,switches[i]);
                if(string.Compare(lookFor,app.Request.Path)==0)
                app.Context.RewritePath(
                string.Format("{0}/{1}","required_page.aspx", app.Context.Request.ApplicationPath);
            }
        }
    }
}

Register assembly in web.config

<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
  <system.web>
    <httpModules>
      <add name="SEOModule" type="Root.Client.SEOHandler.SEOModule" />
    </httpModules>
  </system.web>
</configuration>



Reference: URL Rewriting in ASP.NET

Tuesday, May 27, 2008

Adding new section to web.config - Microsoft ASP.NET

Create new section handeler for your new config section (implement IConfigurationSectionHandler interface)

Add a reference to your new config section and register it with the assembly

    public class CustomConfiguration : IConfigurationSectionHandler
    {
        public object Create(object parent, object input, XmlNode node)
        {
            /// 
            /// add your logic here ...
            /// 
            return new object();
        }
    }

Set custom configuration section in application start event(global.ascx) and add it to the cache

<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
  <configSections>
    <section name="customConfiguration" 
             type="Root.Client.Configuration.CustomConfiguration, Root.Client.Configuration" />
  </configSections>
  <customConfiguration>
    .....
    //
    // your custom configuration
    //
    .....
    <customConfiguration>
</configuration>
public override void Application_Start(object sender, EventArgs e)
{
    HttpContext.Current.Cache.Insert("CustomConfiguration", 
        ConfigurationSettings.GetConfig("customConfiguration"as CustomConfiguration);
}

Friday, May 23, 2008

How to get generated html of a page and change it.

public override void Render(System.Web.UI.HtmlTextWriter writer)
{
    StringBuilder sb = new StringBuilder();
    HtmlTextWriter htw = new HtmlTextWriter(new StringWriter(sb));
    base.Render(htw);
    string html = sb.ToString();
    ///
    /// Example
    /// 
    html.Replace("<b>""<strong>");
    html.Replace("</b>""</strong>");
    /// 
    /// Insert the meta tags
    /// Insert webtrends meta tags
    /// Move hidden system inserted fields
    /// Move viewstate
    /// Perform SEO checks
    /// And finally, write the HTML to original writer
    writer.Write(html);
}

Thursday, May 22, 2008

ASP.NET Master Pages and overriding attributes of Body tag

Default.Master page

<body id="MasterPageBody" runat="server" >
</body>

Code behind

public HtmlGenericControl Body
{
     getreturn this.MasterPageBody}
     setthis.MasterPageBody = value;}
}

Content pageRegister

<%@ MasterPage VirtualPath="~/virtual/path/to/your/master/page" %>

Code Behind

public void Page_Load(object sender, EventArgs e)
{
     this.MasterPageBody.Attributes
            .Add("onload","javascript:alert('I am here')");
}
 

Tuesday, May 13, 2008

How to jQuery with Asp.net Ajax

Symptom:

<script language="javascript">
    $(document).ready(function () {
        ///
        ///execute only when a full page refresh.
        ///
    });
</script>

ready() function executes only when a page does a full page refresh not when it does a partial page refresh inside a update panel
Solution:

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <div class="rounded">
            Welcome to AJAX.Net
            <asp:Button ID="Button1" runat="server" Text="Button" CssClass="button" />
        </div>
        <script type="text/javascript" language="javascript">
            Sys.Application.add_load(functionNeedToBeExecuted);
            function functionNeedToBeExecuted() {
                // code need to be executed ....
            }
        </script>
    </ContentTemplate>
</asp:UpdatePanel>

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;
}

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...