Jack @ ASP.NET

As a software engineer, I focus on .NET, especially asp.net, C#, WCF and so on, and I am also very interested in Search Engine Optimization.

Entries Tagged ‘asp.net’

SEO via IIS and ASP.NET 4

IIS_SEO_toolkit_asp.net Why SEO?

Search engine optimization (SEO) is important for any publically facing web-site.  A large percentage of traffic to sites now comes from search engines, and improving the search relevancy of your site will lead to more user traffic to your site from search engine queries (which can directly or indirectly increase the revenue you make through your site).

IIS Search Engine Optimization (SEO) Toolkit

The SEO Toolkit helps you improve your Website’s relevance in search results by recommending how to make your new or existing site content and structure more search engine-friendly. It works on any Website on the Web. Best of all – it’s a small, lightweight free download!

ASP.NET 4 SEO Improvements

ASP.NET 4 includes a bunch of new runtime features that can help you to further optimize your site for SEO.  Some of these new features include:

  • New Page.MetaKeywords and Page.MetaDescription properties
  • New Response.RedirectPermanent() method
  • New URL Routing support for ASP.NET Web Forms

 

You can use the above routes and methods for both ASP.NET Web Forms and ASP.NET MVC based URLs.

ASP.NET 4 includes a bunch of feature improvements that make it easier to build public facing sites that have great SEO.  When combined with the SEO Toolkit, you should be able to use these features to increase user traffic to your site – and hopefully increase the direct or indirect revenue you make from them.

  • Digg
  • DZone
  • Yahoo Buzz
  • Delicious
  • Reddit
  • StumbleUpon
  • SmakNews
  • Jumptags
  • Ping
  • Share/Bookmark

How to Enable the ASP.NET Ajax script loader

An important feature of the script loader is the separation of the script meta-data from the script code itself. The meta-data can include the name of the script, its dependencies, instructions on how to figure out if it’s already loaded, its debug and release URL patterns and a declaration of the lazy components and plug-ins it introduces. The script loader can also handle composite scripts but I won’t cover that in this post.

  • The name of the script is what will be used to reference it from other scripts and to generate the URL from a pattern. It shouldn’t include the “.js” extension.
  • The dependencies and executionDependencies are each a simple array of script names that the script depends on. I’ll explain the difference in a minute.
  • The is loaded criterion is a JavaScript expression that returns true if the script is already loaded. This is usually a test on an object that the script file defines. For example, the “templates” script uses !!(Sys.UI && Sys.UI.Templates). It can assume Sys because it’s defined by start.js.
  • Debug and release patterns are expressions that enable the framework to map script names into debug and release URLs. The ASP.NET Library uses “%/MicrosoftAjax{0}.debug.js” and “%/MicrosoftAjax{0}.js” where % gets replaced with the path where the script loader was downloaded from (this can be CDN or local) and {0} gets replaced with the script name. You can create your own pattern or just provide fixed URLs if you have only one script file. The debug pattern is optional.
  • Lazy components and plug-ins are helpers that the script loader can create for you and that enable developers to start using your components before they are even loaded and hide the script loading aspects as much as possible. For example, it’s that feature that enables you to write this while still having only start.js loaded:
    Sys.create.dataView("#myDataView", {
        data: myData
    });

    The code that needed to be written for this helper to be created was this:

    behaviors: ["Sys.UI.DataView"]

    This gets automatically transformed by the script loader into the Sys.create.dataView method, before it even tries to load the actual script that defines Sys.UI.DataView. And if you have jQuery loaded as well, you’ll also get a jQuery plug-in out of it for free, which means that you can do:

    $(".data").dataView({data: myData});

    and instantiate DataView controls over the results of a selector query in one operation. Groovy. Of course, you can do the same with the behaviors and controls that you write in your own scripts, with lots of options to customize names, add parameters, etc.

In the case of the class library code, here’s the meta-data declaration code that I had to write:

Sys.loader.defineScript({
  name: "classBrowserTree",
  releaseUrl: "%/TreejQuery.js",
  executionDependencies:    ["jQuery", "Templates", "ComponentModel"],
  isLoaded: !!(window.jQuery &&    window.jQuery.fn.classBrowserTreeView)
});

This declares that my script, named “classBrowserTree”, can be found at the URL TreejQuery.js relative to the base URL of the script loader, that it depends on jQuery, Templates and ComponentModel (which themselves have their own dependencies) and that the loader can determine whether it’s already loaded by evaluating the classBrowserTreeView jQuery plug-in.

Now, loading that script and all its dependencies is as simple as writing this:

Sys.require(Sys.scripts.classBrowserTree);

Notice that as you’re typing this, you actually get full IntelliSense in Visual Studio on the name of the script, which is great for speed and to avoid typos:ScriptLoaderIntelliSense

One of the things that enable the script loader to do its job is a special way to write your script that makes it possible to separate the loading and parsing of the code from its execution.

Don’t freak out (yet) though as the code you have to introduce is very lightweight and it doesn’t prevent your script from being loaded without the script loader (with a plain old script tag for example).

Reversely, a script that doesn’t have the special script loader code can be handled by the script loader but its dependencies must be declared using “dependencies” instead of “executionDependencies” in the meta-data declaration code, which will in effect disable the more advanced features of the script loader such as parallel loading.

The special code in question is the following:

(function() {
  function execute() {
    // Your code goes here.
  }
  if (window.Sys && Sys.loader) {
    Sys.loader.registerScript(      "classBrowserTree", null, execute);
  }
  else {
    execute();
  }
})();

What you see here is a (function() {…})(); wrapper, which is standard practice to isolate code from the global namespace (essentially, it’s a local scope); we also have another named scope in there that we arbitrarily call “execute” (but the name doesn’t matter). This is where you’ll typically put your actual code. Then we have the bootstrapping code that looks for the script loader. If it isn’t found, the code in the execute function is immediately run. If it is found, the execute function is registered with the script loader but is not immediately executed.

This wrapper code is what enables the script loader to do its magic. Thanks to this little bit of code, it doesn’t care at all in what order the scripts are being loaded, because it can delay the time when any script actually gets executed until all its dependencies have been successfully loaded.

This also allows the script loader to load scripts in parallel, even if one depends on another. Normally a script loader would have to download a dependent script first and wait for it to completely load before loading the next script. This ‘serializes’ the loading process and is not good for performance. Modern browsers can download 6 to 8 scripts simultaneously. Separating the loading of a script from its execution allows the loader to take advantage of that, and in most cases, even complex dependency trees can be downloaded completely in parallel, meaning the total time is not the sum of each script, but only the longest one.

  • Digg
  • DZone
  • Yahoo Buzz
  • Delicious
  • Reddit
  • StumbleUpon
  • SmakNews
  • Jumptags
  • Ping
  • Share/Bookmark

Build your own FaceBook applications with ASP.NET, ASP.NET MVC, WinForms or Silverlight !

Another great project in codeplex: http://facebooktoolkit.codeplex.com/

This toolkit is provided as a Facebook Client Library similar to Facebook’s PHP Client Library or Facebook’s JavaScript library. The goal is to enable .NET developers to quickly and easily leverage the various features of the Facebook Platform. This toolkit has evolved over time with input from the community and from Microsoft. The latest release (v3.0) includes new architectural improvements and provides an asynchronous interface for using the toolkit from Silverlight and from WPF.

The main entry point is the API (Facebook.Rest.Api) class in the Facebook.dll assembly. This class wraps the Facebook REST API and provides an easy to use interface for calling the different methods currently available in the Facebook API. We’ve also provided samples and tools for helping develop Facebook applications in the various .NET platforms including: ASP.NET, Silverlight, WPF and WinForms. Additionally, we’ve provided all the source code for the API, components, controls, and samples for you to explore.

The toolkit is comprised of the following core assemblies:

  • Facebook.dll: This is the main assembly that will be used by all applications. This has all the logic to handle communication with the Facebook application. This assembly also has specific support of XAML applications (Silverlight and WPF) to enhance the Facebook platform to make databinding and data caching easier.
  • Facebook.Silverlight.dll: This is the Silverlight version of the main assembly that will be used by all Silverlight applications. This has all the logic to handle communication with the Facebook application. This assembly also has specific support of XAML applications to enhance the Facebook platform to make databinding and data caching easier. The REST API in this assembly is Asynchronous only.
  • Facebook.Web.dll: This assembly should be used by Canvas applications. The main functionality supported in this assembly is to encapsulate the handshake between the Facebook application and a canvas application (both FBML and IFrame)
  • Facebook.Web.Mvc.dll: Provide a support building canvas applications using ASP.NET MVC. Separated from Facebook.Web.dll to avoid all developers from needing to install the MVC bits.
  • Facebook.Winforms.dll: This assembly provides support for writing Facebook applications using Winform technology. This provides a Component that wraps the API to make it easier to use from Winforms. This also contains some user controls to help display Facebook data easily.
  • Digg
  • DZone
  • Yahoo Buzz
  • Delicious
  • Reddit
  • StumbleUpon
  • SmakNews
  • Jumptags
  • Ping
  • Share/Bookmark

Changes in asp.net MVC Preview 2

Helpers now return an MvcHtmlString object

In order to take advantage of the new HTML-encoding expression syntax in ASP.NET 4, the return type of the HTML helpers is now MvcHtmlString instead of a string. Note that if you use ASP.NET MVC 2 and the new helpers with ASP.NET 3.5, you will not be able to take advantage of the HTML-encoding syntax; the new syntax is available only when you run ASP.NET MVC 2 on ASP.NET 4.

JsonResult now responds only to HTTP POST requests

In order to mitigate JSON hijacking attacks that have the potential for information disclosure, by default, the JsonResult class now responds only to HTTP POST requests. AJAX GET calls to action methods that return a JsonResult object should be changed to use POST instead. If necessary, you can override this behavior by setting the new JsonRequestBehavior property of JsonResult. For more information about the potential exploit, see the blog post JSON Hijacking on Phil Haack’s blog.

Model and ModelType property setters on ModelBindingContext are obsolete

A new settable ModelMetadata property has been added to the ModelBindingContext class. The new property encapsulates both the Model and the ModelType properties. Although the Model and ModelType properties are obsolete, for backward compatibility the property getters still work; they delegate to the ModelMetadata property to retrieve the value.

  • Digg
  • DZone
  • Yahoo Buzz
  • Delicious
  • Reddit
  • StumbleUpon
  • SmakNews
  • Jumptags
  • Ping
  • Share/Bookmark

new in asp.net ajax 4.0

“ASP.NET AJAX is alright, but it is way too server-centric for serious client-side development…”, One of the more common misconceptions with ASP.NET AJAX is that it has always been a server-centric framework and offered little to no value for purely client-side JavaScript development. One of the primary objectives of this presentation is to show how ASP.NET AJAX as a JavaScript library has always been useable without server constraints, as well as how ASP.NET AJAX 4.0 makes that even more of a reality by adding additional support.

When some developers think of ASP.NET AJAX they implicitly associate it with WebForms, and feel like it’s very coupled to the ScriptManager and UpdatePanel server controls. While this style of development (partial rendering) in WebForms is an available option, it’s important to keep in mind that that is simply an integration point between ASP.NET AJAX and ASP.NET WebForms. If you’re already using WebForms, partial rendering provides a very easy starting point for introducing AJAX-like functionality to a web application.

That said, ASP.NET AJAX can be used outside of the context of WebForms, because it is ultimately just a collection of JavaScript files that can be referenced within a web page. It’s true that Visual Studio provides rich support for using ASP.NET AJAX, but there is no reason to treat ASP.NET AJAX any differently than any other JavaScript library (i.e. jQuery, Prototype, etc.)

Taking a pragmatic look at the existing ASP.NET AJAX release, we recognize that there are some things missing from it that are really necessary to begin doing any serious client-side web development with it.

There needs to be a stronger offering in terms of client-side controls, which ideally would also provide the same level of templating and data binding that the server controls in WebForms provide. In addition, because JavaScript is a client technology, communication between the server needs to be extremely easy, such that developing with JavaScript, and taking on the tax of an additional tier, becomes simple enough to warrant the benefits it provides without overloading the time it takes to create.

Finally, ASP.NET AJAX really needs to become modular in the sense that developers can pick and choose what pieces of the framework they want to use, or need for that matter.

  • Digg
  • DZone
  • Yahoo Buzz
  • Delicious
  • Reddit
  • StumbleUpon
  • SmakNews
  • Jumptags
  • Ping
  • Share/Bookmark

Microsoft AJAX CDN

Earlier today the ASP.NET team launched a new Microsoft Ajax CDN (Content Delivery Network) service that provides caching support for AJAX libraries (including jQuery and ASP.NET AJAX).  The service is available for free, does not require any registration, and can be used for both commercial and non-commercial purposes.

What does a CDN provide?

Content delivery networks (CDNs) are composed of "edge cache" servers that are strategically placed around the world at key Internet network points.  These "edge cache" servers can be used to cache and deliver all types of content – including images, videos, CSS and JavaScript files.

Using a CDN can significantly improve a website’s end-user performance, since it enables browsers to more quickly retrieve and download content.  For example, instead of having a browser request for an image traverse all the way across the Internet to your web server to download, a CDN can instead serve the request directly from a nearby "edge cache" server that might only be a single network hop away from your customer (making it return much faster – which makes your pages load quicker). 

Summary

The Microsoft Ajax CDN enables you to significantly improve the performance of ASP.NET Web Forms and ASP.NET MVC applications that use ASP.NET AJAX or jQuery.  The service is available for free, does not require any registration, and can be used for both commercial and non-commercial purposes.

ASP.NET 4.0 will make it especially easy for ASP.NET Web Forms developers to take advantage of the CDN. By setting one property of the ScriptManager control, you will be able to redirect all requests for the built-in ASP.NET JavaScript files to the CDN and improve the performance of your Web Forms applications.

  • Digg
  • DZone
  • Yahoo Buzz
  • Delicious
  • Reddit
  • StumbleUpon
  • SmakNews
  • Jumptags
  • Ping
  • Share/Bookmark