Friday, June 26, 2009

Unload Web Site and WAP in Visual Studio

Inside Visual Studio many times people want to be able to unload a projects without having to completely close them…

Web Application Projects (WAPs)/ Class Libraries Unload

WAPs or Class Libraries unloading the project allows you to open the .csproj or .vbproj within an XML editor and modify the properties… This is by far the biggest reason why unloading WAPs, Class Libraries etc is used…  You can Unload most of the VS projects by Right Clicking on the project node and clicking “Unload Project” as shown below:

image

After Unloading the project looks as below and you can again Right Click on it to edit the project file.

image

Web Site Project Unload

Web site project on the other hand are different, firstly cause they do not have a project file and hence unloading them to edit the project file is not a motivation…  People still do want the ability to unload Web Site project and the scenario around it is that when you unload a project then on Solution build the unload project does not get built… This way if you are in middle of writing some code in that project and have existing errors then you can still unload it and continue with solution build…  Also Reloading the project will be faster than opening a closed project…  With that said if you Right Click on Web Site project you won’t find the “Unload Project” option… 

The right Click context menu is already very long for Web Site and as Unloading Web Site is not as common the command for “Unload Web Site” actually sits in the “Web Site” menu on top of Visual Studio as shown below:

image

After unloading the project you can then right click on the unavailable node (just like WAP above) and ask VS to “Reload Project”…

Also FYI unloading and reloading of project resets a lot of in memory objects associated with the project so in VS 2010 we explicitly load and unload WAP as well Web Site when you change your project’s target .NET framework version (e.g. move from 3.5 to 4.0)… This allows VS to hook in the correct intelligence, toolbox etc etc associated with the correct .NET Framework version…

Hope this small tip & trick  will help you…!!

Labels: , , , , , , , , ,

Thursday, June 25, 2009

Disabling Script Debugging with VS 2010, Silverlight & IE 8

This is a quick post to cover few items related to Script Debugging and the way it is impacted by Silverlight, Internet Explorer 8 and Visual Studio 2010…

With IE 8 there is no longer option to disable script debugging… When VS 2010 will launch IE 8 then script debugging will be enabled by default… This will help people debug scripts flawlessly without having to go and change script debugging features within IE 8… While this is a good feature for most users it might at times create problem when you do not really want script debugging to be enabled for performance reasons (i.e. if you do not want to debug scripts and have lot of scripts in your pages)…

On separate note Silverlight is a special debugging option for Web Projects…  You can view that by going to Project –> Properties –> Web…  Check the screenshots below for Web Application Projects (WAP):

WAP Silverlight Debugger

for Web Sites you can view those options by going to Web Site—> Properties –> Start Options as shown in the figure below

Web Site Silverlight Debugger

Now Silverlight debugging is mutually exclusive with Script Debugging as Debugger at a time can attach to only one of the two, so when you turn on Silverlight debugging then VS has to turn Script Debugging Off…  If you have bunch of Client side scripts in your Silverlight project which needs to be debugged then in that case you will have to go to the above option and turn off Silverlight debugging to have Script Debugging enabled… 

Now a side effect of all this is that if you want to turn off Script Debugging on your regular projects then your easiest work around is to go and turn on Silverlight debugging and your script debugging will get turned off by itself…

GreggM on our Debugger team has got some further detailed work around via modifying the registry at http://blogs.msdn.com/greggm/archive/2009/04/06/disabling-script-debugging-in-vs-2008-ie8.aspx, it is a great post take a look at it…

Hope this workaround helps you!!…

Labels: , , , , , , , , ,

Friday, June 12, 2009

Web Development with Windows Azure

Today I am hoping to put together a bunch of resources to get started on Web Development on Windows Azure…

Overview & Value Props

At a very high level Windows Azure will provide cloud computing platform for web developers with few key advantages over any other on premise or hosted environment… IMO, the key value props of Windows Azure for Web Developers are:

  • Scale up and down based on your need – You can start off with very small server capacity and eventually as your web site traffic grows you can choose to request more capacity as things go…
  • Failover management – If one of the server fails or your application goes down then Windows Azure will take care of spinning up new server VMs for you behind the scenes without your site experiencing any downtime…
  • Store your Data in the Cloud -  If your web application is sitting in the cloud then you will need to have your database in the cloud as well...  With Microsoft’s cloud storage you can now have your data in the cloud as well…
  • Use existing  Skill Set – Developers have invested a lot of time and energy in learning technologies like ASP.NET and general .NET framework in itself.  In Windows Azure you will be able to use the same APIs that you are familiar with…  Funny but you can also host PHP applications on Windows Azure…

If you would like to learn more about the high level advantage and direction then visit Windows Azure for Web Developers page… While you are at it make sure you watch the small videos on the page which will give you a good back ground about Azure for Web Developers…

Getting the Windows Azure Tools & Accounts

Next, let us talk about what do you get yourself set up for Azure development…

  • Register for a free Windows Azure Account – The chances are that the account may not remain free and available all the time so go ahead and register for a account at Connect site
  • Use your existing Visual Studio 2008 install or even better than that download Visual Studio 2010 Beta 1  which is available to download for FREE…
  • Recently Windows Azure tools for Visual Studio were released which work on VS 2008 as well as VS 2010 Beta 1… Download the Windows Azure Tools for VS and install them on top of VS 2010 Beta 1…
  • You can also separately get the Windows Azure SDK, although I would recommend using the Tools install which contains all the stuff that you need including the runtime… 

Do find some very useful resources around the Azure application development below:

Useful Documentation

Web Casts & Videos

There are some good Azure web casts available… View Windows Azure Web Casts

Some of the interesting videos in the series of Windows Azure Videos are:

MSDN has got some more Azure Videos too…

Microsoft Events site also has many other Windows Azure videos

Sample Projects

To get started further easily you can find sample projects which use Windows Azure at www.codeplex.com… TIP: Search for “Azure” in CodePlex and you should find some samples easily…

Feedback and Questions

If you have any feedback and Questions, you can certainly leave them here; additionally you can also go to Azure User Groups….   

Hope this helps…

- Vishal | Twitter: @VishalRJoshi

Labels: , ,

SharePoint Designer 2007 download for Free

SharePoint designer was made as a free download for everyone starting April 2009… You can download it for free from:

http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=baa3ad86-bfc1-4bd4-9812-d9e710d44f42#RelatedLinks

You can learn more on the SPD page @ http://www.microsoft.com/spd

Tom Rizzo from SharePoint team shares some of his thoughts on the SPD Designer decisions….

Hope this will remove one more barrier for folks to learn and get ahead with SharePoint…

Labels: ,

Thursday, June 11, 2009

How to make Content Web Pages to use existing Master Page

Let us say you want to add a new page Page1.aspx to use Site.Master…  Lets say that Site.Master already exists in your project…

If you were to add Page1.aspx as a simple .aspx page then you will have to make manual change to the <%@ Page directive of the page to make sure Inherits property is set correctly… But generally you will not need to do this if you add the file in the below fashion…

WEB SITE PROJECTS: If you are using a Web Site Project (i.e. below)

new web site

Then in that case you can Right click on your project –> Add New Item and “Select Master Page”

new web form

On the next page you will get an option to select the master page as shown below:

Web Site Master

WEB APPLICATION PROJECTS (WAPs):   If  you are using a WAP (i.e. File –> New Project as shown below)

new WAP

Then while adding a new page, right click on your project—> Add –> New Item and instead of selecting “Web Form” select “Web Content Form” as shown below:

web content form

When you now click the “Add” button you will get to select the Site.Master page that you had previously added to your project… Check the figure below…

web form site master

Hope this helps…

- Vishal | Twitter: @VishalRJoshi |

Labels: , , , , ,

Monday, June 01, 2009

ASP.NET 4 Beta1 & MsDeploy RC1 Hosting for FREE

FREE is the word of the day…  Check out what all you can get for free:

Sounds interesting right!!… This is exactly what I just announced on our Team Blog…

Get ASP.NET 4 Beta1, VS 2010 Beta1 & MsDeploy RC1 hosting free!!

Although, before finishing off I need to pause and thank OrcsWeb and DiscountASP teams who have been hard at work since weeks now to get you FREE hosting accounts to try out the new technologies way before even “GO LIVE” license for them is available…

I personally want to thank

Takeshi, Frank, Aristotle and their team @ DiscountASP.NET

AND

Scott & WebTeam @ OrcsWeb

for all their hard work over last so many days, including weekends… As you can imagine setting up remote hosted accounts on brand new technologies while we are still making changes to them is not a simple task…  Just to give you a glimpse it takes from provisioning servers, setting up .NET 4.o, SQL Server, IIS, MsDeploy and dependencies, setting up security + provisioning all the individual accounts that you request, configuring automated emails with correct connection strings, auto generated + unique user ids, site names + passwords etc etc…  Then working for several days to make sure that automatic provisioning yeilds correct emails and correct security settings so that your webs work seamlessly…  This is in all honestly a lot of work and hats off to these folks to make all that work…

Gladly enough you do not need to do all that hardwork to try out all these things… All you need to do is below 3 things…

  1. Download VS 2010 Beta 1 for FREE from Microsoft download center
  2. Get a free hosting account from Get ASP.NET 4 Beta1, VS 2010 Beta1 & MsDeploy RC1 hosting free!!
  3. Follow the walkthrough Web 1-Click Publish with VS 2010

Do provide your feedback in comments here, or on Visual Studio 2010 Beta1 and ASP.NET 4 Beta1 Forum…  Also you can follow #1ClickPublish on twitter…

Hope you will enjoy the offer… 
-Vishal

Labels: , , , , ,

Sunday, May 31, 2009

Known Issues, Resolutions and Work-arounds for VS 10 Web 1-Click Publish

There are certain known issues and workarounds which you may or may not encounter while using VS 2010 Web 1-Click Publish but I have still posted them here in case you face any of those and want to debug your deployment problems…

  • If you receive 502- Bad Gateway error then go to Internet Explorer –> Connections –> LAN Settings –> and uncheck the “Automatically detect proxy settings” and after that you should be good to go…
  • At times within Intranet environments if ISA Server or alike is not running then you may get errors like “VsMsdeploy failed.(Request to remote agent URL 'https://myWebServerName:8172/msdeploy.axd?site=myWebSite’ failed.) Error Details:Unable to connect to the remote server. OR The remote name could not be resolved… “   The resolution for the above issue is to enable the ISA server and re-run you deployment…
  • If you get an error about your .mdf file being used by some other process then the resolution for this issue is to right click on your MDF file under App_Data folder and click “Detach”…  The other typical culprit which holds an handle to the .mdf file is the Server Explorer… You can try to close the server explorer and try publishing again too… Finally, I hate to say it but if nothing works then you can restart VS…  This is a known bug and will be resolved in the future releases of Visual Studio 2010…!!
    •  

Labels: , , , , , ,

Web 1-Click Publish with VS 2010

Visual Studio 2010 has great features to make your web deployment easier…   I have written a high level article describing the web deployment feature set of VS 2010 below:

Today my goal is to go through an end to end walkthrough of the Web 1-Click  Publish feature of VS 2010…  This walkthrough will cover following:

  • Prepping up an ASP.NET 4.0 web application which is using a SQL Server Database for deployment
  • Gathering the remote web and database server information
  • Setting up Web.config Transformation to change your connectionString
  • Including SQL Server Databases in Web Deployment
  • Creating a 1-Click Publish Profile to Publish your web content, databases and transformed web.config files
  • 1-Click Publish your Web Application

For this walkthrough you will need Visual Studio 2010 Beta1 which you can download FOR FREE from http://www.microsoft.com/visualstudio/en-us/products/2010/default.mspx

Let us get started…

Prepping up an ASP.NET 4.0 web application which is using a SQL Server Database for deployment

In this walkthrough we are assuming that you already have a web application which uses SQL Server database and you are ready to deploy it to remote web server and database server…  If you do not have such a web application then I encourage you to follow the simple step by step instructions in the walkthrough Creating a simple .NET 4.0 web application using Visual Studio 2010

With the assumption that you now have a data driven ASP.NET 4.0 web application let us try to understand what all is needed to be taken care of while deploying such a web application… Things that you need to take care of during such typical deployments are:

  1. You need to modify the connectionStrings in the web.config file to point to the remote SQL database server instead of the local SQL Server Express that you are using on your dev box…
  2. You need to deploy your databases to the remote SQL database server
  3. You need to deploy all of your master pages, content pages, images etc to the remote web server

In the remaining portion of this walkthrough you will see how to accomplish all of the above things…

But before getting to that, let me introduce you to Web Application we are about to deploy… The solution explorer of this web application looks as below:

1-ClickPublish solution explorer

Notice that this web application has 1-ClickPublish.mdf file in the App_Data folder…  Also notice that it has a Site.Master, Default.aspx and Address.aspx Web pages…  When you run Default.aspx it looks as below:

Default.aspx

The top banner of “Visual Studio 2010 Web 1-Click Publish” is coming from Site.Master…  The grid containing FirstNames & LastNames is being populated from the 1-ClickPublish.mdf file…  The “View Addresses” button takes you to “Address.aspx” page which shows the addresses of the people on “Default.aspx” as shown below:

Address.aspx

The web.config file of this web contains connectionString named “1-ClickPublishDB” which points to the SQL Server express database (1-ClickPublish.mdf )…

Gathering the remote web and database server information

Before we begin to deploy the web application to the remote server we will need to gather the information of the destination servers… Typically if you are going to a shared hoster then this information is provided to you in the welcome email from your web hosting company…  Web hosters typically have various plans which include database as well as web server storage space….

If you are not planning to go to web hosting company but rather are interested in hosting your own web and database servers then you will have to follow some more additional steps to set up your web servers and database servers…  I am not covering this in the current walkthrough but will cover the same in subsequent walkthroughs…  But for now let us assume you have a web hoster who has provided you with the information required for deployment…

Typically web hosters will ask you which .NET Framework version you would like to target (i.e. 2.0, 3.0, 3.5 or 4.0)… Based on the .NET Fraemwork version you choose your web site will be provisioned with the correct Application Pool… For .NET 2.0, 3.0 and 3.5 the Application Pool targets CLR version 2.0… For .NET 4.0 the Application Pool is set to CLR version 4.0…. It is very likely that your .NET 2.0, 3.0 or 3.5 web application will run seamlessly on .NET 4.0 but it is still required to talk to your hoster to change you Application pool from .NET 2.0 to .NET 4.0… 

If you register for a hosting plan which supports the new VS 2010, ASP.NET 4.0 and Microsoft Web Deployment Tool (MsDeploy) then you will receive below pieces of important information which we will use later during the walkthrough… In the rest of the walkthrough I will refer to these as “1-Click Settings” so that you can easily relate to this section…:-)

  • Service URL:  This URL is in the format https://myWebServer:8172/MsDeploy.axd and actually points to a IIS handler which will manage your deployment on the remote web server
  • Site/Application Name: This is the name of your IIS Web Site on the remote web server…  This is where your application will be deployed…
  • UserName: This user name is the account which has the access to the ServiceURL and your Site on the remote web server
  • Password:  The password which you use for your above UserName
  • ConnectionString: This is the ConnectionString to your remote database server… Typically your hoster will make sure that your remote web server and remote database server have the correct ports opened so that your web application can easily consume the data from your database…

At this time I am assuming that you have your web application ready to be deployed and you already have the above pieces of information from your web hoster…  The next thing we will do now is to set up web.config transformation to modify your web.config file during deployment….

Setting up Web.config Transformation to change your connectionString

Let us assume that you are using “Release” build configuration when you are deploying to a remote web server…  You can create and use a different build configuration as well but I am choosing “Release” as it comes out of the box with VS 2010…  Learn more about Managing Build Configurations… 

By default “Debug”  is the ‘Active’ build configuration… As we are ready to deploy to a hoster you can change your Active build configuration to “Release”… You can do so by simply changing the drop down value on the VS “Standard” toolbar as shown below:

build configuration

Alternatively you can also change the build configuration by going to the Build –> Configuration Manager menu…

After this step your Active Build Configuration should be “Release”…  You can now open up the node next to the web.config file to reveal web.debug.config and web.release.config as shown below:

web.release.config

In case of VB.NET you will have to click the top right button to “Show all files” to see the dependent web.release.config…

Now open the web.config as well as web.release.config files and copy the connectionString section from the web.config file into the web.release.config file as shown below…

FROM

web.config connection string

TO

web.config with connection string

Now you need to do two quick things

  1. Just simply write xdt:Transform=”Replace” in the connectionString node of web.release.config as shown below…
  2. Also change the connectionString attribute by putting the value that you got from the hoster (the one we referenced in “1-Click Settings” )… Let us say my hoster proived me with connectionString as “Data Source=myHostedSQLServer;Initial Catalog=myhostedDBName; User ID=VishalRJoshi; Password=*VS10Rocks” then my web.release.config should look as below…

final web.release.config

Also note that by default Web.Release.config has a transform called “RemoveAttributes” to remove the debug attribute when you are going to the “Release” environment…  Many hosted environment will not allow you to have debug=true coz it is not safe hence removing the debug attribute is required…

With this you have set up the automated web.config transformation which will take care of changing your connection string during every deployment… !! There is a lot more you can do with XML Document Transforms (XDT)…  Check out the different possibilities Web.Config Transformations by leveraging XDT here…

Including SQL Server Databases in Web Deployment

As the current web application is actually using the data in 1-ClickPublish.mdf it is required to move the database schema and data from this local SQL Server Express database to remote hosted SQL Server database server… In order to make that happen you need to go to “Deploy SQL” tab of the Project properties…

You can open project properties by double clicking the “Properties” item under the project node as shown below:

image_thumb10[2]

When project properties window opens then navigate to “Deploy SQL” tab…Once you open “Deploy SQL” tab you need to do following quick things:

Make sure you are using the “Release” configuration as that is the configuration we are going to deploy (and you also have web.config transformation for Web.Release.config)…

Click “Add” button and give a friendly name for your database deployment as shown below: (I would recommend using the name that you used for your connectionString – for secret reasons I will talk about in future posts :-))

Add new connectionString

Next you will have to configure the “1-ClickPublishDB” settings which you just created by clicking it…  As soon as you click it the disabled section below will light up which you need to fill in as shown below…

Deploy SQL tab

The key points to note while filling up the DB Deployment information above are:

  • ConnectionString for the destination database is the connectionString which you received from hoster in an email (the one we referenced in “1-Click Settings” )…
  • “Pull data from an existing database” will instruct Visual Studio 2010 to extract data from the local SQL Server…
  • The connection string below the “Pull data from…” checkbox represents the source database (which is on your local dev box)… This connection string can be found in the original web.config file of your web application as the datasource controls you used insert the connectionString in web.config file…
  • The “Complete database” radio button instructs Visual Studio 2010 to script both database schema as well as data from your database…  If you contain junk data that you do not want to deploy to the server then choose “Shema only” option…

With these settings you can now hit save on top of Visual Studio and you have configured your database for deployment as well…Hopefully that was not too hard :-)  If your needs are more deeper than the above then there are many other powerful Database Deployment options which I have discussed in DB Deployment post earlier

Creating a 1-Click Publish Profile to Publish your web content, databases and transformed web.config files

Now that you have set up web.config transformation and also set up you database deployment settings, it is time to create a 1-Click Publish profile to use for your deployment…

You can do so by Right clicking on your project node and hitting “Publish…” as shown below:

Right Click Publish

With that you will get the “Publish Web” dialog which you can fill as below:

Publish Dialog

I have specially numbered the fields above so that you can easily relate to them in the text below:

  1. Publish Profile Name-  I have named it as myWebHosterName you can name it with the destination name that you can easily remember…  Usually if you are going to a web hoster then naming this as something like “DiscountAsp” or “OrcsWeb” would be advisable…
  2. Service URL:  As we discussed in the “1-Click Settings” section at the beginning of the post, this is provided to you by your hoster…  This URL associated with the Publish Method “MsDeploy” which is used behind the scenes by Visual Studio 2010 to Publish your entire web… You can learn more about the way MsDeploy works in one of my previous blog posts…  Also while you are at it note that the new “Publish” dialog also tells you the Build Configuration that you are publishing (i.e. the Active Build Configuration), in our situation we are using the “Release” configuration for which we have set up the DB Deployment and Web.config transformation…
  3. Site/Application Name: As we discussed in the “1-Click Settings” section at the beginning of the post, this is also provided to you by your hoster…  If your hoster provided VishalRJoshi.com as your Site name you can feel free to append a folder name underneath it e.g. VishalRJoshi.com/Blog…
  4. Mark Folder as IIS Application on destination: If you choose to Publish to a folder under the parent site eg “VishalRJoshi.com/Blog” AND  want to have separate session state, cache etc functionality for that subfolder then you will have to convert that folder into an IIS Application underneath your parent web site…  This checkbox will allow you to achieve that easily in an hosted environment… This is a the additional IIS enhancement that was made as part of “MsDeploy” Publish Method, so we hope you will like it…:-)
  5. Allow untrusted certificates-  MsDeploy Publish method will only take https:// URLs… As you know that secure http requires a SSL certificate but it is understood that it will not be possible to always buy a certificate from authorities like VeriSign etc and especially if you are deploying within your team environment then expecting a fully signed certificate may not be rational, hence this option allows the web server owner to provide a self signed SSL certificate… Although, in general it should be understood that checking this box increases threat on the data which is being transferred over the wire…
  6. User Name, Password and Save Password:  Again, As we discussed in the “1-Click Settings” section at the beginning of the post, User Name and Password is also provided to you by your hoster…  “Save Password” is a feature in VS 10 which will securely save your password, so that you do not have to keep typing it again and again…
  7. Save -  Now you can hit the Save button on the top, to save the “Publish Profile” you just created…
  8. Close – Close button will allow you to close the “Publish Web” dialog

After doing all of the above you have configured your Web Application for 1-Click Publish going forward…

1-Click Publish your Web Application

For your convenience Visual Studio 2010 offers Web 1- Click Publish toolbar as shown below:

image

You can enable this toolbar (if not visible) by going to View—>Toolbars—> Web One Click Publish… You can now simply click the Publish button below after every little change you make to your project that you want to deploy… 

image

This way you can keep updating your web at the destination with ease…  Do note that you are allowed to have upto 50 Publish profiles per project, which can allow you to Publish the same project to 50 different web servers in just clicks (I hope 50 should be enough, if not let us know now and we will be happy to bump that up :-))…

NOTE:  If you are incrementally publishing you web then you should go to “Deploy SQL” tab and uncheck your database deployment… If you do not do so then your Publishing will fail as MsDeploy intentionally does not overwrite the database that you already have on the server…  There is a easy fix to change that behavior i.e. there is an option to delete database every time you republish, but I will refrain from mentioning it until someone asks as that is purely a Test server scenario… :-)

Checking your deployed Web

With all of the above steps you are good to hit the “PUBLISH” button…  Once you hit the button your web should get deployed to the hoster much more quickly and reliably than ever before…

With all this you are now set up to have 1-Click Publish of your web application from Visual Studio 2010…

In later posts I will share the Performance and Scalability numbers of MsDeploy Publish method too but as far as I can tell MsDeploy publish is quite more reliable and performant than most other traditional web publishing mechanisms…

I hope this walkthrough will help you experience the new powers of Visual Studio 2010 and Microsoft Web Deployment Tool…

If you would like to learn more about Web Deployment with VS 2010, then I have explained a bunch of other features in the posts below:

Hope this walkthrough is helpful

-Vishal

Some KB Items:  There are certain known issues and workarounds which you may or may not encounter but I have still posted them here in case you face any of those… Known Issues, Resolutions and Work-Arounds for VS 10 Web 1-Click Publish

Labels: , , , , , , , , , , , , , ,

Saturday, May 30, 2009

Creating a simple .NET 4.0 Web App using Visual Studio 2010

The goal of this end to end walkthrough is to create a really simple ASP.NET 4.0 Web Application which uses SQL Server database and is built using Visual Studio 2010 (VS 10)…  The 11 steps in this walkthrough are:

1. Create a new ASP.NET 4.0 Web Application Project (WAP)

2. Create a simple SQL Server Database using SQL Express

3. Add Tables to the Database and set foreign key relationships

4. Add data to the tables created

5. Add a MasterPage and ContentPage to the ASP.NET 4.0 WAP

6. Modify the Master Page to provide consistent look and feel to the site

7. Add datacontrols like GridView and bind them to SQL Express database

8. Add additional web page and use DataView to display more data

9. Use QueryBuilder to fetch data from multiple tables

10. Use AJAX to refresh only parts of the page rather than complete page

11. Hook up various pages and complete the experience….

To complete this walkthrough you will need Visual Studio 2010 Beta1 which you can download FOR FREE from http://www.microsoft.com/visualstudio/en-us/products/2010/default.mspx

Let us get started:

1. Create a new ASP.NET 4.0 Web Application Project (WAP)

Start an instance of Visual Studio 2010 and create a new WAP project by going to File –> New—> Project –> Web –> ASP.NET Web Application as shown below:

file new project

new project dialog

Also notice the nice looking VS 2010 new project dialog box…  If you notice at the the left you will also see “Online Templates” and capabilities to search templates…   This will be pretty handy when there will be a bunch of community created templates available…  Anyways for now go ahead and click “Ok” to create our new “1-ClickPublish” project…  After the creation of the project is successful your solution explorer should look as below:

solution explorer

2. Create a simple SQL Server Database using SQL Express

Visual Studio 2010 comes with SQL Server Express edition in build…  I will be using that for the walkthrough purposes although if you have full SQL Server then feel free to use the same…

Add a new “SQL Server Database” by right clicking on the App_Data folder and choosing Add—> New Item

Add New Item

The “Add New Item dialog box” has also got a new look in Visual Studio 2010 just like “Add New Project dialog box”…  I am going to name the database as 1-ClickPublish database, you can feel free to name it anything but do note that it will matter when it will come to deploying this database to remote web server…

SQL Server Database Visual Studio

3. Add Tables to the Database and set foreign key relationships

To modify this database and add tables to it I will use server explorer… You can open server explorer by going to View—> Server Explorer

server explorer

By default the Server Explorer will show the connection to the database closed…  You can refresh the connection to open it…

refresh server explorer connection

Once you expand the node now you can right click on the tables folder and choose to add new table as shown below

Add new table

Next we will create simple “Person” table with four columns (ID, FirstName, MiddleName & LastName)…  The ID column and the FirstName column are required and MiddleName + LastName column allow nulls…  For current illustrations I have used ID to be numeric and all the rest as varchars…  I have also set the ID column as an identity column so that we can create a relationship of the Person table with PersonAddress table which we will create next.  The table editor will look as below once you create all these columns correctly…

Person table designer

On clicking save Visual Studio will allow you to name the table which in my case, I will be naming as “Person”…

Similarly we will next create “PersonAddress” table with 8 columns and following details:

  • ID | Numeric | Not Null | Identity
  • Person_ID | Numeric | Not Null |
  • AddressLine1 | varchar (100) | Not Null
  • AddressLine2 | varchar (100) | Allows Null
  • City| varchar (100) | Not Null
  • State| varchar(100) | Allows Null
  • Zip | numeric | Allows Null
  • Country | varchar (100) | Not Null

Once the table is created it will look as below:

PersonAddress Table designer

You can also go into both “Person” and “PersonAddress” tables, right click on the ID column and “Set Primary Key”…

Also now right click on the “PersonAddress” table and click relationships…  In the “Foreign Key Relationship dialog box” click the “Add” button to add a new relationship, then on the right side go to the (Name) column and change the name of the relationship to FK_Person_PersonAddress…

Foriegn Key Relationships dialog

Next click on the “…” on the “Tables And Columns Specifications”as selected above… In the specifications dialog box create a relationship between with ID column of Person table as the primary key table and Person_ID column of the PersonAddress table as the Foreign key table and click “Ok”…

table and column specifications dialog

4. Add data to the tables created

After the above step you will have your table created, save and close the table designers now to populate the tables with some sample data…. Let us go back to the server explorer to do that… The sever explorer should look as below:

server explorer with tables created

You can now right click on each of the tables and start populating data by clicking “Show table data”… Start populating the data in the Person table first as shown below…

Person table

Next populate sample data in the “PersonAddress” table as shown below:

PersonAddress table

With this the database should be good to go…

5. Add a MasterPage and ContentPage to the ASP.NET 4.0 WAP

Now let us go to the solution explorer and start editing the Web App by adding a simple Master Page to the project… Master page will allow us to maintain a consistent theme across the project…

Right click on the project node and click Add –> New Item…  This time navigate to the Web node and select “Master Page”… Rename the Master page here to Site.Master and click Add…

Add new Master Page

After adding the master page you can go back to the solution explorer and delete the Default.aspx page… The reason why I am deleting the page is coz it currently does not use the new Site.Master that we created…  

After deleting the Default.aspx and adding the master page the solution explorer will look as below:

Site.Master solution explorer

Next you can go ahead and right click on the project to Add one more new item… This time add a “Web Content Form” and name it “Default.aspx”  when you do that then the next dialog will allow you to select the master page you would like to use… Select Site.Master as shown in the image below and hit OK as shown below…

Site.Master

With this we have a basic skeleton of a web application created and hooked up… 

6. Modify the Master Page to provide consistent look and feel to the site

I will now open the master page and try add some standard boiler plate content to it as shown below:

master page

The above highlighted text will now appear on every page which will use “Site.Master”…

7. Add datacontrols like GridView to the content pages

Now let us go to Default.aspx and add few controls which will use the database we created earlier…  For this simply open Default.aspx and click on the toolbar to the left and open up the Data controls…  Next, drag and drop a Grid view from the tool box on to the “ContentPlaceHolder1” of Default.aspx as shown below:

add grid view to page

There is a switch at the bottom of the code editor to move to the design view… Click that switch and view the grid view in the design view…  The reason for doing this is that design view shows us something we call as Smart tags for grid view… In the Smart tag we will choose to create a new Datasource to tie the grid view to our database…

image

Do note few quick things like Default.aspx’s design view is now showing us the master page content as well…  Also I have to explicitly select the Grid View and then the top right arrow on it will give me the smart tag options…

The New Data Source dialog will look as below and you need to select Database and click “ok”…

Choose Data Source

On clicking OK the “SQL Datasource” configuration wizard will kick off… and will look as below:

image

If you notice 1-ClickPublish.mdf database file will already be pre-populated in the drop down…  Simply select the 1-ClickPublish.mdf and click next… Now name the connectionString as “1-ClickPublishDB” and click next…

image

In next screen select the FirstName, MiddleName and LastName columns of the database and click “Next” as shown below…

selectColumns

Finally click the “Test Query” button to make sure your query is yielding results as shown below and click “Finish”

TestQuery

Now if you select Default.aspx in the Solution Explorer and Hit Ctrl+F5 then you should see our web application up and running as shown below…

1-ClickPublish page test

Now let us put some reasonable headings etc to the page by going into the source view of Default.aspx (by clicking the source button at the bottom of the page...

Type in the code as shown below and switch to “Design View” again to preview your page:

image

The preview should look as below…

image

Now what we want to achieve is that when user clicks “View Addresses” button we want to be able to show a page with Persons with their Address details… 

8. Add additional web page and use DataView to display more data

For this let us add a new "Web Content Form” called “Address.aspx” which also uses the Site.Master… Once we do so then our solution explorer should look as below:

solution explorer with address.aspx

Let us double click Address.aspx and open it in the “Source View” and this time drag and drop a details view from the toolbar, which will make the page look as below:

image

Let us switch back to design view and try to add a SQL data source similar to the one we added for Default.aspx… 

9. Use QueryBuilder to fetch data from multiple tables

Although this time we want to be able to show the content of not only the PersonAddress table but also want to get First Name and Last Name from the Person table…  Hence on the “Configure Select Statements” step of the datasource wizard we will try to add a custom SQL Query to the datasource by following below steps:

specify custom SQL Statement

On clicking next on the dialog you will get an opportunity to select a query builder as shown below:

launch query builder

On clicking the query builder you will be asked to “Add tables”… Add both “Person” and “PersonAddress” tables by clicking the Add button as shown below:

Add Table in Query builder

Now the two tables will get added to the query builder… In the query builder now feel free to select the columns you want to display in the detailed view…  Also note how the query builder is building the SQL statements on your behalf…

query builder building inner join

Click “OK” on query builder and you should be taken back to the SQL Data source configuration wizard

query builder with inner join

Notice that now the query is populated, click “Next”…  As we did for default.aspx, test your query and make sure that the data is getting retrieved…

You should now be seeing following dialog:

testquery with a inner join

Click “Finish” now… In the “Design View” now click on the “DetailsView” control and click “F4”…. This should launch the properties pane for the “DetailsView” as shown below:

image

In the Properties of the DetailsView1 control set “AllowPaging”= True… This will allow your page to iteratively move between addresses instead of just showing one address… 

10. Use AJAX to refresh only parts of the page rather than complete page

Now let us switch to the source view and add quick AJAX capabilities to the page so that the entire page does not get refreshed every time you change the pagination on the Details View… To do this put the below specified code to your page…

image

Once you do this you should be good to test your “Address.aspx” page…  To test your “Address.aspx” page simply select it in the solution explorer and hit “Ctrl+F5”… You should now be able see your page as below:
image

11. Hook up various pages and complete the experience….

Now finally we want to link the Default.aspx Page to Address.aspx page by click of “View Addresses” button… To do this let us open “Default.aspx” page in Design View and double click the “View Addresses” button… This will open the Default.aspx.cs page with the Button Click event hooked up…  We can now write Response.Redirect(“Address.aspx”); into the event handler as shown below…

image

With this we now have a fully functional app  connected with backend database… If you now select Default.aspx and hit Ctrl+F5 then you should see the below page":

image

On clicking the “View Addresses” button you should be able to see the below page with pagination to view addresses one after another:

image

With you web application should be ready to be deployed…

Hope this walkthrough was useful!!

-Vishal

Labels: , , , , , , ,

Database Deployment with Visual Studio 10

Visual Studio 2010 (VS 10) Beta1 was released recently...  You can download VS 10 Beta1 from Microsoft download page….

Do check out the update on Visual Studio features for Web Developers on our team blog…

We have been discussing about a bunch of deployment features previously and today we will discuss about Database Deployment with VS 10….

VS 10 will allow you to deploy your databases both while creating a web package as well as while publishing directly to a web server provided by your hoster…

To catch up on the previous web deployment posts check out the below links:

  • Web Deployment with VS 2010 and IIS
  • Web Packaging: Creating a Web Package using VS 2010
  • Web Packaging: Creating web packages using MSBuild
  • How does Web Deployment with VS 10 & MSDeploy Work?
  • Installing Web Packages using Command Line
  • Web.config Transformation

     

    Apart from the “Package/Publish” tab, with VS10 we will now have a new tab called “Deploy-SQL” in the project properties of Web Application Projects (WAPs)

    The “Deploy SQL” tab looks like below:

    Deploy SQL tab

    Firstly let us note that this tab is Build configuration aware i.e. you can configure different settings for “Release” vs “Debug” environment… I have set the configuration to “Release”  and Platform to “Any CPU” for the above example…

  • TIP:  If you are deploying to a hosted environment then you can create different build configurations per hoster e.g. “DiscountASP” or “OrcsWeb”, this way you can configure various Database deployment settings per hoster…  You can use the same principle for various different database servers you are going to even within your intranet…

    Anyways, the first grid on “Deploy SQL”  tab looks like below and actually is a MASTER part of MASTER-DETAIL view of your Database Deployment Settings.  Every Database Entry in the grid below is a representative of a group of database settings representing source and destination database information:

    connectionString name grid

    i.e. Database Entry (Friendly Name) = Source Database Information + Destination Database Information

    My advice would be to create one entry per every destination database you are deploying to…  The reason why I am emphasizing destination database is coz many folks want to deploy more than one source databases to a single destination database…

    One classic example of this is when you are using ASP.NET membership or login features then ASP.NET automatically creates ASP.NET DB in your project AppData directory, apart from this people also like to create a separate ApplicationDB which has the application specific business data.  As you can imagine this results into two different source DBs.  When you are trying to deploy to a shared hosting environment then many times you are paying per database to your hoster and the obvious thought “my ApplicationDB does not conflict with ASP.NET DB in anyway, I am happy to have both of the DBs to go to the same destination DB without paying for two databases”…  In such a situation you would want to create one database entry in the grid above for every destination connection string that you have.

    The “Add” button at the bottom allows you to add a “Friendly Name” for your Database Entry…  If you would like to go to more than one destination database you can feel free to add as many Database Entries in the grid above as you want… For simplicity of tracking I would recommend using your connectionString name as the Friendly Name in the grid above.

    As you might have already noticed each entry in the grid also has a check box next to it…  The reason why this check box is provided is so that once you configure the database entry then you do not have to completely remove it  by clicking “Remove” button (and loose all the configured data)… If you do not want to include a  particular database Entry (friendly name) in a particular deployment scenario you can simply exclude it by un-checking the checkbox. 

    In order to permanently “Remove” the database entry you can select the entry to be removed and can click the “Remove” button….

  • Let us now take a look at the details of a database entry (e.g details of “productsDB” in the above example).  As I mentioned above the details are going to be broken down into two major categories…

    1. Destination Database Information

    2. Source Database Information

    _____________________________________________________________________________________________________

    Destination Database Information: This section looks as below:

    destination database information

    It is relatively simple, coz all it contains is connection string for the destination database… Typically when you get a hosted account your hoster will send you the connection string of your hosted database in an email.  This connectionString should go into the above text box.

    This field is kept optional and the reason behind it is that if you are using Web Packaging as a model for your deployment and are likely to hand over the web package to your system administrator or someone who will provide connectionString at install time then you can feel free to leave this field empty. 

    Do note that if you are directly publishing to a hoster (i.e. not packaging) and you have left this field empty then you will get an error during publishing.

    __________________________________________________________________________________________________

    Source Database Information: This section looks as below:

    source database information

    The first thing you will see in the Source Database Information is a check box which indicates “Pull data from an existing database” … If you have a local SQL Server database (SQL 2005 or 2008) which you are using for development then this will allow you to extract your database to deploy to the destination database (mentioned in the section above)….

    The first setting under “Pull data from an existing database” is Connection string for the source database… This text box is enabled only when you check the check box for “Pull data from…”  You can also click the “…” button next to the connection string text box which will launch the connection String builder dialog as below:

    connectionString Builder

    This dialog can help you easily create the connection String for your local database…

    The next set of controls under the source connection String text box allow you to determine what kind of SQL Script would like to generate from your source database.  Currently there are two options available…

    Schema Only  - Choosing this will only script the schema of your source database

    Complete Database – Choosing this will script both schema and data of your source database

    On your dev SQL Server it is likely that you might have some test data, in that situation you would want to choose “Schema Only” option which will only pick up the DB schema leaving out the data…  On the other hand if you choose complete database everything from your source database will be scripted…

    Insider Note:  VS 10 Database Deployment is using SQL Management Objects (SMO) behind the scenes to script your database…  SMO is a tried and tested API for scripting huge databases… scriptSchema & scriptData are SMO scripting options which Visual Studio is setting when you choose one of the options above…

    The next check box is “Exclude object with no schema information” which will give you further fine grain control on scripting your database.  If you do not care about schemaQualify feel free to uncheck this checkbox…

    Database Source Scripts -  You might have noticed that in this section there is already an entry called “[Auto-generated Schema Only]”… This entry is added to the source database scripts as soon as you check the “Pull data from an existing database”… At the bottom of Database Source Scripts grid you will notice “Add Script” and “Remove Script” button…  These buttons will allow you to add & remove extra .SQL scripts as your source…

    Most of the times developers or DBAs create .SQL scripts to deploy databases…  These custom .SQL scripts can be added and ordered in the grid (and thereby during deployment) using the up and down arrows…  The “[Auto-generated Schema Only]” is a representative of the script that VS will automatically generate from your source database, it is added to the grid so that you can order it up and down along with the rest of the .SQL scripts that you might want to add…

    Also note that if you are generating your .SQL scripts via tools like Visual Studio Database Edition (Data Dude) or Red Gate then you can add those scripts here to be included in your web package as well. 

    NOTE: There is a way to set up automated build and deployment environment in which you can collect .SQL scripts from Data Dude or Red Gate and provide to VS 10 during web deployment.  I will cover this topic separately in a different blog post…

    _________________________________________________________________________________

    The last section of the “Deploy SQL” tab is a place for you to provide Database Deployment notes so that you can note specific steps you took or scripts you used while deploying databases; this is purely for your reference purposes…. The deployment notes section looks as below…

    Database Deployment Notes

    Once you have provided all of this information you are good to deploy your databases using Visual Studio 2010 Web Deployment…

    Web Packaging  + DB Deployment

    After setting up your DB deployment as shown above you can now right click on your project and hit Package –> Create Package as shown below…Create Package

    The package created as a result will contain your database…  You can read details about creating and installing the web packages below:

  • Web Packaging: Creating a Web Package using VS 2010
  • Web Packaging: Creating web packages using MSBuild
  • Installing Web Packages using Command Line
  •  

    Web Publishing + DB Deployment

    Once you set up the DB then not only will it get included in Web Packages but will also be available to be deployed via Publishing…  You can publish you project by right clicking on your project and hit Publish as shown below…

     Publish

    I will soon write a detailed post on how to use the new “Publishing” features of Visual Studio 2010…

    Hope this information was useful…

    -Vishal

    Labels: , , , , , , , , , , , , , , , ,

    Friday, May 29, 2009

    I just got a Microsoft Tag !!

    In various conferences, events and other places I keep wondering if there was an easy way for me to share my information with folks and since Microsoft Tag came up I have been hoping to get one for myself…

    Finally I got one… In case you would like to get my V-Card feel free to download the tag resolver from http://microsoft.com/tag and scan it…

    Vishal Joshi Tag

    -Vishal

    Labels: ,

    Tuesday, May 26, 2009

    VS 2010 Project Conversion+ Upgrade

    Visual Studio 2010 will allow you to move your projects from previous versions of Visual Studios  to VS 2010 with ease, I will call this process as “Converting” the project from VS 200X to VS 2010… 

    VS 2010 will also allow you to change your project’s Target Framework Version to .NET 4.0 from .NET 2.0, 3.0 or 3.5…  I will call this process as “Upgrading”…

    The reason why VS allows you to deal with these two concepts separately is due to various reasons, some of which can be:

    • You might be ready to use the latest and greatest tooling features of VS 2010 even if you are not yet ready to move to .NET 4.0 just yet…
    • You might have a big solution with various projects and you might want to move few of the project to .NET 4.0 first and then take a staged approach to the rest of the projects…  Obviously you would not want to open various projects in different versions of VS…

    Project Conversion-  When you are using projects with .csproj/.vbproj files (e.g. Class Library, Web Application Project etc) then these files typically contain some type of information about VS IDE version example in .csproj file you can see below:

    <Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProductVersion>9.0.30729</ProductVersion>
    <SchemaVersion>2.0</SchemaVersion>



      In the above example  you can notice that there is msbuild/2003 in the schema namespace… There is also ProductVersion 9.0 in the sample above.  If you examine your project file in further depth you will also find references to the .targets files for the Web Application Projects like below:



     <Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v9.0\WebApplications\Microsoft.WebApplication.targets" />



    Notice that the location of the targets file is in above example is in “V9.0” directory in the above piece of xml…  This all needs to be changed to Visual Studio 2010 references (i.e. “V 10.0”) to allow your pre VS 2010 project to use new features of VS 2010. 



    The process by which pre VS 2010 (e.g. VS 2008, VS 2005)  project and solution files are modified to move to VS 2010 format is what I am referring to as Project Conversion.



    VS 2010 conversion wizard is very similar to how VS 2003/VS 2005 to VS 2008 conversion Wizard use to look like…  To convert pre VS 2010 project to VS 2010 you can double click the project or solution file on a box which has VS 2010 and the conversion wizard will kick off… Following will be the steps that you will see:



    Step 1: UI describing that your project will be converted



    VS Conversion Wizard



    Step 2: Option to back up your project (I would encourage you to create a back up of your project before converting so that you have a copy of your project in case there are any errors in conversion)



    VS conversion wizard back up option



    Step 3: Summary before the conversion begins



    VS Conversion Wizard Summary



    Note that so far you have not been asked about your .NET Framework Version.  Do not worry about it just yet and hit the “Finish” button above… You will be allowed to make a decision on whether or not you would like to “Upgrade” your project to .NET 4.0 in the next step.



    As soon as you click Finish, the project conversion will kick in the Project Upgrade dialog.



    Project Upgrade-  Step 3 of project conversion step is pretty much common to any VS project or solution file, by this what I mean is that some of the things like Product Version, Target File Paths etc are typically required to be changed for most projects including Web Projects… Apart from this step there are certain .NET Framework specific steps required to be done e.g. changes to the project file to indicate which .NET Framework version should be used for the project, similar type of changes in the solution file if need be and additionally for web projects changing the web.config file correctly based on the the framework version you are targeting… These changes are what I am referring to as “Project Upgrade”…



    Once you click “Finish” button in Step 3 above you should see the below  Framework Version dialog



    Step 4:  Choose whether or not to upgrade to .NET 4.0



    choose to upgrade to 4.0



    I will click “Yes” on the button above but you can choose to click “No” if you are not yet ready to move to ASP.NET 4.0 on the server.   As the dialog specifies you can change the target framework of your project eventually when you are ready by going to the project properties…



    If I click “Yes” my web.config file will be modified to conform to ASP.NET 4.0 format...  None of the additional items that you have added to your web.config file (e.g. appSettings, connectionStrings etc) will be altered but rather most of the assembly references in the web.config file will be modified to 4.0…



    In addition with ASP.NET 4.0 there is a need for a new attribute on the compilation tag as shown below:



    <compilation debug="true" targetFrameworkMoniker=".NETFramework,Version=v4.0">
    <assemblies>
    <add assembly="System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
    <add assembly="System.Data.DataSetExtensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
    <add assembly="System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    <add assembly="System.Xml.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/></assemblies>
    </compilation>



    The targetFrameworkMoniker attribute allows VS 2010 to identify that the web is a 4.0 web.  This allows VS 2010 to customize the intellisense, toolbox, references etc to 4.0 for your project. 



    As part of this project upgrade VS will automatically inject targetFrameworkMoniker attribute into your web.config file.   For a 4.0 web in VS 2010 and ASP.NET 4.0 this attribute is required, if you try to run a 4.0 web without this attribute in the web.config file then you will get an error  At this point you should get below screen after the conversion is successful.



    Step 5: Conversion Complete + Logs Screen



    VS 2010 Conversion Wizard Complete



    You can choose to open the conversion logs at this time or hit Close…  At this point your project should be ready to be used…



    Eventually I will write more about Conversion, Upgrade and details about it but in the meantime I hope this will help…



    -Vishal

    Labels: , , , , , , , , ,

    Wednesday, May 13, 2009

    How to find Delegated Vs Non Delegated IIS Settings?

    IIS Manager has a very nice tool to tell you what features are delegated vs non delegated on the server…  To find out go to Start—>Run –> InetMgr

    Now you can click on the server node and then select the “Feature Delegation” as shown below:

    image

    On clicking on the feature delegation IIS Manager will show you all the features which are delegated..

    image

    In most of the “Read/Write” scenarios when you modify your site settings using IISManager they are written into the application’s web.config file… Although certain features are locked down by IIS Manager and they cannot be changed in your application’s web.config file…

    These features are marked as “Read Only” and “Not Delegated”… By default following features are Read/Only and Not Delegated

    image

    In Win 7  there is work being done to allow changing Error Pages in the web.config file as well, although up until Win 7 that was not possible…

    Hope this helps!!

    Labels: , , , , , , , , ,