Scott Hanselman

Hanselminutes Podcast 222 - Art is Shipping - Designers and Developers with Jin Yang

July 16, '10 Comments [4] Posted in Podcast | Programming
Sponsored By

Random Giant Robot Picture My two-hundred-and-twenty-second podcast is up. Scott sits down with designer Jin Yang (@jzy) to talk about the fundamental differences between developers and designers. Are we a totally different breed? How should designers and developers work together? Should designers code their own sites?

NOTE: If you want to download our complete archives as a feed - that's all 219 shows, subscribe to the Complete MP3 Feed here.

Subscribe: Subscribe to Hanselminutes Subscribe to my Podcast in iTunes

Download: MP3 Full Show

Links from the Show

Do also remember the complete archives are always up and they have PDF Transcripts, a little known feature that show up a few weeks after each show.

Telerik is our sponsor for this show.

 Hansel_Promo

Hanselminutes podcasts listeners can get $50 off any Telerik product this summer. All interested listeners should drop an email to podcast@telerik.com and mention the Hanselminutes promo and their sales team will reply with the special $50-off coupon code.

Building quality software is never easy. It requires skills and imagination. We cannot promise to improve your skills, but when it comes to User Interface and developer tools, we can provide the building blocks to take your application a step closer to your imagination. Explore the leading UI suites for ASP.NET AJAX,MVC,Silverlight,Windows Formsand WPF. Enjoy developer tools like .NET reporting,ORM,Automated Testing Tools, TFS, and Content Management Solution. And now you can increase your productivity with JustCode, Telerik’s new productivity tool for code analysis and refactoring. Visitwww.telerik.com.

As I've said before this show comes to you with the audio expertise and stewardship of Carl Franklin. The name comes from Travis Illig, but the goal of the show is simple. Avoid wasting the listener's time. (and make the commute less boring)

Enjoy. Who knows what'll happen in the next show?

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Hanselminutes Podcast 221 - Hanselminutiae-eight with Dan Fernandez

July 16, '10 Comments [1] Posted in Podcast
Sponsored By

image My two-hundred-and-twenty-first podcast is up. This week it's a very sick Dan Fernandez from Channel 9 who joins me on the show for a random Hanselminutiae. We talk iPads, Windows Phone 7, Hulu Plus, TimeSvr, innovation and more. Dan is the co-host of This Week on Channel 9, a random and cool weekly video show on Channel 9 that you can subscribe to here!

NOTE: If you want to download our complete archives as a feed - that's all 219 shows, subscribe to the Complete MP3 Feed here.

Subscribe: Subscribe to Hanselminutes Subscribe to my Podcast in iTunes

Download: MP3 Full Show

Links from the Show

Do also remember the complete archives are always up and they have PDF Transcripts, a little known feature that show up a few weeks after each show.

Telerik is our sponsor for this show.

Hansel_Promo

Hanselminutes podcasts listeners can get $50 off any Telerik product this summer. All interested listeners should drop an email to podcast@telerik.com and mention the Hanselminutes promo and their sales team will reply with the special $50-off coupon code.

Building quality software is never easy. It requires skills and imagination. We cannot promise to improve your skills, but when it comes to User Interface and developer tools, we can provide the building blocks to take your application a step closer to your imagination. Explore the leading UI suites for ASP.NET AJAX,MVC,Silverlight,Windows Formsand WPF. Enjoy developer tools like .NET reporting,ORM,Automated Testing Tools, TFS, and Content Management Solution. And now you can increase your productivity with JustCode, Telerik’s new productivity tool for code analysis and refactoring. Visitwww.telerik.com.

As I've said before this show comes to you with the audio expertise and stewardship of Carl Franklin. The name comes from Travis Illig, but the goal of the show is simple. Avoid wasting the listener's time. (and make the commute less boring)

Enjoy. Who knows what'll happen in the next show?

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Simple Code First with Entity Framework 4 - Magic Unicorn Feature CTP 4

July 15, '10 Comments [54] Posted in ASP.NET | ASP.NET MVC | Data | IIS
Sponsored By

Space Needle made of LEGOMicrosoft's been releasing a number of right-sized LEGO pieces lately. In case you missed it, Betas have been announced for:

  • SQL 4 Compact Edition - It has a small embedded file-based SQL Database, and a web-server called IIS Express that's compatible with the full version of IIS.
  • "Razor" Page Syntax - A way to make pages/ViewEngine called "Razor." Your sites can be later be expanded to use all of ASP.NET MVC. It's a simple syntax that is easy to learn.
  • WebMatrix - It's a small (15 megs if you have .NET 4, 50megs if you don't) lightweight IDE for making ASP.NET or PHP websites. Good for non-pro developers.
    • It uses the WebDeploy engine to deploy apps to hosts, setting up permissions, copying databases, etc.
    • WebMatrix also has the free Search Engine Optimization Toolkit built in, so you can spider your own site and see how Search Engines see it. It'll make recommendations and store reports.
  • IIS Express - A version of the IIS 7.5 Web Server that can be run as non-admin, isn't installed as a service, that will also integrate with Visual Studio

More details to come on all this. Howver, on the tooling side, I did get a chance to talk to Damian Edwards, a developer working on some of this stuff and I put video up on Channel 9 yesterday.

There's lots of cool pieces that are packaged up with WebMatrix initially, but these pieces are interesting for pro developers as well.

Still, something's missing.

imageIn my mind, it's been too hard to talk to databases. I like LINQ to SQL and used it on the first NerdDinner version, but since EF4 sucks so much less is way better than earlier versions of EF, Jon and I updated NerdDinner to use EF. It was easy, but I would have liked to code first, and code only if I could.

Microsoft announced a new Entity Framework CTP today. It has the romantic and wonderful name "Microsoft ADO.NET Entity Framework Feature CTP4" which is lame. You can say "EF Feature CTP4" but I like "EF Magic Unicorn Edition" but that's just me. We're getting the tech better at Microsoft but still can't get naming right. Whadayagonnado? Still, it makes EF a pleasure.

It's got a lot of interesting features and choices, and while it's still a CTP, you should take a minute and check it out. 

To get a more detailed version of this walkthrough plus downloadable sample code, check out the ADO team's excellent blog post.

Quick CRUD via a Code First Model

After you install it (it won't mess up your system if you do), go and create a new whatever project. For my little example, I'll make a new ASP.NET MVC Website. It works for me better than a console app to illustrate a point.

Add a reference to Microsoft.Data.Entity.CTP.dll.

image

Make a new class, maybe in the Models folder, and name it something like Book. Add some code like this. Notice it's just code. Nothing derives from anything.

public class Book
{
[Key]
public int ISBN { get; set; }
[Required]
public string Title { get; set; }
public DateTime FirstPublished { get; set; }
public bool IsFiction { get; set; }
}

Notice I've put [Key] and [Required] on this class, but if that bothers me, I could put these kinds of declarations in a more fluent way in my database context class, in OnModelCreating.

builder.Entity<Book>().HasKey(b => b.ISBN);
builder.Entity<Book>().Property(b => b.Title).IsRequired();

To access my data, Here's a SimpleBookCatalog...

public class SimpleBookCatalog : DbContext
{
public DbSet<Book> Books { get; set; }
}

Next, I'll make a new Controller, via right|click Add Controller. I'll make a BookController.

public class BookController : Controller
{
SimpleBookCatalog db = new SimpleBookCatalog();

public ActionResult Index()
{
var books = db.Books;
return View(books);
}
...
}

I'll right click on the Index method and make an Index view. Then I'll run my app.

image

No data. What if I look in my SQL Management Studio? I got a Database created for me with a convention-based name since I didn't supply one.

SQL Management Studio with an automatically named Database

If I specified a different connection string, that DB could be anywhere.

However, if use a different database provider, like say, a SQL 4 Compact Edition one, setting it as the default in my Application_Start:

Database.DefaultConnectionFactory = new SqlCeConnectionFactory("System.Data.SqlServerCe.4.0");

Then when I run my app and look in my App_Data folder:

SQL Compact Edition Database file in App_Data

So I got a file based database without doing anything and I don't need SQL Server. (Yes, I can change the name, location, etc.) If I do nothing, I get a reasonable convention.

Next, I'll add two Create methods, one for a GET and one for a POST. In Create, I'll add my new book and save the changes:

public ActionResult Create()
{
return View();
}

[HttpPost]
public ActionResult Create(Book book)
{
db.Books.Add(book);
db.SaveChanges();
return RedirectToAction("Index");
}

I'll right click, Add View, and make a Create View. Run my app, look at the empty list, then click Create.

My Create Form

Click Create, and I'm redirected back to the Index page:

Book List

Back on the Index page, I can change the link to Details to use our primary key:

<%: Html.ActionLink("Details", "Details", new { id=item.ISBN })%> |

Create a Details View and add a Details method:

public ActionResult Details(int id)
{
var book = db.Books.Find(id);
return View(book);
}

See that Find method? That's there automatically. I can certainly use al the LINQy goodness as well, but as you can see, CRUD is simple. I can hook up Edit and Delete in a few minutes as well.

Here's the whole thing:

public class BooksController : Controller
{
SimpleBookCatalog db = new SimpleBookCatalog();

public ActionResult Index()
{
var books = db.Books;
return View(books);
}

// GET: /Books/Details/5
public ActionResult Details(int id)
{
var book = db.Books.Find(id);
return View(book);
}

// GET: /Books/Create
public ActionResult Create()
{
return View();
}

[HttpPost]
public ActionResult Create(Book book)
{
db.Books.Add(book);
db.SaveChanges();
return RedirectToAction("Index");
}

// GET: /Books/Edit/5
public ActionResult Edit(int id)
{
return View(db.Books.Find(id));
}

// POST: /Books/Edit/5
[HttpPost]
public ActionResult Edit(int id, FormCollection collection)
{
var book = db.Books.Find(id);
UpdateModel(book);
db.SaveChanges();
return RedirectToAction("Index");
}

// GET: /Books/Delete/5
public ActionResult Delete(int id)
{
var book = db.Books.Find(id);
return View(book);
}

// POST: /Books/Delete/5
[HttpPost]
public ActionResult Delete(int id, FormCollection collection)
{
db.Books.Remove(db.Books.Find(id));
db.SaveChanges();
return RedirectToAction("Index");
}
}

So that's a nice simple controller that uses a model that was written in just code. The database and its schema was created for me. The DbContext is LINQable with stuff like Add, Find, and Remove all just there. Plus, it's all EF under the hood, so if you need more complex stuff, you can do it.

For example, here's a more complex Code First Model with Collections, and more attributes. I show some fluent wiring up of relationships later on, although there are conventions that can assign bi-directionality based on naming.

public class Book
{
[Key]
public int ISBN { get; set; }
[Required]
public string Title { get; set; }
[Required]
public DateTime FirstPublished { get; set; }
[Required]
public bool IsFiction { get; set; }

public virtual Publisher Publisher { get; set; }
[RelatedTo(RelatedProperty="Author")]
public virtual Author Author { get; set; }
}

public class Person
{
[ScaffoldColumn(false)]
public int PersonId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
}

public class Author : Person
{
[ScaffoldColumn(false)]
public int AuthorId { get; set; }

public virtual ICollection<Book> Books { get; set; }
}

public class Publisher
{
[ScaffoldColumn(false)]
public int PublisherId { get; set; }
[Required]
[MaxLength(50)]
public string Name { get; set; }

public virtual ICollection<Book> Books { get; set; }
}

public class SimpleBookCatalog : DbContext
{
public DbSet<Book> Books { get; set; }
public DbSet<Person> People { get; set; }
public DbSet<Author> Authors { get; set; }
public DbSet<Publisher> Publishers { get; set; }
}

Also, "Magic Unicorn EF" supports DataAnnotations (or validation via Fluent interfaces), so those [Required] and [StringLength] stuff from before? Those apply not only in JavaScript, but also at the Server-side and Database persistence layers.

image

You can make your own strategies for creating databases, based on what's going on with the model, if it's changed, etc. Here's some built-in examples. Yours can do whatever you like. Here the SimpleBookCatalog is the DbContext from before.

//This is the default strategy.  It creates the DB only if it doesn't exist
Database.SetInitializer(new CreateDatabaseOnlyIfNotExists<SimpleBookCatalog>());
//Recreates the DB if the model changes but doesn't insert seed data.
Database.SetInitializer(new RecreateDatabaseIfModelChanges<SimpleBookCatalog>());
//Strategy for always recreating the DB every time the app is run.
Database.SetInitializer(new AlwaysRecreateDatabase<SimpleBookCatalog>());

Connection Strings for the SQL 4 CE provider are simpler (like, they are possible to memorize, which is amazing, considering how hard they are now). For example:

<add name="SimpleBookCatalog" connectionString="Data Source=C:\FooFoo\MyBooks.sdf" providerName="System.Data.SqlServerCe.4.0"/>

Here's some examples of fluent mappings and setting up relationships to give you an idea of the kinds of things you can do, while avoiding looking at any visual designers. It all depends on how clean you need your POCO (Plain Old CLR Objects) to be.

modelBuilder.Entity<Book>().HasKey(b => b.ISBN);
modelBuilder.Entity<Book>().HasRequired(b => b.Title);
modelBuilder.Entity<Book>().HasRequired(b => b.Author).WithMany(a => a.Books);
modelBuilder.Entity<Publisher>().Property(p => p.Name).MaxLength = 50;
modelBuilder.Entity<Author>().HasMany(a => a.Books).WithRequired();

These configurations can be batched up into a class that handles configuration for a specific entity so you can reuse them and more easily config like this.

builder.Configurations.Add(new BookConfiguration());

All this is a really basic example as a means of introduction and for my own learning, but so far I like it. It takes just a few minutes to get a lot done without much code. Since this is all Entity Framework, I can put an OData service on top of my model really quickly and then start consuming those services from iPhones or whatever.

It'll be interesting to take a sample like Nerd Dinner or MVC Music Store and change them to use Code First EF and the Razor View Engine and see if they are more readable and how many fewer lines of code they are.

Related Links

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Ultimate Developer PC 2.0 - Part 2 - UPDATE and PODCAST on Building a WEI 7.9 and RFC for building a GOM (God's Own Machine)

July 13, '10 Comments [76] Posted in Hardware | Podcast
Sponsored By

Big Ass Mobo As a reminder, if you're just turning in, here's our glossary:

  • WEI - Windows Experience Index. How fast is your machine? If you say "I've got a WEI 6.0" you've got a good machine, for example.
  • RFC - Request for Comments. This is crowdsourcing. I want to know what YOU think we need to do to make a machine that is so fast that it'll max out at WEI 7.9 and be a GOM.
  • GOM - God's Own Machine. If the Good Lord had a computer, it'd be a 7.9. We want to build that machine.

There were lots of great comments in the original post. Here's some of my answers to those comments, as well as some on Twitter. The fun thing about doing hardware builds is that EVERYONE has an opinion. Also, since I'm a software guy (although I could totally rock a 486-SX build) your opinion, Dear Reader, is better than mine. I can only explain why I (and Pete, who is doing a similar build with me) made certain decisions.

We hosted a great podcast last week with some actual members of the WEI team and asked their ideas on how we could create the Ultimate Developer PC. You can listen to Hanselminutes Podcast 220 on "Creating the Ultimate Developer Machine 2.0 - How can we get a 7.9 WEI Score for under $3k?" here.

This I Believe - Hardware Edition

There's some guiding principles for this build.

  • We aren't trying to build the Ultimate PC. We don't have 20 grand or whatever the super PC is today.
  • We aren't trying to build the Ultimate Gamer PC
  • We don't want a divorce. We have a budget and we've been saving for 2 years, but give or take a few hundred dollars we can hide in tacos, we've got $3k.
  • We do have some existing parts. I've already got good monitors, as you might as well. I've got a decent case, keyboard and mouse. These don't count. Maybe the case, but you get the idea.
  • If we can stretch JUST a smidge and get a better piece of hardware for a few more bucks, or if we feel that if we DON'T get a certain level of hardware that we'll be sad, we'll go for it. Within reason.
  • We aren't AnandTech and don't claim to be.
  • We value multi-tasking as we do a lot of stuff a the same time. We think more cores is a good thing and you can't have enough memory.
  • Sometimes folks who write hardware websites talk perf, but it's unclear what they are actually DOING with these PCs, other than using them to run benchmarks. We are doing these things:
    • Communicating - Email, Twitter, Skype, Messenger, Communicator all running at the same time.
    • Coding - Multiple instances of VS2010, HippoEdit, e, IIS7, etc.
    • Virtual Machines - I usually have at least one VM doing, sometimes peaking at 2 or 3.
    • Writing - Live Writer, Excel, Word
    • Browsing - Chrome uses like 20-30 chrome.exe processes and thing slow down when Flash is involved.
    • Media - Usually running Zune or iTunes in the background. Sometimes a pinned video or Hulu on another monitor.
    • Gaming - Nope. Zip. I have an XBox, Wii and PS3 for that. And a Vectrex.

The Purchase

So here's what I purchased and what I was thinking when I did it.

  • $965 Intel Core i7-980X Extreme Edition 3.33GHz LGA 1366 130W Six-Core Desktop Processor
    • I thought about an overclocked P4, but I REALLY wanted an i series and I really wanted a hexacore and something overclockable to 4GHz without being an expert overclocker. Compile times need GHz and multitasking needs multiple cores so even though it's a grand for a processor, I feel good about it. It is the brain.
  • $699 (with combo actually $480) GIGABYTE GA-X58A-UD9 ATX Intel Motherboard
    • This was the UD7 before, but when I was on NewEgg they had a deal when purchased with memory that took $219 off it, so it was $699-$219 = $480 for the UD9 vs. the $339 UD7. The extra $140 seemed worth it for such an exceptional motherboard. It's a very flexible board, does 6-core and does SATA 6Gbit/s. It's an Intel X58 chipset, and has seven PCIe 2.0 x16 slots. I HATE running out of room. There's also enough space for dual slot graphics cards. I have four monitors (although I'm starting by running just two in this config) and I need the elbow room. It's also got two gigabit LAN, USB 3.0, and two eSATA as well. It supports 24GB of RAM which is nice breathing room, given I'll start at 12GB.
  • $374 OCZ Reaper Edition 12GB (3 x 4GB) 240-Pin DDR3 SDRAM DDR3 1333 (PC3 10666) Low Voltage Desktop Memory
    • Buttloads of RAM. Actually, I'd have preferred 16, as 12 just FEELS a little small. I have 8 now. Good news is, I can double this in a year or so when funds allow.
  • $320 NVidia GTX 470
    • Video cards are like Religions. The only thing that they all have in common is that you think YOURS is the One True Way. Why did I pick this one? I'm religious. No other reason. Why not eat Pork? It's a filthy animal, right? Of course not. But still. You never know! Why not buy ATI? They blue screened me ONE too many times years ago and I just can't do it. They're a filthy beast!
      Now, in fairness, read that paragraph again and swap ATI and NVidia. It works both ways.
      I like NVidia. You may think this is a gamer card, but it really came down to this. I want my Windows, and my (soon to be) hardware accelerated browsers to as well.
    • UPDATE: David in the comments said that I contradicted myself with my religious rant. To the numbers. This card gets me 7.9. I like NVidia. It'll run two 30" monitors no problem. Two of them will run four. It's in my budget and it's the Top NVidia card that'll push the pixels I want. That's why I picked it.
  • $610 Crucial RealSSD C300 CTFDDAC256MAG-1G1 2.5" MLC Internal Solid State Drive (SSD)
    • This was a hard one. Folks were suggesting "get a small C: drive" and a large spinning-rust drive for data. I have 2 TB of storage on a Windows Home Server and lots of External Drives around, so let's just say D: drive space is a non-issue. However, I can't abide a 64gig or 128gig C: drive. It's insane. There's no room. This is a great drive, a good balance between size and speed. It'll probably get a 7.7-7.8 WEI, but I really think that RAID 0 array of two drives is overkill. It also seems like I'd be asking for a drive failure. This was a good balance of price and performance. I need to update the firmware before building.
  • $200 SILVERSTONE ST1000-P 1000W Power Supply
    • A number of people thought this was overkill. Fortunately, I can always swap it out or return it if it was a bad idea. That said, when I add in another video card for the other two monitors, as well as a harddrive or three, I'm going to want the extra headroom.

I have likely (and will likely) make mistakes here, but that's part of the fun of building your own machine. Remember, Jedis build their own lightsabers, so you should build your own computer at least one!

I'll be building this in the next week or two.

QUESTION: Is there any interest in a "live build" where we stream the build and the viewers make suggestions, ask questions, etc?

Your thoughts?

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Microsoft WebMatrix in Context and Deploying Your First Site

July 6, '10 Comments [30] Posted in ASP.NET | ASP.NET MVC | IIS | Learning .NET | WebMatrix
Sponsored By

 ScottGu announced Microsoft WebMatrix Beta today.

  • WebMatrix Starting PageIt's a small (15 megs if you have .NET 4, 50megs if you don't) lightweight IDE for making ASP.NET or PHP websites.
  • It has a small embedded file-based SQL Database, and a web-server called IIS Express that's compatible with the full version of IIS.
  • It uses a View Engine called "Razor" to make Web Pages, and your sites can be later be expanded to use all of ASP.NET MVC. It's a simple syntax that is easy to learn
  • It uses the WebDeploy engine to deploy apps to hosts, setting up permissions, copying databases, etc.
  • WebMatrix also has the Search Engine Optimization Toolkit built in, so you can spider your own site and see how Search Engines see it. It'll make recommendations and store reports.

I've said before that Microsoft is just now starting to get the "right-sized LEGO pieces." It the past some stuff was too little or too big, but now as an example, here's five separate and right-sized LEGOs (ya, I know it's singular) that are helpful for the professional and the folks just getting starter, or those who don't want to learn a bunch of stuff to setup and/or modify a website.

Visual Studio 2010 looks like a dashboard. It's big and powerful and overwhelming. I tried to get my wife, then later my 10 year old nephew to make a website and it was a non-starter. It worked later with WebMatrix. This isn't for professionals, even though it has components that professionals will use. Pros will like a free file-based SQL Server, and a non-service version of IIS that's more compatible than the Visual Web Developer, and pros might like using Razor as an alternative View Engine for their ASP.NET MVC sites.

However, folks that are starting out, or hobbyists, or maybe just installing a blog or forum will use WebMatrix to get stuff done.

Download and Install Matrix

Here's how you'd get WebMatrix, sign up for a new host, and deploy your first site.

Go to the WebMatrix site and click Download Now. It'll install the Web Platform Install (about 2 megs) and then you click Install. The WebMatrix download for me was 8megs, then SQL Compact was 2.5megs, and then some deployment dependencies brought my total download to 29 megs.

Run and Select a Site

You can install a site from the Gallery, like ScottGu did when he chose BlogEngine.NET. These are regular ASP.NET and PHP apps that you've probably used before. There's lots of Open Source apps like Blogs (like DasBlog, that runs this site!), Content Management Systems (like Umbraco, that powers http://asp.net!) and other apps that you can start working with immediately.

However, since we're learning, my wife and I are going to select Site from Template and pick the Bakery App. This is a basic store-type application that we can deploy in just a few minutes. We don't need to look at code if we don't want to.

WebMatrix Site from Template

Hit OK and I'm in WebMatrix looking a new screen.

image

At this point I can click Run to see my app.

image

It's running locally on IIS Express along with some others Apps I was looking at earlier. This is effectively FULL IIS (not Visual Web Developer) but installed as a User App...when I stop the app, it's gone. It's not an auto-startup service, but it is IIS, which means your apps will run the same locally as they do deployed.

image

I can run it locally, but how do I get it up to a host?

Deploying My App to a Host

Things usually get complicated when you go to deploy and app. It's pretty easy to get an application running locally, but it's sometimes a challenge to get that app up on a site. People can sign up for a Gmail or Hotmail account and get that running, so why can't they get a website up that they coded themselves?

I've blogged about WebDeployment before and shown examples in my Mix Video "If you're using XCopy you're doing it wrong." WebDeploy is part of WebMatrix also.

I'll click on Publish and "Find Web Hosting" and I get a list of hosts I can choose from. I'll select Applied Innovations and click Learn More. I do prefer hosts like AdHost that give you both a .NET 2 and .NET 4 Application Pools to work in, which means I can use apps from the Gallery and apps that use the new Razor Syntax at the same time.

I go to Applied Innovations, and fill out the form. I'll get free hosting until next year with 1 GB of Disk Space and 100 GB monthly transfer. I get .NET 3.5 and 4, but also PHP. I can use SQL Compact, but also mySQL.

I fill out a form -  no credit card needed - and they send me an email. Click a link and they send me back an email with all the details I need. This is the same experience you'll get with all the hosters.

My Opinion: Some hosts make you switch your AppPools between .NET 2 and .NET 4 and that's too hard for beginners, I think. Hopefully all the hosters will remove this step and offer two app pools, or make switching between them a top level button in their Control Panels. AdHost does this. I hope others will also.

To switch to .NET 4, go to the Control Panel URL in your welcome email. Click WebSites, Extensions and select ASP.NET 4 from the dropdown.

Control Panel

Other hosts to choose from during this Beta are:

I fill out the Publish Form in WebMatrix with the details direct from my new host.

Publishing

Notice I don't need to do anything special for my database, as it's a file-based SQL database, runs in Medium Trust and requires no configuration.

Click Publish, and I'll get a list of files that'll be copied up. This is a differential copy, so if you change one file later, only that file will go up. Be sure to click the checkbox to deploy your database.

Publishing Preview

The publish happens in the background...

Publish Progress Bar

Then it completes, and I can now visit my new Bakery site online at my host, AppliedI:

image

Of course, if I wanted to, I could change the site, maybe modify the Products page:

@{
LayoutPage = "~/_Layout.cshtml";
PageData["Title"] = "Product";

var db = Database.Open("bakery");
}

<h2>Available Products:</h2>
<div class="products group">
@foreach (var p in db.Query("SELECT * FROM PRODUCTS")) {
<div class="product">
<h3>@p.Name</h3>
<img src="@Href("~/Images/"+ p.ImageName)" alt="@p.Name"/>
<p>@p.Description</p>
<ul class="group">
<li class="price">$@string.Format("{0:f}", p.Price)</li>
<li class="order">
<form action="Order" method="post">
<input type="hidden" name="ProductId" value="@p.Id"/>
<input type="submit" value="Order Now"/>
</form>
</li>
<ul>
</div>
}
</div>

There's lots of nice helpers for Google Analytics and Twitter integration:

<div class="sidebar">
@Twitter.Search("#bakery", caption: "#bakery")
</div>
I could of course, also edit my data:

Database Editing in WebMatrix

All in a reasonably not scary-dashboard looking UI. It's all ASP.NET underneath, so I can graduate to ASP.NET MVC and move my logic into controllers, and I've already got Views written in the "Razor" syntax, which is the new default for ASP.NET MVC 3.

Context

If you're reading this blog, and you're not my Wife, this tool probably isn't for you. (Hi, wife.)

However, the pieces that make up WebMatrix probably are. SQL Compact is pretty sweet. It's small, free, file-based and easy to upgrade to SQL Express Big Boys and Girls Edition. The new Razor syntax is a nice alternative to the WebForms Syntax (as are other alternative ViewEngines). IIS Express is hotness, especially if you've ever had an app that acted differently on IIS than on Visual Web Developer.

If you are learning web development or just want to get a site up, check out WebMatrix. Even if you don't edit the code, you can get and deploy and app to a host quickly, be it an ASP.NET app or a PHP app. If you do choose to write an app yourself, you can get started with WebMatrix and then move to Visual Studio (Free Express or $ Pro) if you outgrow it.

I'll report back and see what the WAF (Wife Acceptance Factor) is on WebMatrix.

Related Links

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.