This week in tweets (07-24-2010)

July 24, 2010 § 3 Comments

Photoshop your own Windows Phone 7 applications

It looks like Microsoft is not just making the Windows Phone 7 application development experience easy for developers, but it turns out designers have most of their job cut out for them. If you need to mock up an application UI for Windows Phone 7, it’s now as easy as mashing up some Photoshop files from the “Design Templates for Windows Phone 7″ resource. Since finding useful information on M…  read more

Windows Phone 7 in-depth preview

Source: Engadget

It’s been a long road, hasn’t it? Well, in some respects, it hasn’t — in fact, it’s only been about two years since development of Windows Phone 7 as we know it today kicked off — but when you consider that this product will be replacing Windows Mobile 6.5, that puts things in proper perspective. In fact, even the very …  read more

Google signs 20-year deal to power data centers with wind energy

Source: Engadget

It’s not the first investment Google has made in wind power, but anyone wondering about its commitment needn’t look any further than the company’s just-announced deal with NextEra Energy. It’s agreed to buy wind power from NextEra’s wind farm in Iowa for the next twenty years, which it says will provide enough power to supply "several" of its data centers. What’s more, Google says that the size…  read more

Apple posts record $3.25b profit in first full quarter of iPad sales, says more ‘amazing products’ coming this year

Source: Engadget

Apple just posted up its third quarter earnings — its first full quarter selling the iPad — and, well, it’s raining cash in Cupertino. The company posted a record profit of $3.25b on record revenues of $15.7b, which is up from $1.83b and $9.73b from a year ago. The big stat? Apple sold 3.27 million iPads, nearly matching the 3.47 million Macs sold — and Mac sales were up 33 percent from a ye…  read more

Uploading a File (Or Files) With ASP.NET MVC

I wanted to confirm something about how to upload a file or set of files with ASP.NET MVC and the first search result for the phrase “uploading a file with mvc” is Scott Hanselman’s blog post…  read more

Apple TV Rumored To Get $.99 TV Show Rentals, But Will The iPad And iPhone Get The Service Too?

Source: TechCrunch

The Apple TV might suddenly be part of the next big thing from Apple. We’ve heard that there’s a major retooling underway and Apple shifted some of their best people on the project. Updated hardware is likely, but new services will likely be at the forefront of the relaunch. The latest rumor states that Apple is in contract talks to bring TV show rentals to the platform. They would probably wo…  read more

The articles listed in this post are random selections from my Google Buzz account and are not my work. You may need to obtain authorization from the owner by clicking the source for each article before using them.


Server side conversion of UserControl to html

December 24, 2009 § 1 Comment

In order to get the html out of an ASP.NET control you can use the following code:

string pathToUserControl = "~/Controls/MyUserControl.ascx";
System.Web.UI.Page page = new System.Web.UI.Page();
System.Web.UI.UserControl control = page.LoadControl(pathToUserControl);
StringWriter writer = new StringWriter();
HttpContext.Current.Server.Execute(page, writer, false);
string renderedHtml = writer.ToString();

This method is mostly used to send the html back to the client browser using web services.

Strongly typed view in ASP.NET MVC

December 21, 2009 § Leave a comment

When passing the model to MVC you have a couple of options.

Option 1: Passing un-typed model to the view

public ActionResult Product(string id)
    var product = new Product();

    product.ID = id;
    product.Name = "iPhone";

    ViewData["product"] = product;

In your view you have to cast the value in ViewData to the correct type as follows:

    var item = (Product)ViewData["product"];
    ID: <%= item.ID %>
    Name: <%= item.Name %>

Option 2: Pass a strongly typed model to the view

// ViewData["product"] = product;
ViewData.Model = product;

The Page directive of your view must specify the type it expects as follows:

<%@ Page Title="blah" ... Inherits="System.Web.Mvc.ViewPage<Product>" %>

Sometimes you may need to pass more than one object to the view. You can handle this by creating a new class that encapsulates all objects you need and pass an instance of that class to the view instead.

How to force SSL on your ASP.NET website?

March 27, 2008 § Leave a comment

I have seen may implementations of forcing SSL on websites that require changes to IIS and creating dummy aspx pages for the redirect, but nothing beats the simple and elegant code that follows:

Courtesy: IKOSoftware

// Force SSL
Uri currentUrl = System.Web.HttpContext.Request.Url;
if (!currentUrl.IsLoopback)
    if (!currentUrl.Scheme.Equals(Uri.UriSchemeHttps, 
        // Build the Secure Uri
        UriBuilder secureUrlBuilder = new UriBuilder(currentUrl);
        secureUrlBuilder.Scheme = Uri.UriSchemeHttps;
        // Use the default port.
        secureUrlBuilder.Port = -1;
        // Redirect and end the response

We just got AJAXed

January 23, 2007 § 4 Comments

Woohoo! Microsoft has released the final version (1.0) of ASP.NET AJAX library. That means we can finally write production quality AJAX applications. Microsoft fully supports the library and is giving out the source code for the entire library for free. You can modify and re-distribute the source code at will for both commercial and non-commercial applications. You can read more about this on Scott Guthrie’s blog. The AJAX library will be embedded into the next version of ASP.NET (3.0) scheduled to be released by this year end.

Update: I have updated this website to use ASP.NET AJAX 1.0 RTM build Cool


HTTP Compression

October 5, 2006 § Leave a comment

I serve my website off of my home computer which has a decent broadband connection. The upload speed however is a mere 384KB, which used to make my web pages slow in loading up until I enabled HTTP compression and let me tell you it is a real blessing. Not only does it save a lot of bandwidth, but more importantly my pages are a lot more responsive.

Most modern browsers support two compression algorithms, GZip and Deflate. I am using Blowery an open source compression software for serving my web pages in Deflate compression mode. The other thing I enabled last week on my site was AJAX using the new Microsoft Atlas Framework. What I saw was that one of the JavaScript files served to the browser was a whopping 242KB. Although script files get cached by the browser, the speed on the first serving on my web page would be aweful.

The Javascript files are served through a new concept in ASP.NET called Web Resources, where you can embed JavaScript and image files directly into your assembly as resources. When the ASP.NET engine gets a request for these resources it extracts these files out of the assembly and serves them. The file that does is called WebResource.axd. I don’t have a clue as to what that file is / does, but I will do some reasearch to find out. The point is that by enabling Blowery the JavaScripts on my web pages stop working. I found a patch for this. You have to add the following lines to the httpCompress section required by blowery in the web.config

      <add path="ebresource.axd"/>
      <add path="webresource.axd"/> 

Having fixed the web pages, I still wanted to do something about those huge Atlas files. Luckily some smart Atlas developers at Microsoft have coded a compression routine for the resource files that are served through webresource.axd. You can enable it by adding the following line in the httpModules section to your web.config.

      <add name="WebResourceCompression"
           type="Microsoft.Web.Services.WebResourceCompressionModule" />

An important point to note is that this needs to be above the blowery http module. That is blowery also is an httpModule that needs to be added to the httpModules section in the web.config. However by keeping the add tag for blowery above the atlas module, my Atlas JavaScripts were not getting compressed. Moving the tag fixed the problem.

Have fun!

Enable AJAX with Atlas

October 2, 2006 § Leave a comment

Start off by downloading and installing the latest CTP from the site. Watch the "Get Started with “Atlas”?" video on this page to install and setup Visual Studio to be Atlas ready. You can then watch the other videos that show how to use some neat tricks to avoid server postbacks.

For the view comments feature on my blog, I created the following:

  • A custom control (by extending System.Web.UI.WebControls.WebControl) that accepts a dataset as a property and loops through the dataset in the Render method to output the necessary html.
  • A webservice that talks to my business logic, gets the necessary data, passes it to the custom control and outputs whatever the control renders.

Let’s look at a simple example:


public class HelloControl : WebControl
      private string _text; 

      public string Text
            get { return _text; }
            set { _text = value; }

      protected override void Render(HtmlTextWriter writer)
         writer.Write("<span style='font-weight:bold;color:#dd0000'>Hello "
                       + _text + "</span>");

All this control does is given an input text, it outputs the text in bold and red.


class HelloService : WebService 
      public string SayHello(string name) 
            HelloControl c = new HelloControl(); 

            StringWriter writer = new StringWriter(); 
            HtmlTextWriter htmlWriter = new HtmlTextWriter(writer); 


            return writer.ToString(); 

That’s it, you now have a webservice that spits out html which can then be used to fill certain sections of your web page. You can watch the "“Atlas” Enable an Existing Web Service?" video to see how to use webservices on the client side using Atlas.

Have fun!

Where Am I?

You are currently browsing the ASP.NET category at