BusinessRx Community

Dedicated to the advancement of software, technology and the people who devote their lives to it.

Welcome to BusinessRx Community Sign in | Join | Help
in Search

BusinessRx Reading List

These blog entries are written by industry experts and leaders. We consider this content to be a good read for any software developer or web technologist.

Browse by Tags

All Tags » Tips and Tricks » Atlas » .NET   (RSS)

  • July 4th Links: ASP.NET, ASP.NET AJAX, Visual Studio, Silverlight and IIS7

    I've fallen behind on my weekly link-listing series - apologies for the delay.

    ASP.NET

    • ASP.NET RSSToolkit 2.0 Released: One of the cool projects for ASP.NET 2.0 that was released last year was this free RSS Toolkit - which makes consuming and exposing RSS feeds in ASP.NET super easy (you can even databind any ASP.NET control against them).  The team working on the CodePlex project has recently released V2 of the RSSToolkit.  You can learn all about it and download it here.

    • Building a Custom Database Driven Site Map Provider: Scott Mitchell has written a great article on how to implement your own site map provider for ASP.NET that is populated from a database (instead of statically from an XML file).  You can learn more about the ASP.NET 2.0 SiteMap system from this older blog post of mine here.

    • .NET DateTime and Number Format String Cheat Sheet: If you are like me, you might have trouble remembering all of the standard format strings you can pass to the String.Format() method and/or the Eval() databinding method in ASP.NET to generate the appropriate string output from a DateTime or Numeric datatype.  This PDF cheatsheet is a useful one to download and save to quickly look these format strings up.  John has some other really useful .NET PDF cheatsheets he has also created that you might like to download here.

    • Profile Support for ASP.NET Web Application Projects: VS 2005 Web Application Projects can't directly access the strongly-typed ASP.NET "Profile" object that web site projects support.  This VS add-in supports the ability to generate a strongly typed profile class to accomplish this.  You can read this great series of posts to learn more about how to use the ASP.NET 2.0 Profile system.  I have it on my list of tips/tricks posts to-do to cover using this VS add-on as well.

    • ASP.NET Photo Handler: Bertrand has posted a cool photo album HttpHandler for ASP.NET that allows you to easily drop images into a web directory and automatically generate a nice photo album of them (complete with EXIF information, stack sorting icons, etc).  Might be very useful for people enjoying holidays this summer.  Download the code here.

    • BlogEngine.NET: This is a new open source blog engine for ASP.NET that Mads Kristensen has helped start up, and which I've heard a lot of good things about.  You can read about its features here, and download it here.

    ASP.NET AJAX

    • ScriptDoc 1.0 Available: Bertrand Le Roy has published a cool ScriptDoc utility that extracts documentation from JavaScript files and packages it into XML that can be consumed by documentation building tools.  A very useful tool as you start to build up your own JavaScript libraries.

    Visual Studio

    • GhostDoc 2.1.1 Released: GhostDoc is a free add-in for Visual Studio 2005 (and now 2008) that automatically generates default XML documentation comments for code you write in C# or VB.  It can automatically re-use existing documentation inherited from base classes or implemented interfaces, or generate initial documentation by deducing comments from the name and type of the member signature. You can learn more about it and download it for free here.

    Silverlight

    • Silverlight Tutorials: Michael Schwarz has a great blog where he writes regularly about Silverlight.  This tutorials link points to a bunch of great Silverlight content.

    IIS 7

    • IIS 7.0 is now running all of Microsoft.com: One of the things we push at Microsoft is to "dogfood" our products on our high volume sites when they enter the beta cycle.  As of a few weeks ago, all of the web servers running www.microsoft.com are now running on IIS7 and Windows 2008 Server Beta3.  These servers host 500+ virtual roots and 350 ASP.NET applications, and handle 300,000 concurrent connections.  IIS7 is going to be an awesome release.

    • IIS 7.0 on Server Core: Bill Staples blogs about some of the new IIS7 enhancements that appear with the June CTP of Windows 2008 Server.  One of the big features that is now supported is the ability to install IIS7 on "server core" - which is a low footprint installation of Windows 2008 Server that lays down just the minimal footprint needed to boot (meaning no GUI shell).  This lowers the resources required on servers, and even more importantly means that servers don't need to be updated if a patch is released for a component not installed on the server (which lowers the downtime of servers).  ASP.NET and the .NET Framework aren't supported yet in server core configurations - but will be in the future.

    Hope this helps,

    Scott

    P.S. I'm out on vacation this week, so please excuse delays on email and comment feedback.

  • Tip/Trick: Url Rewriting with ASP.NET

    People often ask me for guidance on how they can dynamically "re-write" URLs and/or have the ability to publish cleaner URL end-points within their ASP.NET web applications.  This blog post summarizes a few approaches you can take to cleanly map or rewrite URLs with ASP.NET, and have the option to structure the URLs of your application however you want.

    Why does URL mapping and rewriting matter?

    The most common scenarios where developers want greater flexibility with URLs are:

    1) Handling cases where you want to restructure the pages within your web application, and you want to ensure that people who have bookmarked old URLs don't break when you move pages around.  Url-rewriting enables you to transparently forward requests to the new page location without breaking browsers.

    2) Improving the search relevancy of pages on your site with search engines like Google, Yahoo and Live.  Specifically, URL Rewriting can often make it easier to embed common keywords into the URLs of the pages on your sites, which can often increase the chance of someone clicking your link.  Moving from using querystring arguments to instead use fully qualified URL's can also in some cases increase your priority in search engine results.  Using techniques that force referring links to use the same case and URL entrypoint (for example: weblogs.asp.net/scottgu instead of weblogs.asp.net/scottgu/default.aspx) can also avoid diluting your pagerank across multiple URLs, and increase your search results.

    In a world where search engines increasingly drive traffic to sites, extracting any little improvement in your page ranking can yield very good ROI to your business.  Increasingly this is driving developers to use URL-Rewriting and other SEO (search engine optimization) techniques to optimize sites (note that SEO is a fast moving space, and the recommendations for increasing your search relevancy evolve monthly).  For a list of some good search engine optimization suggestions, I'd recommend reading the SSW Rules to Better Google Rankings, as well as MarketPosition's article on how URLs can affect top search engine ranking.

    Sample URL Rewriting Scenario

    For the purpose of this blog post, I'm going to assume we are building a set of e-commerce catalog pages within an application, and that the products are organized by categories (for example: books, videos, CDs, DVDs, etc).

    Let's assume that we initially have a page called "Products.aspx" that takes a category name as a querystring argument, and filters the products accordingly.  The corresponding URLs to this Products.aspx page look like this:

    http://www.store.com/products.aspx?category=books
    http://www.store.com/products.aspx?category=DVDs
    http://www.store.com/products.aspx?category=CDs

    Rather than use a querystring to expose each category, we want to modify the application so that each product category looks like a unique URL to a search engine, and has the category keyword embedded in the actual URL (and not as a querystring argument).  We'll spend the rest of this blog post going over 4 different approaches that we could take to achieve this.

    Approach 1: Use Request.PathInfo Parameters Instead of QueryStrings

    The first approach I'm going to demonstrate doesn't use Url-Rewriting at all, and instead uses a little-known feature of ASP.NET - the Request.PathInfo property.  To help explain the usefulness of this property, consider the below URL scenario for our e-commerce store:

    http://www.store.com/products.aspx/Books
    http://www.store.com/products.aspx/DVDs
    http://www.store.com/products.aspx/CDs

    One thing you'll notice with the above URLs is that they no longer have Querystring values - instead the category parameter value is appended on to the URL as a trailing /param value after the Products.aspx page handler name.  An automated search engine crawler will then interpret these URLs as three different URLs, and not as one URL with three different input values (search engines ignore the filename extension and just treat it as another character within the URL). 

    You might wonder how you handle this appended parameter scenario within ASP.NET.  The good news is that it is pretty simple.  Simply use the Request.PathInfo property, which will return the content immediately following the products.aspx portion of the URL.  So for the above URLs, Request.PathInfo would return "/Books", "/DVDs", and "/CDs" (in case you are wondering, the Request.Path property would return "/products.aspx").

    You could then easily write a function to retrieve the category like so (the below function strips out the leading slash and returning just "Books", "DVDs" or "CDs"):

        Function GetCategory() As String

            If 
    (Request.PathInfo.Length 0Then
                Return 
    ""
            
    Else
                Return 
    Request.PathInfo.Substring(1)
            
    End If

        End Function

    Sample Download: A sample application that I've built that shows using this technique can be downloaded here.  What is nice about this sample and technique is that no server configuration changes are required in order to deploy an ASP.NET application using this approach.  It will also work fine in a shared hosting environment.

    Approach 2: Using an HttpModule to Perform URL Rewriting

    An alternative approach to the above Request.PathInfo technique would be to take advantage of the HttpContext.RewritePath() method that ASP.NET provides.  This method allows a developer to dynamically rewrite the processing path of an incoming URL, and for ASP.NET to then continue executing the request using the newly re-written path.

    For example, we could choose to expose the following URLs to the public:

    http://www.store.com/products/Books.aspx
    http://www.store.com/products/DVDs.aspx
    http://www.store.com/products/CDs.aspx

    This looks to the outside world like there are three separate pages on the site (and will look great to a search crawler).  By using the HttpContext.RewritePath() method we can dynamically re-write the incoming URLs when they first reach the server to instead call a single Products.aspx page that takes the category name as a Querystring or PathInfo parameter instead.  For example, we could use an an Application_BeginRequest event in Global.asax like so to do this:

        void Application_BeginRequest(object sender, EventArgs e) {

            
    string fullOrigionalpath Request.Url.ToString();
            
            if 
    (fullOrigionalpath.Contains("/Products/Books.aspx")) {
                Context.RewritePath(
    "/Products.aspx?Category=Books");
            
    }
            
    else if (fullOrigionalpath.Contains("/Products/DVDs.aspx")) {
                Context.RewritePath(
    "/Products.aspx?Category=DVDs");
            
    }
        } 

    The downside of manually writing code like above is that it can be tedious and error prone.  Rather than do it yourself, I'd recommend using one of the already built HttpModules available on the web for free to perform this work for you.  Here a few free ones that you can download and use today:

    These modules allow you to declaratively express matching rules within your application's web.config file.  For example, to use the UrlRewriter.Net module within your application's web.config file to map the above URLs to a single Products.aspx page, we could simply add this web.config file to our application (no code is required):

    <?xml version="1.0"?>

    <configuration>

      
    <configSections>
        
    <section name="rewriter"  
                 requirePermission
    ="false" 
                 type
    ="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler, Intelligencia.UrlRewriter" />
      </
    configSections>
      
      
    <system.web>
          
        
    <httpModules>
          
    <add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule, Intelligencia.UrlRewriter"/>
        </
    httpModules>
        
      
    </system.web>

      
    <rewriter>
        
    <rewrite url="~/products/books.aspx" to="~/products.aspx?category=books" />
        <
    rewrite url="~/products/CDs.aspx" to="~/products.aspx?category=CDs" />
        <
    rewrite url="~/products/DVDs.aspx" to="~/products.aspx?category=DVDs" />
      </
    rewriter>  
      
    </configuration> 

    The HttpModule URL rewriters above also add support for regular expression and URL pattern matching (to avoid you having to hard-code every URL in your web.config file).  So instead of hard-coding the category list, you could re-write the rules like below to dynamically pull the category from the URL for any "/products/[category].aspx" combination:

      <rewriter>
        
    <rewrite url="~/products/(.+).aspx" to="~/products.aspx?category=$1" />
      </rewriter>  

    This makes your code much cleaner and super extensible.

    Sample Download: A sample application that I've built that shows using this technique with the UrlRewriter.Net module can be downloaded here

    What is nice about this sample and technique is that no server configuration changes are required in order to deploy an ASP.NET application using this approach.  It will also work fine in a medium trust shared hosting environment (just ftp/xcopy to the remote server and you are good to go - no installation required).

    Approach 3: Using an HttpModule to Perform Extension-Less URL Rewriting with IIS7

    The above HttpModule approach works great for scenarios where the URL you are re-writing has a .aspx extension, or another file extension that is configured to be processed by ASP.NET.  When you do this no custom server configuration is required - you can just copy your web application up to a remote server and it will work fine.

    There are times, though, when you want the URL to re-write to either have a non-ASP.NET file extension (for example: .jpg, .gif, or .htm) or no file-extension at all.  For example, we might want to expose these URLs as our public catalog pages (note they have no .aspx extension):

    http://www.store.com/products/Books
    http://www.store.com/products/DVDs
    http://www.store.com/products/CDs

    With IIS5 and IIS6, processing the above URLs using ASP.NET is not super easy.  IIS 5/6 makes it hard to perform URL rewriting on these types of URLs within ISAPI Extensions (which is how ASP.NET is implemented). Instead you need to perform the rewriting earlier in the IIS request pipeline using an ISAPI Filter.  I'll show how to-do this on IIS5/6 in the Approach 4 section below.

    The good news, though, is that IIS 7.0 makes handling these types of scenarios super easy.  You can now have an HttpModule execute anywhere within the IIS request pipeline - which means you can use the URLRewriter module above to process and rewrite extension-less URLs (or even URLs with a .asp, .php, or .jsp extension).  Below is how you would configure this with IIS7:

    <?xml version="1.0" encoding="UTF-8"?>

    <configuration>

      
    <configSections>
        
    <section name="rewriter" 
                 requirePermission
    ="false" 
                 type
    ="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler, Intelligencia.UrlRewriter" />
      </
    configSections>
      
      
    <system.web>
          
        
    <httpModules>
          
    <add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule, Intelligencia.UrlRewriter" />
        </
    httpModules>
        
      
    </system.web>

      
    <system.webServer>

        
    <modules runAllManagedModulesForAllRequests="true">
          
    <add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule" />
        </
    modules>

        
    <validation validateIntegratedModeConfiguration="false" />

      </
    system.webServer>

      
    <rewriter>
        
    <rewrite url="~/products/(.+)" to="~/products.aspx?category=$1" />
      </
    rewriter>
      
    </configuration>

    Note the "runAllManagedModulesForAllRequests" attribute that is set to true on the <modules> section within <system.webServer>.  This will ensure that the UrlRewriter.Net module from Intelligencia, which was written before IIS7 shipped, will be called and have a chance to re-write all URL requests to the server (including for folders).  What is really cool about the above web.config file is that:

    1) It will work on any IIS 7.0 machine.  You don't need an administrator to enable anything on the remote host.  It will also work in medium trust shared hosting scenarios.

    2) Because I've configured the UrlRewriter in both the <httpModules> and IIS7 <modules> section, I can use the same URL Rewriting rules for both the built-in VS web-server (aka Cassini) as well as on IIS7.  Both fully support extension-less URLRewriting.  This makes testing and development really easy.

    IIS 7.0 server will ship later this year as part of Windows Longhorn Server, and will support a go-live license with the Beta3 release in a few weeks.  Because of all the new hosting features that have been added to IIS7, we expect hosters to start aggressively offering IIS7 accounts relatively quickly - which means you should be able to start to take advantage of the above extension-less rewriting support soon.  We'll also be shipping a Microsoft supported URL-Rewriting module in the IIS7 RTM timeframe that will be available for free as well that you'll be able to use on IIS7, and which will provide nice support for advanced re-writing scenarios for all content on your web-server.

    Sample Download: A sample application that I've built that shows using this extension-less URL technique with IIS7 and the UrlRewriter.Net module can be downloaded here

    Approach 4: ISAPIRewrite to enable Extension-less URL Rewriting for IIS5 and IIS6

    If you don't want to wait for IIS 7.0 in order to take advantage of extension-less URL Rewriting, then your best best is to use an ISAPI Filter in order to re-write URLs.  There are two ISAPI Filter solutions that I'm aware of that you might want to check-out:

    • Helicon Tech's ISAPI Rewrite: They provide an ISAPI Rewrite full product version for $99 (with 30 day free trial), as well as a ISAPI Rewrite lite edition that is free.
    • Ionic's ISAPI Rewrite: This is a free download (both source and binary available)

    I actually don't have any first-hand experience using either of the above solutions - although I've heard good things about them.  Scott Hanselman and Jeff Atwood recently both wrote up great blog posts about their experiences using them, and also provided some samples of how to configure the rules for them.  The rules for Helicon Tech's ISAPI Rewrite use the same syntax as Apache's mod_rewrite.  For example (taken from Jeff's blog post):

    [ISAPI_Rewrite]
    # fix missing slash on folders
    # note, this assumes we have no folders with periods!
    RewriteCond Host: (.*)
    RewriteRule ([^.?]+[^.?/]) http\://$1$2/ [RP]

    # remove index pages from URLs
    RewriteRule (.*)/default.htm$ $1/ [I,RP]
    RewriteRule (.*)/default.aspx$ $1/ [I,RP]
    RewriteRule (.*)/index.htm$ $1/ [I,RP]
    RewriteRule (.*)/index.html$ $1/ [I,RP]

    # force proper www. prefix on all requests
    RewriteCond %HTTP_HOST ^test\.com Idea
    RewriteRule ^/(.*) http://www.test.com/$1 [RP]

    # only allow whitelisted referers to hotlink images
    RewriteCond Referer: (?!http://(?:www\.good\.com|www\.better\.com)).+
    RewriteRule .*\.(?:gif|jpg|jpeg|png) /images/block.jpg [I,O]

    Definitely check out Scott's post and Jeff's post to learn more about these ISAPI modules, and what you can do with them.

    Note: One downside to using an ISAPI filter is that shared hosting environments typically won't allow you to install this component, and so you'll need either a virtual dedicated hosting server or a dedicated hosting server to use them.  But, if you do have a hosting plan that allows you to install the ISAPI, it will provide maximum flexibility on IIS5/6 - and tide you over until IIS7 ships.

    Handling ASP.NET PostBacks with URL Rewriting

    One gotcha that people often run into when using ASP.NET and Url-Rewriting has to-do with handling postback scenarios.  Specifically, when you place a <form runat="server"> control on a page, ASP.NET will automatically by default output the "action" attribute of the markup to point back to the page it is on.  The problem when using URL-Rewriting is that the URL that the <form> control renders is not the original URL of the request (for example: /products/books), but rather the re-written one (for example: /products.aspx?category=books).  This means that when you do a postback to the server, the URL will not be your nice clean one.

    With ASP.NET 1.0 and 1.1, people often resorted to sub-classing the <form> control and created their own control that correctly output the action to use.  While this works, it ends up being a little messy - since it means you have to update all of your pages to use this alternate form control, and it can sometimes have problems with the Visual Studio WYSIWYG designer.

    The good news is that with ASP.NET 2.0, there is a cleaner trick that you can use to rewrite the "action" attribute on the <form> control.  Specifically, you can take advantage of the new ASP.NET 2.0 Control Adapter extensibility architecture to customize the rendering of the <form> control, and override its "action" attribute value with a value you provide.  This doesn't require you to change any code in your .aspx pages.  Instead, just add a .browser file to your /app_browsers folder that registers a Control Adapter class to use to output the new "action" attribute:

    You can see a sample implementation I created that shows how to implement a Form Control Adapter that works with URLRewriting in my sample here.  It works for both the Request.PathInfo and UrlRewriter.Net module approaches I used in Approach 1 and 2 above, and uses the Request.RawUrl property to retrieve the original, un-rewritten, URL to render.  With the ISAPIRewrite filter in Approach 4 you can retrieve the Request.ServerVariables["HTTP_X_REWRITE_URL"] value that the ISAPI filter uses to save the original URL instead.

    My FormRewriter class implementation above should work for both standard ASP.NET and ASP.NET AJAX 1.0 pages (let me know if you run into any issues).

    Handling CSS and Image Reference Correctly

    One gotcha that people sometime run into when using Url Rewriting for the very first time is that they find that their image and CSS stylesheet references sometimes seem to stop working.  This is because they have relative references to these files within their HTML pages - and when you start to re-write URLs within an application you need to be aware that the browser will often be requesting files in different logical hierarchy levels than what is really stored on the server.

    For example, if our /products.aspx page above had a relative reference to "logo.jpg" in the .aspx page, but was requested via the /products/books.aspx url, then the browser will send a request for /products/logo.jpg instead of /logo.jpg when it renders the page.  To reference this file correctly, make sure you root qualify CSS and Image references ("/style.css" instead of "style.css").  For ASP.NET controls, you can also use the ~ syntax to reference files from the root of the application (for example: <asp:image imageurl="~/images/logo.jpg" runat="server"/>

    Hope this helps,

    Scott

    P.S. For more ASP.NET 2.0 Tips and Tricks, please check out my ASP.NET 2.0 Tips, Tricks and Tutorials Page.

    P.P.S. Special thanks to Scott Hanselman and Michael K. Campbell for testing my Form Control Adapter with their sites.

  • Gotcha: Don't use <xhtmlConformance mode="Legacy"/> with ASP.NET AJAX

    Recently I've helped a few developers who have been having some weird JavaScript issues (both when using ASP.NET AJAX and with some other custom JavaScript routines they were using).  The culprit was that they had automatically migrated a VS 2003 Web Project to VS 2005, and still had the <xhtmlConformance mode="Legacy"/> switch configured within their web.config file. 

    If you are writing custom client-side JavaScript in your web application and/or are going to be using AJAX, please read-on to learn how to avoid a common gotcha (note: for a list of other tips, tricks, recipes and gotchas I've previously posted, please check out this page here).

    Symptom:

    You see strange behavior when adding new client-side JavaScript to a project that was previously upgraded (successfully) from VS 2003 to VS 2005.  When using ASP.NET AJAX UpdatePanel controls, this strange behavior can sometimes include cases where the page does a full-page postback instead of just incrementally updating pieces of a page. 

    When you open up your web.config file, you also see a <xhtmlConformance/> element within it like so:

    <configuration>

        
    <system.web>
            
    <xhtmlConformance mode="Legacy" />
        </
    system.web>

    </configuration>

    Background:

    ASP.NET 1.0 and 1.1 didn't emit XHTML compliant markup from many of its server controls.  ASP.NET 2.0 changed this and by default emits XHTML compliant markup from all controls (note: you can learn more about ASP.NET 2.0's standards compliance from this excellent MSDN article).

    One of the things we noticed in the early ASP.NET 2.0 betas, though, was that when upgrading customer applications a lot of the applications had assumptions that the page output was not XHTML compliant.  By changing our default output of the server controls to be XHTML, it sometimes modified the visual rendering of a page.  For backwards compatibility purposes we added the <xhtmlConformance> switch above that allows developers to render controls in "Legacy" mode (non-XHTML markup the same as ASP.NET 1.1) as well as Transitional mode (XHTML Transitional) as well as Strict mode (XHTML Strict). 

    By default when you use the VS 2003->VS 2005 Web Project Migration wizard (for both web sites and web application projects), your web.config file will have the legacy switch added.

    Solution:

    Unless you know of known issues that your site has when running in XHTML mode (and which you don't have time yet to fix), I'd always recommend removing the <xhtmlConformance> section from your web.config file (or you can explicitly set it to "Transitional" or "Strict"). 

    This will make your HTML output standards compliant.  Among other things, this will cause the HTML from your server controls to be "well formed" - meaning open and close tag elements always match.  This is particularly important when you are using AJAX techniques to dynamically replace the contents of certain HTML elements on your page (otherwise the client-side JavaScript sometimes gets confused about container elements and can lead to errors).  It will also ensure that ASP.NET AJAX works fine with your site.

    Hope this helps,

    Scott

  • Gotcha: Lost HTML Intellisense within ASP.NET AJAX Controls

    Symptom:

    You are using ASP.NET AJAX Beta1 or Beta2, and create a .aspx page that is based on a .master file.  You add the <asp:scriptmanger>, <asp:updatepanel>, <asp:updateprogress> or <asp:timer> control into the content page, and find that markup intellisense no longer works for these controls, or for any controls nested within them:

    In the screen-shot above notice how the ScriptManager, UpdatePanel and ContentTemplate tags have the little red-squiggly lines underneath them.  You also won't get tag completion when you type these elements in the document.  You can still compile and run just fine, and the WYSIWYG designer works just fine.  But you do lose source editor intellisense.

    Some Background on the Issue:

    ASP.NET 2.0 added support for registering controls (both compiled and .ascx user controls) within your web.config file - removing the need to always add <%@ Register %> directives at the top of your page.  For more details on this and to see a sample in action, please check out my Tips and Tricks talk from the recent ASP.NET Connections conference.

    One of the cool aspects of this feature is that it also now allows you to map the same tag prefix against multiple assemblies.  We use this with ASP.NET AJAX to have these controls use the <asp:> tag prefix, even though they live in a separate assembly from the system.web.dll file that contains the rest of ASP.NET.

    Unfortunately we discovered a bug with the VS markup intellisense engine when doing the ASP.NET AJAX Beta1 release - which is that you lose intellisense when you map multiple assemblies against the <asp:> tag prefix and use the controls within a <asp:content> control in a .aspx page based on a master page. 

    How to Fix This

    The fix for the intellisense issue will be in VS 2005 SP1.

    In the meantime there are two workarounds that you can use to fix it immediately:

    1) Keep the .master file open within the Visual Studio IDE when working on the .aspx content page.  It turns out the intellisense engine only runs into issues if the .master file is closed.  As long as it is open within the same IDE, it resolves the assemblies just fine and will give you full intellisense:

    The screen-shot above is with the exact same sample as the previous screen-shot.  The only difference is that I also have the Site.Master file open in the editor in the background.  When that file is open, I get full intellisense for the ASP.NET AJAX control elements and no intellisense errors.

    Alternatively you could instead use the below technique if you don't want to keep the .master file open:

    2) Go into your web.config file and change the tag-prefix naming for the ASP.NET AJAX controls to something other than <asp:>.  For example, instead of:

          <controls>
            
    <add tagPrefix="asp" namespace="Microsoft.Web.UI" assembly="Microsoft.Web.Extensions" />
            <
    add tagPrefix="asp" namespace="Microsoft.Web.UI.Controls" assembly="Microsoft.Web.Extensions" />
          </
    controls>

     

    change them to something like this:

     

          <controls>
            
    <add tagPrefix="ajax" namespace="Microsoft.Web.UI" assembly="Microsoft.Web.Extensions" />
            <
    add tagPrefix="ajax" namespace="Microsoft.Web.UI.Controls" assembly="Microsoft.Web.Extensions" />
          </
    controls>

    You'd then want to update your tag prefixes in your .aspx page to use this new tag prefix.

    Either of these approaches will solve the problem and deliver full intellisense.  The issue should then be resolved completely with VS 2005 SP1.

    Hope this helps (and sorry for the inconvenience),

    Scott

  • Nikhil's WebDevHelper Utility and ASP.NET AJAX Support

    If you aren't subscribed yet to Nikhil's blog, you really should visit it and subscribe immediately.

    Nikhil is an architect on the ASP.NET Team and is constantly cooking up and posting cool new utilities and samples on his blog (all of which are of course free).  Among his many projects is the Script# project, which is a C# compiler that generates JavaScript as its output instead of IL (allowing you to get type-safety, refactoring, and compile-time checking of your code).  He also wrote the cool forward/back button support control for ASP.NET AJAX that I blogged about in September.

    Earlier today he released an update to his popular WebDevHelper utility.  Included within this release is support for easily monitoring the HTML updates that are returned from ASP.NET when using the <asp:updatepanel> control.  His utility allows you to log and inspect all of the HTTP traffic between the browser and the server - making it much easier to debug AJAX code.  For example, in the picture below you can see the HTML returned from an UpdatePanel when partial rendering is enabled on the page:

    Nikhil has also recently added new support for inspecting JSON network requests and drilling into the objects serialized on the wire.  For example, in the picture below you can see the properties for an "EXIF" picture object returned from the server via the ASP.NET AJAX Networking stack.  Nikhil's utility automatically sniffs these on the client and allows you to easily inspect them:

    He also has support for outputting trace statements as well as dumping objects from within JavaScript code using the WebDevHelper utility as well. 

    You can learn more about this free utility here, and read Nikhil's excellent documentation on how to use it here.

    Hope this helps,

    Scott

     

    Share this post: Email it! | bookmark it! | digg it! | reddit!
  • ASP.NET Connections Slides + Demos

    Earlier this week I presented at the ASP.NET Connections conference in Las Vegas.  This is a great conference that is held twice a year (the fall show is in Las Vegas, the spring show is in Orlando).  This past week we had over 1,500 attendees for the ASP.NET conference alone, and more than 4,700 total for all of the DevConnections conferences held in parallel (VS, SQL, SharePoint, Mobile and Office Connections are all held in the same place - with attendees allowed to attend any session).

    I presented an overview keynote to everyone at the conference on the opening night, and then three ASP.NET specific talks:   

    ASP.NET AJAX Keynote

    This talk kicked off the first full day of the conference, and provided an overview of our ASP.NET AJAX 1.0 plans and some "from scratch" demos of it in action.  You can download the slides+demo here

    The highlight of the talk for me was having Ben Noonan from Burton join me on stage and show off some of the cool ASP.NET AJAX usage they are currently doing at Burton on their live sites.  Ben did a great job walking people through some of the ways they've used it, as well as highlighting some of the great business results they are seeing -- both in terms of increases in the average length of time spent by a user on the site, and the increase in sales and revenue they are realizing.

    One of the fun things we did for the conference was to commission a custom Burton ASP.NET AJAX snowboard to be built (see picture on the right for what it looks like).  Bill Gates and Jake Burton both agreed to autograph it, and we raffled it off to a lucky conference attendee yesterday. 

    ASP.NET Tips and Tricks

    This talk covered ASP.NET UI, Caching and Deployment Tips and Tricks, and Visual Studio 2005 tips/tricks.  You can download the slides+demos here.

    You can learn more about the Visual Studio build performance optimization suggestions by reading this past post of mine on improving build performance.  You can also find several dozen more ASP.NET and Visual Studio Tips/Tricks of mine by browsing my past blog posts marked with the "Tips and Tricks" tag.

    ASP.NET and LINQ

    This talk provided an overview of the new LINQ technology that is shipping next year, and demonstrated some of the dramatic productivity improvements it will bring for ASP.NET with data access.  Click here to download the slides+demos for this talk.

    You can learn more about LINQ and how to use it with ASP.NET by reviewing some of my past LINQ posts.  Here are a few in particular worth reviewing:

    As I've said in the past, I think LINQ is one of the coolest new .NET technologies.  It is definitely worth reviewing and trying out.

    My Upcoming Speaking Schedule

    I'm actually done speaking at conferences for the year - which is something of a relief since I've already done events in Amsterdam, Helsinki, Nice, Dublin, Auckland, Sydney, Boston, Orlando, Dallas, and Las Vegas (twice) this year.  I am looking forward to being able to stay in sunny Seattle for the next 2 months and actually do my day job. :-)

    I am still finalizing my speaking schedule for next year.  I will be speaking at the CodeMash conference in Ohio in mid-January, at the Spring ASP.NET Connections Conference in Orlando in March, potentially the SDWest conference in San Francisco in March (I'm still finalizing my plans here), and definitely the Microsoft MIX07 conference April 30th-May 2nd. 

    Beyond May I'm not sure of my exact plans yet -- although I'll probably present again at TechEd US, potentially squeeze in a trip to Europe, and most likely be making my first trips to India and Japan next year.

    Hope to see you soon,

    Scott

    P.S. People sometimes ask me whether they can re-use some of my slides + demos for their own talks.  The answer is absolutely yes!  Please re-use any and all content you find on my blog or in presentations -- no need to ask permission or give credit.  I post this content to have as many people as possible learn from it, so having you deliver it to others is exactly what I'd like to have happen more.

    Share this post: Email it! | bookmark it! | digg it! | reddit!
  • Tip/Trick: Handling Errors with the UpdatePanel control using ASP.NET AJAX

    Luis Abreu is an ASP.NET MVP who has a great blog on the http://msmvps.com blog site.  Earlier today he posted a great tutorial post that describes how to use some of the new features in the ASP.NET AJAX Beta1 release to add more robust error handling into your application.  I highly recommend reading and bookmarking it for future use.

    Error handling in an AJAX world can often be tricky -- especially when AJAX call-backs are taking place and a mixture of client and server code is running within an application.  In its most recent release, the <asp:updatepanel> control that comes with ASP.NET AJAX now has much more robust error handling and reporting features for you to use.  Specifically:

    1) You can now handle the "OnAsyncPostBackError" event on the <asp:scriptmanager> control to catch and/or modify an error message that occurs during the processing of an AJAX postback callback on the server. 

    2) You can now set the "AllowCustomErrors" property on the <asp:scriptmanager> control to enable the standard ASP.NET custom error support to be enabled to redirect a user automatically to an error page when an error occurs (even if it is happening during an AJAX postback).

    3) You can now optionally handle client-side JavaScript events on the page to intercept any error message sent back from the server, and perform custom client-side actions as a result (for example: to output the error message to a nicely formatted <div> section instead of performing a pop-up message). 

    Read all about how to take advantage of the above new features from Luis' great tutorial here.

    Hope this helps,

    Scott

    Share this post: Email it! | bookmark it! | digg it! | reddit!
  • Tip/Trick: Enabling Back/Forward-Button Support for ASP.NET AJAX UpdatePanel

    Nikhil recently posted a nice blog post that includes a new ASP.NET AJAX-enabled control called "HistoryControl".  When added to a page it allows developers to programmatically add logical views into a browser's history list.  This enables you to make AJAX enabled sites much more useful, and to follow the standard back/forward navigation paradigm that traditional web apps follow.

    For example, the below code could be written by a developer in response to a selection change within a list to to add the previous list selection to the browser's history via Nikhil's "HistoryControl":

    private void ContentList_SelectedIndexChanged(object sender, EventArgs e) {
       history.AddEntry(contentList.SelectedIndex.ToString()
    ;
    }

    Once you add entries into the history control, the back/forward button will be enabled in the browser.  Nikhil's history control then exposes a "Navigate" event which fires when you press the forward or back button in the browser, and this event then exposes the identifier entry provided before when the view was added into the browser history.  You can then use this to restore the page to whatever state it should be in to match the previous history item and update the page:

    private void HistoryControl_Navigate(object sender, HistoryEventArgs e) {

        
    int selectedIndex 0;

        if 
    (String.IsNullOrEmpty(e.Identifier) == false) {
            selectedIndex 
    Int32.Parse(e.Identifier);
        
    }

        
    // Update the content being displayed in the page
        
    contentList.SelectedIndex selectedIndex;

        
    // Mark the update panels as needing an update
        
    mainUpdatePanel.Update();
    }

    And now your end-users get forward/back button history navigation working with AJAX.  You can download the code for Nikhil's history control and start using it here.

    Hope this helps,

    Scott

    Share this post: Email it! | bookmark it! | digg it! | reddit!
Powered by Community Server, by Telligent Systems
'