Combine ScriptResource ajaxcontroltoolkit script

Task: Combine the AjaxControlToolkit Script.

Description: Combine the AjaxControlToolkit Script. As we can see when we use AjaxControl on our webpage it load with several javascript resources (ScriptResource.axd). For SEO purpose we need to minimize the several request. So that we can combine these script in a single request.

First we need to know which script's are required for our webpage. for that we need to use ScriptReferenceProfiler (it is available in codeplex). So download it from codeplex and stored the dll in our 'Bin' Folder. And Use below code to find the several request.



<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="c1" %>
<%@ Register Assembly="ScriptReferenceProfiler" Namespace="ScriptReferenceProfiler"    TagPrefix="srp" %>

<html>
<head runat="server"></head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="sm1" runat="server">
</asp:ScriptManager>
<srp:ScriptReferenceProfiler ID="ScriptReferenceProfiler1" runat="server" />
<%-- Below will be all controls with ajax controls whatever.. --%>
</form>
</body>
</html>

Result (On Browser):


11 references found on this page:
        <asp:ScriptReference name="MicrosoftAjax.js"/>
        <asp:ScriptReference name="MicrosoftAjaxWebForms.js"/>
        <asp:ScriptReference name="AjaxControlToolkit.Compat.Timer.Timer.js" assembly="AjaxControlToolkit, Version=3.0.30930.28736, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e"/>
        <asp:ScriptReference name="AjaxControlToolkit.Common.Common.js" assembly="AjaxControlToolkit, Version=3.0.30930.28736, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e"/>
        <asp:ScriptReference name="AjaxControlToolkit.Compat.DragDrop.DragDropScripts.js" assembly="AjaxControlToolkit, Version=3.0.30930.28736, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e"/>
        <asp:ScriptReference name="AjaxControlToolkit.ExtenderBase.BaseScripts.js" assembly="AjaxControlToolkit, Version=3.0.30930.28736, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e"/>
        <asp:ScriptReference name="AjaxControlToolkit.DragPanel.FloatingBehavior.js" assembly="AjaxControlToolkit, Version=3.0.30930.28736, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e"/>
        <asp:ScriptReference name="AjaxControlToolkit.DynamicPopulate.DynamicPopulateBehavior.js" assembly="AjaxControlToolkit, Version=3.0.30930.28736, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e"/>
        <asp:ScriptReference name="AjaxControlToolkit.RoundedCorners.RoundedCornersBehavior.js" assembly="AjaxControlToolkit, Version=3.0.30930.28736, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e"/>
        <asp:ScriptReference name="AjaxControlToolkit.DropShadow.DropShadowBehavior.js" assembly="AjaxControlToolkit, Version=3.0.30930.28736, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e"/>

        <asp:ScriptReference name="AjaxControlToolkit.ModalPopup.ModalPopupBehavior.js" assembly="AjaxControlToolkit, Version=3.0.30930.28736, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e"/>



Now we can combine the several Script request to one. For that we have to just copy the all found reference & use as below code .




<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="c1" %>

<html>
<head runat="server"></head>
<body>

<form id="form1" runat="server">

<asp:ScriptManager ID="sm1" runat="server">
<CompositeScript>
<Scripts>
      <asp:ScriptReference name="MicrosoftAjax.js"/>
      <asp:ScriptReference name="MicrosoftAjaxWebForms.js"/>
      <asp:ScriptReference name="AjaxControlToolkit.Compat.Timer.Timer.js" assembly="AjaxControlToolkit, Version=3.0.30930.28736, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e"/>
      <asp:ScriptReference name="AjaxControlToolkit.Common.Common.js" assembly="AjaxControlToolkit, Version=3.0.30930.28736, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e"/>
      <asp:ScriptReference name="AjaxControlToolkit.Compat.DragDrop.DragDropScripts.js" assembly="AjaxControlToolkit, Version=3.0.30930.28736, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e"/>
      <asp:ScriptReference name="AjaxControlToolkit.ExtenderBase.BaseScripts.js" assembly="AjaxControlToolkit, Version=3.0.30930.28736, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e"/>
      <asp:ScriptReference name="AjaxControlToolkit.DragPanel.FloatingBehavior.js" assembly="AjaxControlToolkit, Version=3.0.30930.28736, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e"/>
      <asp:ScriptReference name="AjaxControlToolkit.DynamicPopulate.DynamicPopulateBehavior.js" assembly="AjaxControlToolkit, Version=3.0.30930.28736, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e"/>
      <asp:ScriptReference name="AjaxControlToolkit.RoundedCorners.RoundedCornersBehavior.js" assembly="AjaxControlToolkit, Version=3.0.30930.28736, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e"/>
      <asp:ScriptReference name="AjaxControlToolkit.DropShadow.DropShadowBehavior.js" assembly="AjaxControlToolkit, Version=3.0.30930.28736, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e"/>
      <asp:ScriptReference name="AjaxControlToolkit.ModalPopup.ModalPopupBehavior.js" assembly="AjaxControlToolkit, Version=3.0.30930.28736, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e"/>
</Scripts>
</CompositeScript>
</asp:ScriptManager>
<%-- Below will be all controls with ajax controls whatever.. --%>
</form>
</body>
</html>


Now we can see in our browser the several ScriptResource combined in one request.

Create automated sitemap using asp.net

Task: Create automated sitemap dynamically using asp.net generic web handler.

Description: In E-Commerce website or blog we need to update sitemap regularly, instead of generating sitemap using third-party tool, we can generate sitemap dynamically using asp.net. Using "ashx" generic handler we can generate xml sitemap & using url rewriting we can rewrite "sitemap.ashx" for "sitemap.xml" request.


<%@ WebHandler Language="C#" Class="sitemap" %>

using System;
using System.Web;
using System.Text;
using System.Data;

public class sitemap : IHttpHandler {

    string currentTime = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ssZ");
    public void ProcessRequest (HttpContext context) {

        context.Response.ContentType = "text/xml";
        context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
        context.Response.Cache.SetAllowResponseInBrowserHistory(true);
        context.Response.Charset = "UTF-8";
        context.Response.Write("<?xml version='1.0' encoding='UTF-8'?><urlset xmlns='http://www.sitemaps.org/schemas/sitemap/0.9'>");
        context.Response.Write(sitemap());
        context.Response.Write("</urlset>");
    }

    public bool IsReusable {
        get {
            return false;
        }
    }
    public string sitemap()
    {
        string weburl = "http://hemantrautela.blogspot.com/";
        System.Text.StringBuilder sitemap = new System.Text.StringBuilder();
        sitemap.Append(@"<url>
        <loc>" + weburl + @"</loc>
        <lastmod>"+currentTime+@"</lastmod>
        <priority>1.00</priority>
        </url>");
        // Append more url in your sitemap here using database
        return sitemap.ToString();
    }

Get Blogger Post - Rss Feed in our website using javascript

Task: Get Blogger post - Rss Feed in our website using javascript.

Description: It shows 2 post and summery of post without any html tag like without any image. If you want to show all content then just use content as it is without any operation on it.


­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<div id="blog-feed"></div>
<script type="text/javascript">
  google.load("feeds", "1");

  var feedContainer=document.getElementById("blog-feed");
  var feedURL="https://hemantrautela.blogspot.com/feeds/posts/default?alt=rss";
  var postsReturned=2;
  var rssoutput="<div style='background-color:green'>";
  var stringWithHTML="";

  function rssFeedSetup(){
    var pullFeed=new google.feeds.Feed(feedURL)
    pullFeed.setNumEntries(postsReturned)
    pullFeed.load(showFeed)
  }

  function showFeed(result){
    if (!result.error){
      var thefeeds=result.feed.entries;
      for (var i=0; i<thefeeds.length; i++)
      {
       stringWithHTML = thefeeds[i].content.replace(/<\/?[a-z][a-z0-9]*[^>]*>/ig, ""); // remove html tag
      if(stringWithHTML.length>200) // just a summery of post
       {
       stringWithHTML= stringWithHTML.substring(0,200);
       var n = stringWithHTML.lastIndexOf(" ");
       stringWithHTML= stringWithHTML.substring(0,n)+"...";
       }
      rssoutput+="<div><a target='_blank' style='color:#ddd; font-size:16px;' href='" + thefeeds[i].link + "'rel='nofollow'>" + thefeeds[i].title + "</a><br/>" + stringWithHTML +"</div><hr/>"
      }
      rssoutput+="</div>";
      feedContainer.innerHTML=rssoutput;
    }
    else
      {
       rssoutput ="There was an error loading the blog posts.";
       feedContainer.innerHTML=rssoutput;
      }
    }
    window.onload=function(){
    rssFeedSetup()
  }

</script>­­­

Test .Net Framework is correctly installed and working fine

Task: Test .Net Framework is correctly installed and working fine.

Description: We can test by creating a aspx file using below code for checking .Net Framework is correctly installed and working fine.

<%@ Page Language="C#"%>
<%@ Import Namespace=Microsoft.Win32 %>
<script runat="server">
void Page_Load(Object s, EventArgs e)
{
    Label1.Text = "The "+Environment.Version+" .NET Framework <b>is</b> correctly installed and working";
    Label2.Text = "Running on machine " + Environment.MachineName + " at " + System.DateTime.Now.ToString();
 }   
</script>
<!DOCTYPE html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>ASP.NET Test</TITLE>
</HEAD>
<BODY>
<DIV align="center" style="margin-top:60px">
<table style="background-color:#ffffff; width:500px; border width:1px solid #666666;" cellpadding="8">
<tr>
<td style="font-family: arial; font-size: 17px; font-weight: bold; color: #000000;">
      ASP.NET Test
</td>
</tr>
</table>
<br><br>
<table style="background-color: #ffffff; width: 500px; border width: 1px solid #666666;" cellpadding="8">
      <tr>
      <td style="line-height:18px">
      This form will determine if .NET is working correctly
<hr noshade width='90%' size='1px'>
<asp:Label ID="Label1" Runat="server">If you can read this then .NET is <b>not</b> working correctly!</asp:Label>
<br><br>
      <asp:Label ID="Label2" Runat="server"></asp:Label>
      </td>
      </tr>
</table>
<p>&nbsp</p>
</div>
</BODY>
</HTML>