Thursday, December 11, 2008

Managed Debugging Assistants - Microst .NET Framework

The CLR has been unable to transition from COM context 0x1a1a90 to COM context 0x1a1c00 for 60 seconds.
The thread that owns the destination context/apartment is most likely either doing a none pumping. This situation generally has a negative performance impact and may even lead to the application becoming non responsive or memory usage accumulating continually over time. To avoid this problem, all single threaded apartment (STA) threads should use pumping wait primitives (such as CoWaitForMultipleHandles) and routinely pump messages during long running operations.

Possible Reasions:

1. Deadlock
2. A very long operation, which worth more than 60 seconds.

If execution does not trap in a deadlock
It is possible to execute an very long operation by Disabling Visual Studio’s MDA (Managed Debug Assistant)
Visual Studio 2005: To disable MDA please add or edit following registry key:

1. Run > regedit
2. Navigate to > HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework
3. Set [MDA=”0”]
4. Or create MDADisable.reg file and paste following text and run it

Windows Registry Editor Version 5.00

Please note: Always it is useful to leave MDA enable for efficient debugging. To enable MDA please set MDA=”1”

Diagnosing Errors with Managed Debugging Assistants (MSDN)

Friday, September 12, 2008

Adding page specific scripts (java scripts), styles to web content pages: Microsoft ASP.NET

protected void Page_Load(object sender, EventArgs e)
    /// modify existing meta defined in master page 
    HtmlMeta meta = Page.Header.FindControl("metaRedirect"as HtmlMeta;
    foreach (string metadata in MetaDataCollection)
        meta.Content += metadata;
    /// adding content specific styles into content page's header 
    HtmlLink link = new HtmlLink();
    link.Href = "~/styles/default.css";
    link.Attributes["rel"] = "stylesheet";
    /// adding content specific scripts into content page’s header 
    HtmlGenericControl script = new HtmlGenericControl("script");
    script.Attributes["src"] = Page.ResolveUrl("~/scripts/default.js");
public IEnumerable<string> MetaDataCollection { getset; }

Tuesday, August 26, 2008

Could not find part of the path: Microsoft ASP.NET

Symptom: When try to view the source of an .aspx or masterpage it highlight the first line (page or master) and in the little popup it says "could not find part of the path"

Resolution: clear the content of the folder
C:\Documents and Settings\{USERNAME}\Application Data\Microsoft\VisualStudio\8.0\ReflectedSchemas

Thursday, August 21, 2008

Protect file types (.xml, .doc, .html, .pdf etc.) using ASP.NET authentication: Microsoft ASP.NET

Because requests to .xml, .doc, .html, .pdf etc handled by the IIS instead of ISAPI module first it is required to configure specified extensions to be handled by the ISAPI module

How to configure custom file extension to be handled by the ISAPI module

In IIS (run ‘inetmgr’)
  1. Locate the website (or virtual directory, which configured as a web application) you want to configure custom file extensions to be secured.
  2. Right click and find the ‘Virtual Directory’ tab under properties
  3. In ‘Virtual Directory’ tab click configuration
  4. Add extension (ex: .xml) and browse aspnet_isapi.dll from the usual location (C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727). If you can’t find the exact directory perform a search and locate it.
  5. Uncheck ‘check that file exist’ checkbox just in case of request to a non existing file. then press ok
  6. If it is local it is recommend to do a IIS reset (run ‘iisreset’) if not if it is the production server or UAT, recycle the application pool
For securing asp web applications: please review my previous post - ASP.NET Authentication

Tuesday, August 12, 2008

The following module was built either with optimizations enabled or without debug information: Microsoft ASP.NET

Symptom: Solution includes a web project and a class library(may be more). But can not hit any break points in class library as it says ‘no symbols has been loaded’

  • Try 'Configuration Manager' – make sure all project configurations are set to ‘debug mode’ and clean the solution
  • Try web config – make sure you have set [debug=’true’] in compilation section.
  • Remove the assembly reference and try adding it again.

Friday, August 08, 2008

Oracle replace (XML) - Oracle 10.2 E

update affiliate set config = REPLACE(config, 'old.text', 'new.text') where id ='SADB12345';

Wednesday, July 02, 2008

Remote Debugging in Microsoft ASP.Net

Debug an application or a web service, which runs in a remote host
(version of code does not need to be a debug built)
  1. Install Visual Studio Remote Debugging Monitor(MSVSMON) in the remote host (server) – recommend to install as a windows application and make sure MSVSMON is listening for connections
  2. Start Visual Studio and pull up source code for the relevant application - if you try to add break points to irrelevant code, break points will not be reached.
  3. From main menu select -> Debug >> Attach to Process
    For the Qualifier use domain\ (Ex CSG\Charith.Gunasekara@CSG-UATWebTest) and refresh process list
  4. Select required process from the (in this case work process(aspnet_wp.exe))
    Try inserting couple of breakpoints to the source code and browse the website.
  5. This is useful if you cant replicate errors in local machine while investigating exceptions
Reference: Set Up Remote Debugging (MSDN)

Monday, June 16, 2008

XPathNodeIterator - Microsoft ASP.NET

XPathNodeIterator iterator = navigator.Select(
while (iterator.MoveNext())
    XPathNodeIterator products = 
    while (products.MoveNext()) 
        XPathNavigator productNavigator = 
            products.Current; XPathNodeIterator prodDetails = 
                productNavigator.SelectDescendants(XPathNodeType.Text, false); 
                    String name, link; 
        while (prodDetails.MoveNext()) 
            if (prodDetails.CurrentPosition == 1) name = prodDetails.Current.Value; 
                if (prodDetails.CurrentPosition == 2) link = prodDetails.Current.Value;
    /// utilize your strings here

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
"COL1" NUMBER(19,0),



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





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]);
                string.Format("{0}/{1}","required_page.aspx", app.Context.Request.ApplicationPath);

Register assembly in web.config

<configuration xmlns="">
      <add name="SEOModule" type="Root.Client.SEOHandler.SEOModule" />

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="">
    <section name="customConfiguration" 
             type="Root.Client.Configuration.CustomConfiguration, Root.Client.Configuration" />
    // your custom configuration
public override void Application_Start(object sender, EventArgs e)
        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));
    string html = sb.ToString();
    /// Example
    /// 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

Thursday, May 22, 2008

ASP.NET Master Pages and overriding attributes of Body tag

Default.Master page

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

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)
            .Add("onload","javascript:alert('I am here')");

Tuesday, May 13, 2008

How to jQuery with Ajax


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

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

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

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

Sunday, March 23, 2008

ASP.NET Authentication


Securing location of an 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


    <user name="Mary" password="GASDFSA9823598ASDBAD">
      <user name="John" password="ZASDFADSFASD23483142">

if (FormsAuthentication.Authenticate(this.Login1.UserName, this.Login1.Password))
    FormsAuthentication.RedirectFromLoginPage(this.Login1.UserName, false);
    <compilation batch="false" debug="true" defaultlanguage="c#">
      <authentication mode="Forms">
        <forms name="cornerstone" 
          <credentials passwordformat="Clear">
            <user name="user1" password="password1">
              <user name="user2" password="password2">
        <allow users="*">
  <location path="admin">
        <deny users="?">

iPhone Launch Screen Sizes

iPhone Portrait iOS 8 Retina HT 5.5 = 1242 X 2208 Retna HD 4.7 = 750 X 1134 iPhone Landscape iOS 8 Retina HD 5.5  2208 X 1242 iPho...