This is the third post of Migrating ASP.NET Application to Windows Azure series. You are encourage to read my first post about Preparing the ASP.NET Application and the second post about Preparing SQL Azure Database if you have not do so. Without further due, let’s get started.
Before conversion, do note that web role is actually ASP.NET web application++, not ASP.NET website. If you are not sure about the difference, please go through the following blogs and discussion about that:
The ++ that I’ve mentioned before is some additional files as well as minor changes as following:
- WebRole.cs / WebRole.vb which derived from RoleEntryPoint that functions for initiating the configuration of your Windows Azure WebRole project.
- If you notice your web.config file, there would be an additional section as following:
<add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=188.8.131.52, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="AzureDiagnostics">
Alright, now let’s get our hand dirty to convert the core application.
I’ll continue the steps that are done in the first post here. We have 3 projects in our solution: namely the Website personal, CloudServicePersonal,and PersonalWebRole.
1. As we need to align our webrole with the website personal content,we need to delete the unused files in default WebRole project. On the WebRole project “PersonalWebRole”, delete the default.aspx and web.config file. Note that, if we want to implement the diagnostic, we’ll need to manually add those diagnostic section later on.
2. Next step is to copy the entire content of the website personal to the PersonalWebrole. Block all of the content from personal website and drag it to PersonalWebRole. Alternately, you can do so by copy the website personal and paste it on the PersonalWebRole.
If it prompts for merge folders, check “Apply to all items” and select “Yes” to merge.
3. Remembering that ASP.NET Web Role is based on ASP.NET Web application, not web site, we will need to convert the aspx files to web application so that it contains the .designer.cs file. To do that, right click on the PersonalWebRole and select Convert to Web Application.
4. You may delete your personal website as we don’t need to use it anymore.
5. Try to build the solution to check if any error occurs.
6. As hosting your application on Windows Azure is somehow different with traditional web application, we’ll need to examine the code whether they are all valid.
Some example of invalid code could be found in App_CodePhotoManager.cs, ListUploadDirectory() method since it tries to get the detail directory info of “upload” folder. Comment this method.
We’ll also need to comment any other code that call that method such as AdminPhoto.aspx.
In some case where you really need the similar functionality, of course you’ll need to modify it as required to be ready to run on Azure. For example, If your ASP.NET Website allow people to upload and store the file on file system, you will want to implement similar feature using Azure Storage Blob. I’ll talk about those stuff on the further post if possible .
Updated on 8 Sept 2010: Please refer this link where I’ve implemented similar functionality for bulk upload
7. Run the web role on the development fabric by pressing F5 or Run. Development Fabric is the local simulation environment of Windows Azure hat implements things like load balancing, etc. Make sure that your website is running well on development fabric first before deploy it to real Windows Azure environment.
8. Try to log-in with the credential to see whether it’s running well.
9. Congratulation if you’ve done at this step. It means that you have successfully converted your web site to Windows Azure web role, as well as have successfully connected it to SQL Azure.
But wait, you are not done yet! Why? Running well on development fabric, doesn’t mean it will run well on Windows Azure .
No worries, in next post, I’ll show you how to deploy it to Windows Azure and solve each problem if there’s any issue arise.