Follow me on Twitter at Twitter.com/wbm
FYI, I'm blogging most of my stuff over at More Wally now.
You might want to add my rss feed to your reader at:http://morewally.com/cs/blogs/wallym/rss.aspx
December 2008 - Posts - Wallace B. McClure

Wallace B. McClure

All About Wally McClure - The musings of Wallym on Web, HTML5, Mobile, Xamarin.iOS, Xamarin.Android, and Windows Azure.

News

Visual Studio Magazine Column Personal Blog

.NET

Book Authors

Business

Family

Friends

Georgia Tech Bloggers

Personal

Archives

December 2008 - Posts

ASP.NET Providers with Windows Azure

 

Are you trying to get the ASP.NET Provider code working in a separate application with Windows Azure?  If so, check out this item from the read me file:

  • Make sure that the Table Storage service is running in development storage. Also make sure that the database called 'ServiceHostingSDKSamples' is currently selected for the table service; choose Development Storage -> Tools -> Table service properties -> ServiceHostingSDKSamples. 

I missed this and got the error message below:

<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>
<error xmlns=\"http://schemas.microsoft.com/ado/2007/08/dataservices/metadata\">
<code></code>
<message xml:lang=\"en-US\">Attempt to create table 'Sessions' failed. Creating a new table dynamically is not supported in development storage</message>
</error>

I sure hope that this changes  in the future.  I'd like some way to have the asp.net membership "stuff" setup for me, like with .net 2.x.
ASP.NET 3.5 Service Pack 1 Wrox Blox

My eBook ASP.NET 3.5 Service Pack 1 Wrox Blox is now for sale.  Please buy 3 or 4 copies for the ones you love.

Seriously, there is a lot of good solid material on the new features, especially AJAX History, Routing, and other new features.  Please check it out.

Some interesting things I am finding about Windows Azure
  • Queue messages have a max size of 8kb.
  • Queued messages in azure are typed.
  • If you are interested in #Azure, I would suggest following @smarx on twitter.com.
  • Transaction support will come in future #Azure CTPs.
  • ACID Transactions are only supported on single entity updates at this time in azure.
  • Azure table writes are synchronous.
  • In the commercial release, MS will offer some control over geodistribution and georeplication. Info is scarce at this time.
  • In the CTP, Azure runs in "a single datacenter on the US west coast."
  • The lease timeframe appears to be configurable. The default is 30 seconds.
  • You can hold a lease on message in an azure queue. No one else can see it during the lease. This is good.

These are just some of the things I have found while reading online.  As I find out more, I'll be posting. If you want immediate access to my info, go to twitter.com and follow me (@wbm)

ASP.NET Podcast Show #133 - Windows Azure Table Storage - video

Subscribe to All!

Subscribe to WMV.

Subscribe to M4V (iPod).

Subscribe to MP3.

Download WMV.

Download M4V (iPod).

Download MP3.

Win a ticket to the MDC in Detroit.  Enter here. 

Original Url: http://aspnetpodcast.com/CS11/blogs/asp.net_podcast/archive/2008/12/25/asp-net-podcast-show-133-windows-azure-table-storage-video.aspx

Show Notes:

  • CRUD Application
  • CRUD application.
  • Message.
  • Message Data Service Context.
  • This example is taken from Hands On Labs.

Source Code for Default.aspx.cs:

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.Services.Client;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Microsoft.Samples.ServiceHosting.StorageClient;
using Microsoft.ServiceHosting.ServiceRuntime;

namespace TableCloudService_WebRole
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string statusMessage = String.Empty;
            if (!Page.IsPostBack)
            {
                DisplayMessages();
            }
        }

        protected void lbDisplayMessages_Click(object sender, EventArgs e)
        {
            DisplayMessages();
        }

        protected void OnDeleteMessage(object sender, CommandEventArgs e)
        {
            LinkButton lb = (LinkButton)sender;
            GridViewRow gvr = (GridViewRow)lb.Parent.Parent;

            if (e.CommandName == "Delete")
            {
                string PartitionKey = ((HiddenField)gvr.FindControl("hdPartitionKey")).Value;
                string RowKey = ((HiddenField)gvr.FindControl("hdRowKey")).Value;
                string TimeStamp = ((HiddenField)gvr.FindControl("hdTimeStamp")).Value;
                string Body = ((TextBox)gvr.FindControl("txtBody")).Text;
                string Name = ((TextBox)gvr.FindControl("txtName")).Text;
                MessageDataServiceContext context = GetContext();

                //var m = (from mess in context.Messages
                //         where
                //             (mess.PartitionKey == PartitionKey) &&
                //             (mess.RowKey == RowKey)
                //         select mess).Single();
                var m = new Message();
                m.PartitionKey = PartitionKey;
                m.RowKey = RowKey;
                m.Timestamp = Convert.ToDateTime(TimeStamp);
                context.AttachTo("Messages", m, "*");
               
                context.DeleteMessage(m);
                RoleManager.WriteToLog("Verbose", "Delete Message.");
                DisplayMessages();
            }
        }
        protected void OnUpdateMessage(Object sender, CommandEventArgs e)
        {
            LinkButton lb = (LinkButton)sender;
            GridViewRow gvr = (GridViewRow)lb.Parent.Parent;

            if (e.CommandName == "Update")
            {
                string PartitionKey = ((HiddenField)gvr.FindControl("hdPartitionKey")).Value;
                string RowKey = ((HiddenField)gvr.FindControl("hdRowKey")).Value; ;
                string TimeStamp = ((HiddenField)gvr.FindControl("hdTimeStamp")).Value; ;
                string Body = ((TextBox)gvr.FindControl("txtBody")).Text; ;
                string Name = ((TextBox)gvr.FindControl("txtName")).Text; ;
                MessageDataServiceContext context = GetContext();

                //var m = (from mess in context.Messages
                //         where
                //             (mess.PartitionKey == PartitionKey) &&
                //             (mess.RowKey == RowKey)
                //         select mess).First();
                var m = new Message();
                m.PartitionKey = PartitionKey;
                m.RowKey = RowKey;
                m.Timestamp = Convert.ToDateTime(TimeStamp);
                m.Body = Body;
                m.Name = Name;
                context.AttachTo("Messages", m, "*");
                context.UpdateMessage(m);
                RoleManager.WriteToLog("Information",  "Update complete.");
                DisplayMessages();
            }
        }

        protected void Timer1_OnTick(Object sender, EventArgs e)
        {
            DisplayMessages();
        }

        private void DisplayMessages()
        {
            MessageDataServiceContext context = GetContext();
            RoleManager.WriteToLog("Verbose", "Display Messages.");
            messageList.DataSource = context.Messages.Take(10);
            messageList.DataBind();
        }

        private MessageDataServiceContext GetContext()
        {
            MessageDataServiceContext context;
            StorageAccountInfo accountInfo = StorageAccountInfo.GetAccountInfoFromConfiguration("TableStorageEndpoint");
            TableStorage.CreateTablesFromModel(typeof(MessageDataServiceContext), accountInfo);
            context = new MessageDataServiceContext(accountInfo);
            RoleManager.WriteToLog("Verbose", "Message Data Service Context created.");
            return context;
        }

        protected void SubmitButton_Click(object sender, EventArgs e)
        {
            StorageAccountInfo accountInfo = StorageAccountInfo.GetAccountInfoFromConfiguration("TableStorageEndpoint");
            MessageDataServiceContext context = new MessageDataServiceContext(accountInfo);
            context.AddMessage(this.nameBox.Text, this.messageBox.Text);
            nameBox.Text = String.Empty;
            messageBox.Text = String.Empty;
            DisplayMessages();
        }
    }
}

Source Code for Default.aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="TableCloudService_WebRole._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Azure Table Example Page</title>
        <style type="text/css">
        body { font-family: Verdana; font-size: 9pt; }
        h1 { font-size: 12pt; color: #555555; }
        li { list-style-type: none; }
        form { background-color: #eeeeff; width: 80%; margin: 0 auto; padding: 1em; border: solid 1px #333333; }
        #entryform, #messages { margin: 1em 0 }
        #entryform li span { float: left; width: 15%; color:#333333; margin-top:0.25em; }
        #entryform input[type="text"] { border: solid 1px #999999; }
        #messages { border: solid 1px #999999; }
        #messages li { padding: 0.5em; }
        .error { color: #ff0000; }
        .even { background-color: #ccccff; }
        .odd { background-color: #ffffff; font-style: italic; }       
        .messageBox { width: 73%; }
    </style>

</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="sm" runat="server" />
    <div>
        <h1>Windows Azure Chat</h1>
        <ul id="entryform">
            <li><span>Your name</span><asp:TextBox ID="nameBox" runat="server" Text="Anonymous" /></li>
            <li><span>Message</span><asp:TextBox ID="messageBox" runat="server" CssClass="messageBox" /> <asp:Button ID="submitButton" runat="server" Text="Submit" OnClick="SubmitButton_Click" /></li>
            <li><span><asp:LinkButton ID="lbDisplayMessages" runat="server" OnClick="lbDisplayMessages_Click" Text="Update Messages" /></span></li>
        </ul>
                <div>
                    <asp:Label ID="status" runat="server" CssClass="error" />
                </div>
                <asp:GridView ID="messageList" runat="server" AutoGenerateColumns="false">
                    <AlternatingRowStyle CssClass="even" />
                    <RowStyle CssClass="odd" />
                    <Columns>
                    <asp:TemplateField HeaderText="Name">
                    <ItemTemplate>
                        <asp:HiddenField ID="hdPartitionKey" runat="server" Value='<%#Eval("PartitionKey") %>' />
                        <asp:HiddenField ID="hdRowKey" runat="server" Value='<%#Eval("RowKey") %>' />
                        <asp:HiddenField ID="hdTimeStamp" runat="server" Value='<%#Eval("TimeStamp") %>' />
                        <asp:HiddenField ID="hdName" runat="server" Value='<%#Eval("Name") %>' />
                        <asp:HiddenField ID="hdBody" runat="server" Value='<%#Eval("Body") %>' />
                        <asp:TextBox ID="txtName" runat="server" Text='<%# Eval("Name") %>' />
                        said:
                    </ItemTemplate>
                    </asp:TemplateField>                   
                    <asp:TemplateField HeaderText="Message">
                    <ItemTemplate>
                        <asp:TextBox ID="txtBody" runat="server" Text='<%# Eval("Body") %>' />
                    </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Operations">
                    <ItemTemplate>
                        <asp:LinkButton ID="updateMessage"
                            CommandName="Update"
                            runat="server" Text="Update" OnCommand="OnUpdateMessage" />
                        <asp:LinkButton ID="deleteMessage"
                            OnClientClick="return confirm('Delete Message?');"
                            CommandName="Delete"
                            runat="server" Text="Delete" OnCommand="OnDeleteMessage" />               
                    </ItemTemplate>
                    </asp:TemplateField>
                    </Columns>
                </asp:GridView>
    </div>
    </form>
</body>
</html>

Source for Message.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.Samples.ServiceHosting.StorageClient;

namespace TableCloudService_WebRole
{
    public class Message : TableStorageEntity
    {
        //private string PartitionKey;
        //private string RowKey;
        public string Name { get; set; }
        public string Body { get; set; }

        public Message()
        {
            PartitionKey = "a";
            RowKey = String.Format("{0:10},{1}", DateTime.MaxValue.Ticks - DateTime.Now.Ticks,
                Guid.NewGuid().ToString());
        }
    }
}

Source for MessageDataServiceContext.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.Samples.ServiceHosting.StorageClient;

namespace TableCloudService_WebRole
{
    public class MessageDataServiceContext : TableStorageDataServiceContext
    {
        public MessageDataServiceContext(StorageAccountInfo accountInfo) : base(accountInfo)
        {
        }

        public IQueryable<Message> Messages
        {
            get
            {
                return this.CreateQuery<Message>("Messages");
            }
        }

        public void AddMessage(string name, string body)
        {
            Message MessageEntity = new Message { Name = name, Body = body };
            this.AddObject("Messages", MessageEntity);
            this.SaveChanges();
        }

        public void DeleteMessage(Object MessageEntity)
        {
            this.DeleteObject(MessageEntity);
            this.SaveChanges();
        }

        public void UpdateMessage(Object MessageEntity)
        {
            this.UpdateObject(MessageEntity);
            this.SaveChanges();
        }
    }
}
ASP.NET Podcast Show #132 - Windows Azure Blob Storage - video

Subscribe to All!

Subscribe to WMV.

Subscribe to M4V (iPod).

Subscribe to MP3.

Download WMV.

Download MP4 for iPod.

Download MP3 (audio only).

Win a ticket to the MDC in Detroit.  Enter here.

ASP.NET Podcast Url: http://aspnetpodcast.com/CS11/blogs/asp.net_podcast/archive/2008/12/22/asp-net-podcast-show-132-windows-azure-blob-storage-video.aspx

Show Notes:

  • Azure SDK.
    •  Vista SP1.
    • Visual studio 2008/.NET 3.5 SP1.
    • Local Development.Speed.
    • VPC.
    • Improvements are coming.
    • YMMV.
  • Project type.
    • Configuration settings.
    • Web Project.
  • Storage Client.
  • Local Development Fabric.
  • Local Development Storage.
  • Hands on Labs. This example is taken, with modifications, from the hands on labs.

Local Development Storage Setup:

Development Storage Setup

Local Development Storage:

Storage Icon

Source Code for Default.aspx.cs file:

using System;
using System.Collections;
using System.Collections.Specialized;
using System.Configuration;
using System.Data;
using System.Globalization;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Microsoft.ServiceHosting.ServiceRuntime;
using Microsoft.Samples.ServiceHosting.StorageClient;

namespace CloudImageService_WebRole
{
    public partial class _Default : System.Web.UI.Page
    {
        private string unknownValue = "unknown";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                RefreshGallery();
            }
        }

        protected void upload_Click(object sender, EventArgs e)
        {
            if (imageFile.HasFile)
            {
                status.Text = "Inserted [" + imageFile.FileName +
                    "] - Content Type [" + imageFile.PostedFile.ContentType + "]";
                SaveImages(Guid.NewGuid().ToString(), imageName.Text, imageDescription.Text,
                    imageTags.Text, imageFile.FileName, imageFile.PostedFile.ContentType,
                    imageFile.FileBytes);
                imageTags.Text = String.Empty;
                imageDescription.Text = String.Empty;
                imageName.Text = String.Empty;
                RefreshGallery();
            }
            else{
                status.Text = "No image file uploaded.";
            }
        }

        private void SaveImages(string id, string name, string description, string tags, string fileName, string contentType, byte[] data)
        {
            BlobProperties properties = new BlobProperties(string.Format(CultureInfo.InvariantCulture, "image_{0}", id));
            NameValueCollection metadata = new NameValueCollection();
            BlobContainer container = GetContainer();
            metadata["Id"] = id;
            metadata["Filename"] = fileName;
            metadata["ImageName"] = String.IsNullOrEmpty(name) ? unknownValue : name;
            metadata["Description"] = String.IsNullOrEmpty(description) ? unknownValue : description;
            metadata["Tags"] = String.IsNullOrEmpty(tags) ? unknownValue : tags;
            properties.Metadata = metadata;
            properties.ContentType = contentType;
            BlobContents imageBlob = new BlobContents(data);
            container.CreateBlob(properties, imageBlob, true);
           
        }

        protected void OnBlobDataBound(object sender, ListViewItemEventArgs e)
        {
            BlobContainer container = GetContainer();
            if (e.Item.ItemType == ListViewItemType.DataItem)
            {
                Repeater metadataRepeater = e.Item.FindControl("blobMetadata") as Repeater;
                BlobProperties blob = ((ListViewDataItem)(e.Item)).DataItem as BlobProperties;
                NameValueCollection metadata = container.GetBlobProperties(blob.Name).Metadata;
                metadataRepeater.DataSource = from key in metadata.AllKeys
                                              select new
                                              {
                                                  Name = key,
                                                  Value = metadata[key]
                                              };
                metadataRepeater.DataBind();
            }
        }

        protected void OnDeleteImage(object sender, CommandEventArgs e)
        {
            BlobContainer container = GetContainer();
            if (e.CommandName == "Delete")
            {
                string blobName = (string)e.CommandArgument;
                if (container.DoesBlobExist(blobName))
                {
                    container.DeleteBlob(blobName);
                }
                else
                {
                    status.Text = "Item does not exist";
                }
                RefreshGallery();
            }
        }

        private void RefreshGallery()
        {
            BlobContainer container = GetContainer();
            images.DataSource = container.ListBlobs(String.Empty, false);
            images.DataBind();
        }

        /// <summary>
        /// This is code written against an early CTP.
        /// It is neither production ready or a best of breed.
        /// It is merely code that works today.
        /// </summary>
        /// <returns></returns>
        private BlobContainer GetContainer()
        {
            string blobContainer = RoleManager.GetConfigurationSetting("ContainerName");
            BlobStorage blobStorage = BlobStorage.Create(StorageAccountInfo.GetDefaultBlobStorageAccountFromConfiguration());
            BlobContainer newContainer = blobStorage.GetBlobContainer(blobContainer);
            if (!newContainer.DoesContainerExist())
            {
                newContainer.CreateContainer(null, ContainerAccessControl.Public);
            }
            return (newContainer);
        }
    }
}

Source code for Default.aspx:

 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="CloudImageService_WebRole._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Azure Blob Storage Engine Page</title>
        <style type="text/css">
        body { font-family: Verdana; font-size: 12px; }
        h1 { font-size:x-large; font-weight:bold; }
        h2 { font-size:large; font-weight:bold; }
        img { width:200px; height:175px; margin:2em;}
        li { list-style: none; }
        ul { padding:1em; }
        
        .form { width:50em; }
        .form li span {width:30%; float:left; font-weight:bold; }
        .form li input { width:70%; float:left; }
        .form input { float:right; }
        
        .item { font-size:smaller; font-weight:bold; }
        .item ul li { padding:0.25em; background-color:#ffeecc; }
        .item ul li span { padding:0.25em; background-color:#ffffff; display:block; font-style:italic; font-weight:normal; }
    </style>

</head>
<body>
    <form id="form1" runat="server">
    <div>
            <h1>Image Gallery (Windows Azure Blob Storage)</h1>
        <div class="form">
            <ul>
                <li><span>Name</span><asp:TextBox ID="imageName" runat="server"/></li>
                <li><span>Description</span><asp:TextBox ID="imageDescription" runat="server"/></li>
                <li><span>Tags</span><asp:TextBox ID="imageTags" runat="server"/></li>
                <li><span>Filename</span><asp:FileUpload ID="imageFile" runat="server" /></li>
            </ul>
            <asp:Button ID="upload" runat="server" onclick="upload_Click" Text="Upload Image" />
        </div>
        <div>
        Status: <asp:Label ID="status" runat="server" />
        </div>

            <asp:ListView ID="images" runat="server" OnItemDataBound="OnBlobDataBound">
            <LayoutTemplate>
                <asp:PlaceHolder ID="itemPlaceholder" runat="server" />
            </LayoutTemplate>
            <EmptyDataTemplate>
                <h2>No Data Available</h2>
            </EmptyDataTemplate>            
            <ItemTemplate>            
                <div class="item">
                    <ul style="width:40em;float:left;clear:left" >
                    <asp:Repeater ID="blobMetadata" runat="server">
                    <ItemTemplate>
                        <li><%# Eval("Name") %><span><%# Eval("Value") %></span></li>
                    </ItemTemplate>
                    </asp:Repeater>
                    <%-- UNCOMMENT THE FOLLOWING LINES FOR DELETE FUNCTIONALITY --%>
                        <li>
                        <asp:LinkButton ID="deleteBlob"
                                OnClientClick="return confirm('Delete image?');"
                                CommandName="Delete"
                                CommandArgument='<%# Eval("Name")%>'
                                runat="server" Text="Delete" oncommand="OnDeleteImage" />                
                        </li>
                    </ul>                    
                    <img src="<%# Eval("Uri") %>" alt="<%# Eval("Name") %>" style="float:left"/>
                </div>
            </ItemTemplate>
        </asp:ListView>
    </div>
    </form>
</body>
</html>

.csdef file:

<?xml version="1.0" encoding="utf-8"?>
<ServiceDefinition name="CloudImageService" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition">
  <WebRole name="WebRole">
    <InputEndpoints>
      <!-- Must use port 80 for http and port 443 for https when running in the cloud -->
      <InputEndpoint name="HttpIn" protocol="http" port="80" />
    </InputEndpoints>
    <ConfigurationSettings>
      <Setting name="AccountName" />
      <Setting name="AccountSharedKey" />
      <Setting name="BlobStorageEndpoint" />
      <Setting name="QueueStorageEndpoint" />
      <Setting name="TableStorageEndpoint" />
      <Setting name="ContainerName" />
    </ConfigurationSettings>
  </WebRole>
</ServiceDefinition>

cscfg file:

<?xml version="1.0"?>
<ServiceConfiguration serviceName="CloudImageService" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration">
  <Role name="WebRole">
    <Instances count="1"/>
    <ConfigurationSettings>
        <Setting name="AccountName" value="devstoreaccount1" />
        <Setting name="AccountSharedKey" value="Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==" />
        <Setting name="BlobStorageEndpoint" value="http://127.0.0.1:10000/" />
        <Setting name="QueueStorageEndpoint" value="http://127.0.0.1:10001/" />
        <Setting name="TableStorageEndpoint" value="http://127.0.0.1:10002/" />
        <Setting name="ContainerName" value="storagegallery" />
    </ConfigurationSettings>
  </Role>
</ServiceConfiguration>
ASP.NET Podcast Show #131 - General discussions on Cloud Computing with Wally, David, and Scott Cate - mp3 audio

Subscribe to everything!

Subscribe to the MP3 file(s) only.

Download.

ASP.NET Podcast Url: http://aspnetpodcast.com/CS11/blogs/asp.net_podcast/archive/2008/12/22/asp-net-podcast-show-132-windows-azure-blob-storage-video.aspx

Show Notes:

  • General discussions on  Cloud Computing.
  • Scott on CloudDB.  Scott gets into the specifics of CloudDB, including how to let customer's setup databases.
ASP.NET Podcast Show #130 - David and Wally talk about .NET 3.5 Service Pack 1

Subscribe to Everything.

Subscribe to MP3.

Download.

Show Notes:

ASP.NET Podcast Show #129 - Caching with .NET 3.5 SP1

Subscribe to All!

Subscribe to WMV.

Subscribe to M4V (iPod).

Subscribe to MP3.

Download WMV.

Download M4V (iPod).

Download MP3.

Original Url: http://aspnetpodcast.com/CS11/blogs/asp.net_podcast/archive/2008/12/04/asp-net-podcast-show-129-caching-with-net-3-5-sp1.aspx

Show Notes:

  • New Caching Support in .NET 3.5 SP1.

Source Code:

    protected void Page_Load(object sender, EventArgs e)

    {

        string Output = String.Empty;

        if (!Page.IsPostBack)

        {

            lblOutput.Text = GetCacheItem();

        }

    }

 

    private string GetCacheItem()

    {

        string OutValue = String.Empty;

        if (Cache["Test"] != null)

        {

            OutValue = Convert.ToString(Cache["Test"]);

        }

        else

        {

            OutValue = DateTime.Now.ToString();

            Cache.Insert("Test", OutValue, null,

                DateTime.Now.AddSeconds(10),

                TimeSpan.Zero, OnUpdateCallback);

        }

        return (OutValue);

    }

    private void OnUpdateCallback(String key, CacheItemUpdateReason r,

        out Object ObjectToCreate, out CacheDependency CacheDependencies,

        out DateTime DateTimeExpire, out TimeSpan TimeSpanExpire)

    {

        ObjectToCreate = DateTime.Now;

        CacheDependencies = null;

        DateTimeExpire = DateTime.Now.AddSeconds(10);

        TimeSpanExpire = TimeSpan.Zero;

    }

 

ASP.NET Podcast Show #128 - AJAX with jQuery

Subscribe to All!

Subscribe to WMV.

Subscribe to M4V (iPod).

Subscribe to MP3.

Download WMV.

Download iPod Video.

Download MP3.

Original Url: http://aspnetpodcast.com/CS11/blogs/asp.net_podcast/archive/2008/12/03/asp-net-podcast-show-128-ajax-with-jquery.aspx

Show Notes:

Source Code:

jQuery Version:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title>jQuery Example</title>

</head>

<body>

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

<!--

<script language="javascript" type="text/javascript"

    src="jquery-1.2.6-vsdoc.js"></script>

-->

<script language="javascript" type="text/javascript"

    src="jquery.pack.js"></script>

<div>

<label for="lblOutput">

    Text Out:

</label>

<div id="lblOutput" />

 

<script language="javascript" type="text/javascript">

    $(document).ready(function() {

        $.ajax({

            type: "POST",

            contentType: "application/json; charset=utf-8",

            url: "GetData.asmx/ReturnData",

            data: "{i: 47}",

            dataType: "json",

            success: function(msg) { onSuccess(msg); },

            error: function() {

                alert("An error occurred on the server.");

            }

        });

    });

 

    function onSuccess(msg) {

        var newline = "<br />";

        $('#lblOutput').html("Name: " + msg.d.Name + newline +

                "Notes: " + msg.d.Notes + newline +

                "Passed Value: " + msg.d.PassedValue);

    }

</script>

 

</div>

    </form>

</body>

</html>

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

ASP.NET AJAX Version:

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title></title>

    <script type="text/javascript">

   

      function pageLoad() {

          GetData.ReturnData(47, onSuccess);

      }

      function onSuccess(result) {

          var newline = "<br />";

          $get('lblOutput').innerHTML = "Name: " + result.Name +

                newline + "Notes: " + result.Notes + newline +

                "Passed Value: " + result.PassedValue;

 

      }

   

    </script>

</head>

<body>

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

<label for="lblOutput">

    Text Out:

</label>

    <div id="lblOutput" />

 

    <div>

        <asp:ScriptManager

            ID="ScriptManager1" runat="server"

            >

            <Services>

                <asp:ServiceReference

                    Path="~/jQuery/GetData.asmx" />

            </Services>

            </asp:ScriptManager>

    </div>

    </form>

</body>

</html>
More Posts