DNS Cache Pollution

Standard

Your DNS cache stores the locations (IP addresses) of webservers that contain pages which you have recently viewed. If the location of the web server changes before the entry in your DNS cache updates, you will be unable to access the site.

If you encounter a large number of HTTP 404 Error, you may need to clear your DNS cache. Once you clear your DNS cache, your computer will query nameservers for the new DNS information.

Windows 98/NT/2000/XP Flush DNS

Flushing the DNS on Windows is an easy process, outlined below is the steps that should be run if you wish to clear your DNS cache.

  1. Open up a command prompt (Start > Run > cmd.exe > OK).
  2. Type in the command ipconfig /flushdns
Windows XP Flush DNS - Step 1 - Click Start Windows XP Flush DNS - Step 2 - Click All Programs Windows XP Flush DNS - Step 3 - Click Accessories and run Command Prompt Windows XP Flush DNS - Step 4 - Command Prompt will open Windows XP Flush DNS - Step 5 - Type 'ipconfig /flushdns' Windows XP Flush DNS - Step 6 - The DNS is now flushed Windows XP Flush DNS - Step 7 - Type 'exit' to close the Command Prompt

Windows Vista / Windows 7 Flush DNS

Flushing DNS on newer versions of Windows is almost as easy as the earlier versions but due to Microsoft’s security additions you must run the command prompt with administrator privileges.

  1. Click the start button and navigate to the command prompt (Start > All Programs > Accessories > Command Prompt)
  2. Make sure that you right click on the command prompt application and choose “Run as Administrator”
  3. Type in the command ipconfig /flushdns
Windows Vista / Windows 7 Flush DNS - Step 1 - Click Start and click All Programs Windows Vista / Windows 7 Flush DNS - Step 2 - Click Accessories Windows Vista / Windows 7 Flush DNS - Step 3 - Click Command Prompt Windows Vista / Windows 7 Flush DNS - Step 4 - Command Prompt will open Windows Vista / Windows 7 Flush DNS - Step 5 - Type 'ipconfig /flushdns' Windows Vista / Windows 7 Flush DNS - Step 6 - The DNS is now flushed Windows Vista / Windows 7 Flush DNS - Step 7 - Type 'exit' to close the Command Prompt

Note: It is also possible to type in cmd into the Windows Vista / Windows 7 start menu search field and then right click on the cmd.exe result instead of having to navigate through the various sub menus.

Windows 8 / Windows 8.1 Flush DNS

Flushing the DNS cache on Windows 8 and Windows 8.1 is a very easy process. Due to system security permissions, you must ensure that you run the command prompt as an administrator user.

  1. Ensure that you’re on the Windows 8 Start Screen.
  2. Simply type cmd and the Windows search bar will appear on the right hand side with search results.
  3. Right click on Command Prompt and click Run as administrator.
  4. Type in the command ipconfig /flushdns
Windows 8 / Windows 8.1 Flush DNS - Step 1 - Begin on the Windows 8 Start Screen Windows 8 / Windows 8.1 Flush DNS - Step 2 - Type 'cmd' Windows 8 / Windows 8.1 Flush DNS - Step 3 - Right click 'Command Prompt' and choose 'Run as administrator' Windows 8 / Windows 8.1 Flush DNS - Step 4 - Command Prompt will open Windows 8 / Windows 8.1 Flush DNS - Step 5 - Type 'ipconfig /flushdns' Windows 8 / Windows 8.1 Flush DNS - Step 6 - The DNS is now flushed Windows 8 / Windows 8.1 Flush DNS - Step 7 - Type 'exit' to close the Command Prompt

Performance Enhancement in asp.net [Client Side]

Standard

Performance Enhancement

1. Minify Resources (HTML, CSS, and JavaScript):¨

Minification refers to the process of removing unnecessary or redundant data without affecting how the resource is processed by the browser – e.g. code comments and formatting, removing unused code, using shorter variable and function names, and so on.

2. Enable Compression:

¨All modern browsers support and automatically negotiate gzip compression for all HTTP requests. Enabling gzip compression can reduce the size of the transferred response by up to 90%, which can significantly reduce the amount of time to download the resource, reduce data usage for the client, and improve the time to first render of your pages.

Solution:

¨All excel templates/uploaded files etc in application

3.Optimize Images:

¨Images often account for most of the downloaded bytes on a page. As a result, optimizing images can often yield some of the largest byte savings and performance improvements: the fewer bytes the browser has to download, the less competition there is for the client’s bandwidth and the faster the browser can download and render content on the screen.

Solution

¨Sprites
¨Save Image as font [using @font-face]
¨Using SVG’s [bit controversial]

4.Optimize CSS Delivery:

¨Before the browser can render content it must process all the style and layout information for the current page. As a result, the browser will block rendering until external stylesheets are downloaded and processed, which may require multiple roundtrips and delay the time to first render.

¨If the external CSS resources are small, you can insert those directly into the HTML document, which is called inlining. Inlining small CSS in this way allows the browser to proceed with rendering the page.

¨If the amount of data required exceeds the initial congestion window, it will require additional round trips between your server and the user’s browser. For users on networks with high latencies such as mobile networks this can cause significant delays to page loading.

5. Reduce the size of the above-the-fold content:

Solution:

To make pages load faster, limit the size of the data (HTML markup, images, CSS, JavaScript) that is needed to render the above-the-fold content of your page. There are several ways to do this:

¨Structure your HTML to load the critical, above-the-fold content first

¨Reduce the amount of data used by your resources

6.Remove Render-Blocking JavaScript:

¨Before the browser can render a page it has to build the DOM tree by parsing the HTML markup. During this process, whenever the parser encounters a script it has to stop and execute it before it can continue parsing the HTML. In the case of an external script the parser is also forced to wait for the resource to download, which may incur one or more network roundtrips and delay the time to first render of the page.

Solution:
¨Inline JavaScript [if few lines of code]
¨<script async src=”my.js”>

7. Working with the DOM:

¨Working with the DOM can cause browser reflow, which is the browser’s process of determining how things should be displayed. Directly manipulating the DOM, changing CSS styles of elements, and resizing the browser window can all trigger a reflow. Accessing an element’s layout properties such as offsetHeight and offsetWidth can also trigger a reflow. Because each reflow takes time, the more we can minimise browser reflow, the faster our applications will be.

function addAnchor(parentElement, anchorText, anchorClass)

{

var element = document.createElement(‘a’); parentElement.appendChild(element);

element.innerHTML = anchorText;

element.className = anchorClass;

}

Solution

function addAnchor(parentElement, anchorText, anchorClass)

{

var element = document.createElement(‘a’);

element.innerHTML = anchorText;

element.className = anchorClass;

parentElement.appendChild(element);

}

8. Avoid Plugins:

¨Plugins help the browser process special types of web content, such as Flash, Silverlight, and Java. Most mobile devices do not support plugins, and plugins are a leading cause of hangs, crashes, and security incidents in browsers that provide support.

Solution:

¨Use HTML5
¨Removal of activeX control from application

 

Dev Tool: Client Side Performance Evaluation

Page Speed Insight [Extension by Google Chrome]
¨Minimise payload
¨Minimise delay in page load
¨Other

Notes prepared From Google Blog

Ten Simple Tips to Improve Performance of an ASP.NET Website

Standard
Tips to improve the performance of ASP.NET web applications

Introduction

In this tip, we will look at various aspects of improving the performance of ASP.NET web applications.

Performance is an important aspect of the modern day web application development. Here are some tips that you can consider while making a better performing website.

1. Upgrade Your ASP.NET Framework

Check your .NET framework. If you can upgrade your site to use .NET 4.5, then it has some great performance optimizations. .NET 4.5 has a new Garbage Collector which can handle large heap sizes (i.e., tens of gigabytes). Some other improvements are Multi-core JIT compilation improvements, and ASP.NET App Suspension. These optimizations do not require code changes.

2. Caching

  1. Use output caching – Use output caching for regularly used views or pages which have no dynamic updates. The easiest way to implement cache on MVC view is to add an [OutputCache] attribute to either an individual controller action or an entire controller class. Here is a controller action Index() that will be cached for 15 seconds.
    [OutputCache(Duration = 15, VaryByParam = "None")]
    public ActionResult Index(string Id)
    {
    
    }
  2. Use Data caching – Reduces the database or the disk I/O by caching the regularly used data to in-memory cache. This avoids repeated queries for data, and it can improve performance and scalability. In addition, caching makes data available when the data source is temporarily unavailable. The .NET Framework provides classes that enable you to use caching facilities in ASP.NET applications. These classes are defined in the System.Runtime.Caching namespace.

3. Always keep CSS and JavaScript External

Never add any JavaScript or inline style information within the views. That would regenerate the view each time and you would miss out on the benefits of the Caching. Hence always keep JS and CSS as separate files and add them as links in the view.

4. File Compression

There are often requests to the web server with lot of static content. These contents can be compressed thereby reducing the bandwidth on requests. The following setting is only available in II7 and later.

<configuration>  
    <system.webServer>    
        <urlCompression doStaticCompression=&rdquo;true&rdquo;       doDynamicCompression=&rdquo;true&rdquo; />  
    </system.webServer> 
</configuration>

The urlCompression name sounds strange but it is not really the compressing of URLs. It means compressing or gzipping the content that is sent to the browser. By setting to true/enabling, you can gzip content sent to the browser while saving lots of bandwidth.

5. Bundling and Minification

The custom CSS files and the JavaScript files should be bundled into a single large file (reduces the number of HTTP requests) and also minified (reduces the size of the data transferred over the wire).

6. CDN (Content Delivery Network)

All the 3rd party JavaScript files such as JQuery, Knockout should always use the CDN instead of the web application server. CDN Servers are dedicated to deliver the static content and is always faster than your own host. There is a very high probability that the client (browser) would have already cached the JavaScript as part of other web application since most of them use the same CDN URL.

7. Control Image Requests

There are couple of ways to do this.

  1. Image sprite – With image sprite, you can combine multiple different images into a single large image. Then use CSS to reposition those images within the site.
  2. Base64 Data URIs – With this option, you would never make any requests to the server to obtain any images.

8. Script Rendering Order

Move the script tags <script> to the very bottom of the page. The reason this is important is because during the rendering, when the browser comes across a <script> tag, it stops to process the script and then moves ahead. If you put the script tags at the bottom of the page, the page/HTML will render faster and the scripts can execute after the DOM elements have loaded. Sometimes moving the script to the bottom of the page is not possible as some DOM elements or CSS may depend on these scripts, so they can be rendered. In such cases, you could move those scripts further up the page.

There are some other ways:

  1. defer attribute
    <script src=&rdquo;some.js&rdquo; defer>
    
    </script>

    Using the defer attribute, you can specify the script not to run until the page has been fully loaded.

  2. async attribute
    <script src=&rdquo;some.js&rdquo; async>
    
    </script>

    Using the async tag, the scripts will be run asynchronously, as soon as it is available.

9. Removing Default HTTP Modules in ASP.NET

ASP.NET has many http modules waiting for request to be processed and would go through the entire pipeline even if it’s not configured for your application.

All the default modules will be added in the machine.config place in“$WINDOWS$\Microsoft.NET\Framework\$VERSION$\CONFIG directory. One could improve the performance by removing those modules which you wouldn’t require.

10. Compile in Release Mode

Always set the build configuration to release mode for the website.

In this tip, we looked at some of the approaches that you can take to make optimized and better performing web sites. This included, reducing number of requests to the server, changes to the .NET framework, and compressing techniques.

 

About the Author

Jithin Geroge


United States United States

Debug ASP.NET MVC application with Glimpse

Standard

Introduction

For debugging and diagnostic information for ASP.NET apps, Glimpse is a NuGet packages that provides detailed performance,  It is fast, super-light and serve developer with best visual display for all performance metrices. It helps developer to debugg performance of asp.net application through data access layer to presentation layer, debugging your ajax call is a plus feature of this extension. You dont need to read severl manual pages in order to use this extension as compare to fiddler 🙂

Background

The best part of Glimpse is to debug and analyze performane of all server side functionality as for client side we have firebug, fiddler and F-12 development tool.

Using the code

For tutorial, I am going to use sample Contoso University Project available at MSDN.

1. Open ContosoUniversity.sln in Visual Studio, It is implemented using asp.net MVC and Entity Framework 6

2. Click on Manage NuGet Packages in Project Tab

3a. NuGet will look for your project configuration and will recommend available glimpse extensions, type glimpse in search box

3b. You may perform same function through NuGet Package Manager Console

Console Command For MVC5: Install-Package Glimpse.MVC5
Console Command For MVC4: Install-Package Glimpse.MVC4
Console Command For MVC3: Install-Package Glimpse.MVC3
Console Command For WebForms: Install-Package Glimpse.Webforms

Console Command For ADO.NET: Install-Package Glimpse.Ado
Console Command For Entity Framework 6: Install-Package Glimpse.EF6
Console Command For Entity Framework 5: Install-Package Glimpse.EF5
Console Command For Entity Framework 4 or 3: Install-Package Glimpse.EF43

If you are installing first time, it will automatically include Glimpse.AspNet and Glimspe.Core in order to resolve dependency.

4. Glimpse refrences will be added in project:

and web.config will be updated as below:

<configuration>
  <configSections>
    <section name="glimpse" type="Glimpse.Core.Configuration.Section, Glimpse.Core" />
  </configSections>
  <system.web>
    <httpModules>
        <add name="Glimpse" type="Glimpse.AspNet.HttpModule, Glimpse.AspNet" />
    </httpModules>
        <httpHandlers>
            <add path="glimpse.axd" verb="GET" type="Glimpse.AspNet.HttpHandler, Glimpse.AspNet" />
        </httpHandlers>
  </system.web>
  <system.webServer>
         <modules>
            <add name="Glimpse" type="Glimpse.AspNet.HttpModule, Glimpse.AspNet" preCondition="integratedMode" />
        </modules><handlers>
            <add name="Glimpse" path="glimpse.axd" verb="GET" type="Glimpse.AspNet.HttpHandler, Glimpse.AspNet" preCondition="integratedMode" />
        </handlers>
  </system.webServer>
  <glimpse defaultRuntimePolicy="On" endpointBaseUri="~/Glimpse.axd">
  </glimpse>
</configuration>

 

5. Build the project and open view Home/About in browser

6. Type /Glimpse.axd after available URL of your project

7. Click on Turn Glimpse On in order to debugg your application for better performance

8. Glimpse will be available at bottom right of your browser

9. When you hover on HOST section of dashboard, It will show all trvial data about total action time, number of db connections opened, number of quieires served by controller to render this view and much more

10. Click on ‘g’ at the bottom right on toolbar and explore all server side debugging features. Through Glimpse you may go through cache entries.

11. Glimpse will help you out to analyze performance of controller methods by displaying time elapsed for each method of controller.

12. This extension will help developer in displaying all key-values of cookie, parameters of query string, attributes of http header.

13. Best part of Glimpse is to display duration of each sql query under SQL tab.

14. Then comes timeline analysis of execution of each events, this will help developer to look for area of concern in more prominent way.

Points of Interest

There might be chance you are not using entity framework in your project, then for ADO.NET, to retrieve data for the SQL tab, Glimpse attaches itself by providing its own GlimpseDbProviderFactory which wraps the standard ones. This lets it collect information about how you’re using your data connections. If you’re not using an ADO connection that uses the DbProviderFactories, Glimpse won’t collect any data for the SQL tab.

DbProviderFactory factory = DbProviderFactories.GetFactory("System.Data.SqlClient");
            using (var connection = factory.CreateConnection())
            {
                using (var command = factory.CreateCommand())
                {
                    try
                    {
                        connection.ConnectionString = connString;
                        command.Connection = connection;
                        command.CommandType = CommandType.StoredProcedure;
                        command.CommandText = "StoreProcedureName";

                        var parameters = new[]{
                             new SqlParameter(){ ParameterName="@param1", Value = param1 }
                        };
                        command.Parameters.AddRange(parameters);
                        command.CommandTimeout = ConnectionTimeOut;
                        connection.Open();
                        
                        using (var myReader = DbProviderFactories.GetFactory("System.Data.SqlClient").CreateDataAdapter())
                        {
                            //code here
                        }
                        
                    }
                    finally
                    {
                        if (command.Connection.State == ConnectionState.Open)
                            command.Connection.Close();
                    }
                }
            }

Code available @Github: https://github.com/m-hassan-tariq/GlimpseforMVCContosoUniversity

History

Vesrion 1.0

About the Author

Muhammad Hassan Tariq

Software Developer TRG/IBEX-Global
Pakistan Pakistan