ICaramba

Miguel Castro's blog about .NET and its effect on National Security, the Eco-system, and his daughter's sleeping patterns.


News

My Stats

  • Posts - 120
  • Comments - 69
  • Trackbacks - 145

Twitter












Recent Comments


Recent Posts


Archives


Image Galleries



Blogs I read


Links


Microsoft DCCs


August 2006 Entries

New interview on www.polymorphicpodcast.com


I just did an interview on Craig Shoemakers's Polymorphic Podcast and I'm very pleased with the way it came out.

I'd love to hear any feedback from people on what they think.  This one is NOT on custom webcontrols :)  it's on Extensibility Achitecture.

http://www.polymorphicpodcast.com/shows/architectextensibility/

 

posted @ Friday, August 25, 2006 2:36 PM | Feedback (5) |


Cache Tip


Well, I did promise that since I don't have time to blog as much as I used to, I would try to keep the quality of my postings as high as possible.  I hope that they have been useful so far and I hope this one is too -- please let me know !

I recently ran into a little challenge while using the output cache from several pages of an ASP.NET 2.0 site.  My site uses a master page and also incorporates the built-in authentication controls and providers (oh so cool).  As opossed to the traditional approach with these controls, I didn't build a login page which contains the login control.  Instead I have a small Login control on the left side of the Master Page and I encased it inside a LoginView control.  This is very cool control because it contains two templates that show automatically based on the user's authentication state.  Check out one of my DNR-TV shows for lots of info on this.  So when the user is logged on, the LoginView control shows a welcome message and when the user is logged off, it displays a Login control.  The challenge is that many of my pages (some secure and some not), use output cache.  So if I am on a cached page and use the Login control to authenticate, the page refresh still shows the Login control, though authentication DID take place.  It's not for another 60 seconds that I can refresh the page and see the Welcome message.

The answer to this problem is in using the VaryByCustom attribute of the OutputCache directive.  You can use any string(s) you want here so I use the string “Login”.  The trick is then to make the page cache exempt based on something related to this value.  That's where the Global.asax comes in.  You need to override the GetVaryByCustomString method in the global.asax file.  One of the arguments in this method is the custom string I placed in the VaryByCustom attribute, “Login”.  I can then condition on this and return a string value.  Whenever this string value changes from the last value, the page will NOT cache, which is what I need.

Here's my code for this method:

public override string GetVaryByCustomString(HttpContext context, string custom)
{
   
// This check ensures that if a user's authentication state changes,
    //
the page is not cached.
   
if (custom == "Login")
        return User.Identity.IsAuthenticated.ToString();

        return base.GetVaryByCustomString(context, custom);
}

As you can see, I'm leveraging a value that automatically gets changed based on authentication state.  So if the value was False before, and you just logged in, it changes to True, thus changing the return value of this method an causing the page to reload.

Problem solved.

posted @ Friday, August 18, 2006 10:36 AM | Feedback (7) |


Interesting requirement with Images and WebResource


For those of you that don't mess with this technology too much, one of the coolest new features in ASP.NET 2.0 Webcontrol development is WebResources.  This allows you to embedd resource files, predominantly images, directly into the DLL of the webcontrol, and thus eliminating the need to distribute your required images with your controls.

WebResources are pretty thouroughly documented and are also covered in the up-coming CoDe Magazine issue in an article written by yours truly.  Recently in a site I'm developing, I had a need to do something a little unique.  My requirements demanded that I programmatically obtain the dimenstions of images from within a control.  These images can be obtained from either an ImageUrl property I exposed in a control or from an embedded WebResource.  Well, getting this information from the ImageUrl provided by a page developer is easy enough:

System.Drawing.Image image = System.Drawing.Image.FromFile(this.Context.Server.MapPath(imgScreenshot.ImageUrl));

As you can see, I create a System.Drawing.Image object, and read the image in from the file path specified in the url.  From here, I can obtain the Width and Height properties without a problem.

Getting the same information from a WebResource is a little different however.  The Page.ClientScript.GetWebResourceUrl method returns a url path to the embedded image that uses a custom http handler to access it.  This url does not work within the FromFile method of the Image object, nor does it work inside a MapMap call.  the Image object however, does have a FromStream method that I can use so now the task at hand became loading a WebResource into a stream.

Here's the final code:

System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
using(System.IO.Stream stream = assembly.GetManifestResourceStream("CorporateSite.Web.UI.WebControls.CodeBreezeSS.jpg"))
{
      image = System.Drawing.Image.FromStream(stream);
      stream.Close();
}

As you can see here, I used the GetManifestResourceStream method of the Assembly object to grab the embedded resource and turn it into a stream.   The rest was easy of course.  The interesting thing here is that the GetWebResourceUrl method that's new in ASP.NET 2.0 is used to access the image using the http handler, but the fact that the GetManifestResourceStream method works to extract the image from the DLL tells me that maybe in 1.1, I could have simulated web resources by building image controls out of streams.   Hmmm. Interesting.

I hope someone finds this helpful.

 

 

posted @ Friday, August 04, 2006 1:20 PM | Feedback (2) |


VSLive NY Coming up


Add the Most Anticipated VSLive! Sessions to Your New York Agenda

Check out the top ten sessions at VSLive! New York. See which sessions your peers visited most on our conference Web site. Then, add these interesting topics to your “Must See” list for New York.

The Early Bird Deadline of August 9 is right around the corner – lock in savings of $200 by using Priority Code TOP10. Register today to attend these top ten sessions and our full conference lineup September 10-13. Visit www.vslive.com/newyork or call 800-848-5523 (or 650-378-7100) to speak to one of our customer service representatives.

In this email (click to jump):

Top 10 New York Sessions

Webcontrol Development Enhancements in ASP.NET 2.0
Miguel Castro, Infotek Consulting Group, Inc.

Embed Workflow (WF) into Your Next Application
Richard Hundhausen, Accentient

Programming SharePoint 2007
Bill Wolff, Agility Systems

Datasets, Business Objects or Just DLINQ
Sahil Malik

Inside C# 3.0: Extension Methods, Query Expressions & Expression Trees
Richard Hale Shaw, Richard Hale Shaw Group

Data Binding Custom Objects and DataSets
John Papa, ASPSOFT

Everyday Use of Generics
Deborah Kurata, InStep Technologies

Client/Server Communication Options
Rockford Lhotka, Magenic Technologies

Build Distributed Object-Oriented Apps in .NET 2.0
Rockford Lhotka, Magenic Technologies

Click-Once
Jeff Levinson, The Boeing Company

Want more content to choose from? You can view the complete conference agenda online at www.vslive.com/newyork.

Favorite ASP.NET Sessions

Webcontrol Development Enhancements in ASP.NET 2.0
Miguel Castro, Infotek Consulting Group, Inc.
ASP.NET 2.0 brought to the table many great enhancements to increase productivity in the development of web applications. Accompanying these great new features that mainstream web developers are already familiar with, are some incredible improvements to the infrastructure for developing custom server controls. As in ASP.NET 1.1, server controls or webcontrols, as they are also known, are not additions to ASP.NET’s infrastructure; they are at the very heart of its architecture. Becoming intimate with this technology gets you closer than ever to understanding exactly how ASP.NET really works. The development of custom webcontrols has not been a technology embraced by all ASP.NET developers. With the great new enhancements you’ll learn here, maybe you too will get as hooked as I have. Learn about Template Editing, SmartTags, AutoFormatting, WebResources and the AJAX-based Callbacks, and how easy it is to integrate all of this into Webcontrols of your own. This presentation expects established knowledge of custom control development and provides a fast-paced tour through the most exciting control development features in ASP.NET 2.0.

Programming SharePoint 2007
Bill Wolff, Agility Systems
SharePoint 2007 radically changes how a developer works with SharePoint technologies. Sites now make full use of ASP.NET 2.0. Customizable site starter templates enable users to build their own sites.             Pluggable service-provider models for personalization, membership, navigation and enhanced security improve extranet support. Document management with content types and enhanced policies target compliance needs. Users can configure and manage workflows without coding. Blogs, Wikis and RSS feeds are now standard lists. Lists can work in offline mode with rich synchronization. There is deeper integration with Office 2007. Managed code extensions in all new Office products enable rich extensions and custom solutions. There is also integration with the new Groove Server for offline collaboration. FrontPage has morphed into SharePoint Designer which knows ASP.NET 2.0, CSS, WWF, XSLT and XHTML standards. This talk will cover all of these features from a developer's perspective and give insight into where coding is added to visual designers and templates.

Inside C# 3.0: Extension Methods, Query Expressions & Expression Trees
Richard Hale Shaw, Richard Hale Shaw Group
LINQ, DLINQ, XLINQ – what the heck? Just what we need: more TLAs and FFLAs (fancy, four-letter acronyms). Forget all that. What you need to know is this: C# 2.0 anonymous methods are incredibly useful but require a bit of plumbing to be effective. In C# 3.0, you get an elegant, expressive syntax for generating anonymous methods called lambda expressions. Another C# 3.0 feature, extension methods, let you define a static method in one class, but use it as an instance method in some other class, all without deriving or modifying the latter. Combine the two and you can create query expressions to perform SQL-like and XQuery-like searches on collections. You can store the queries – not the results, but the query itself – in an expression tree data structures for re-use. Combined with simpler variable initialization syntax, elegant object initialization, and the ability to define types on-the-fly (anonymous types), C# 3.0 will transform your day-to-day C# development into elegant, high-level expressions. In this session, Richard will wipe away the techno-speak and show you how to leverage these new features.

Everyday Use of Generics
Deborah Kurata, InStep Technologies
You may think of generics as a Ferrari that you only take out for special occasions and when the conditions are just right. But they are better compared to your trusty pickup, perfectly suited for everyday use. This session covers the generic structures provided in .NET such as the List and Dictionary. It details how to leverage these structures to simplify your code and make it more generalized – or should I say “generic”?

Build Distributed Object-Oriented Apps in .NET 2.0
Rockford Lhotka, Magenic Technologies
Get an in-depth look at the concepts and techniques from Rockford Lhotka's Expert VB 2005 and C# 2005 Business Objects books on distributed business object programming updated for .NET 2.0. You will learn how to design Windows and Web-based applications based on distributed business objects, achieving high levels of reuse, scalability, long-term maintainability, and other benefits. Learn how to apply System.Transactions, generics, new ADO.NET features, data binding and WinFX when building distributed applications on .NET 2.0.

Most-Viewed Smart Client Sessions

Embed Workflow (WF) into Your Next Application
Richard Hundhausen, Accentient
Workflow is an important part of business software, but that doesn’t mean it’s easy to develop or describe. For the first time, Microsoft has created a workflow foundation that can be embedded into your custom applications. This general-purpose designer and engine can solve both system and human workflow problems. In this session, we will review the importance of designing proper application workflow and how to use the visual designer, debugger and runtime environment found in WinFx.

Datasets, Business Objects or Just DLINQ
Sahil Malik
Have you heard about LINQ (Language Integrated Query)? Are you more of a Dataset person, or more of a business object person? What happens to this religious war in the light of DLINQ? Come and explore a balanced view of Datasets and business objects, and what DLINQ means to you.

Data Binding Custom Objects and DataSets
John Papa, ASPSOFT
The .NET Framework introduces a new assortment of interfaces and features that make binding both DataSets and custom objects to Windows Forms easier and more powerful than ever. In this session, I will demonstrate how the binding interfaces work and how to bind different types of objects to the WinForms, and how to implement different  interfaces to notify the application when specific events occur such as when a property changes.

Client/Server Communication Options
Rockford Lhotka, Magenic Technologies
Many of us need to choose a client/server communication technology for our current development. How do you choose between WCF (Indigo), Web services, WSE, Enterprise Services, Remoting, DCOM and MSMQ? In this session, you’ll learn the strengths and weaknesses of each option in terms of their use today, and migration to WCF in the future. If you are developing n-tier client/server systems, this session is a must!

Click-Once
Jeff Levinson, The Boeing Company
Have you ever wondered why everyone says the web is where it’s at? All the new applications have to be web based, but why? The answer is simple: lower cost of maintenance. No one thinks web applications are superior to desktop applications – state management is a mess, the user interface (while getting better) is hardly user friendly, and then there’s the back button on the browser. If you want a windows forms application but don’t want to pay for the cost of maintenance and the difficulty with upgrades then Click-Once is for you. Learn how to leverage the power of Click-Once to centrally deploy and update your application with virtually no effort. Learn the new security features to keep your application secure. Give your users what they want – a clean, responsive interface which is always up to date!

Special New York Hotel Rates

All VSLive! attendees are eligible for discounted room rates of $199 per night at our Conference Headquarters, the New York Marriott at the Brooklyn Bridge, one stop from Grand Central. Rooms are subject to availability and must be reserved by August 21st. Call the Marriott directly at 888-436-3759 and reference group reservation code FWTFWTA to reserve your room today!

Register Today

For your best value at VSLive! New York, register for a Gold Passport by the Early Bird deadline of August 9 and save $200. The Gold Passport is your all-access pass to every session, workshop and keynote in New York. Register online or call 800-848-5523 or 1-650-378-7100 to speak to one of our customer service representatives. Reference Priority Code TOP10.

We look forward to seeing you in New York!

FTP logo
2600 South El Camino Real
Suite 300
San Mateo, CA 94403-2332

This message was sent by Fawcette Technical Publications.
Click here to unsubscribe from this newsletter.
Click here to view our privacy policy.

posted @ Tuesday, August 01, 2006 7:54 PM | Feedback (0) |