To choose which configuration to use in your cloud services, right click on the Azure project, and click properties:

Then go to Development, and there you can choose which configuration you want to use:

For this article I was using Windows Azure and SQL Database Tutorials - Tutorial 3: Using Windows Azure Blob Service.

In your controller you must to have code like:

 

public class BalooController : Controller
{
	private MyTableDBContext db = new MyTableDBContext();
	private const string messageImageBlobName = "golfermessageboardpics";
	private CloudBlobClient blobClient;
	private CloudBlobContainer blobContainer;
	private static CloudStorageAccount storageAccount;
	private CloudTableClient tableClient;

	public BalooController ()
	{
		string connectionString = RoleEnvironment.GetConfigurationSettingValue("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString");

		storageAccount = CloudStorageAccount.Parse(connectionString);
		tableClient = new CloudTableClient(storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials);
		tableClient.CreateTableIfNotExist("myBlob");

		blobClient = storageAccount.CreateCloudBlobClient();
		blobContainer = blobClient.GetContainerReference(messageImageBlobName);
		blobContainer.CreateIfNotExist();

		var permissions = blobContainer.GetPermissions();
		permissions.PublicAccess = BlobContainerPublicAccessType.Container;
		blobContainer.SetPermissions(permissions);
	}

	//
	// GET: /Baloo/

	public ViewResult Index()
	{
		return View(db.BlobModel.ToList());
	}

Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString
is in
MvcApplication17\MvcApplication17.Azure\ServiceConfiguration.Local.cscfg (if name of your app is MvcApplication17 :) )
and golfermessageboardpics is actual name of the blob.

 

One example of foreign key model, using code first approach:

  

public class MyMaster
{
	public int Id { get; set; }
	public string Username { get; set; }

	public virtual ICollection MyDetails { get; set; }
}

public class MyDetail
{
	public int Id { get; set; }

	[ForeignKey("MyMaster")]
	public int masterId { get; set; }

	public virtual MyMaster MyMaster { get; set; }
}

and another version of same thing:

public class MyMaster
{
	public int MyMasterId { get; set; }
	public string Username { get; set; }

}

public class MyDetail
{
	public int MyDetailId { get; set; }

	[ForeignKey("MyMasterId")]
	public int masterId { get; set; }

	public virtual MyMaster MyMasterId { get; set; }
}

To add MVC application to IIS as web site, just right click on the sites, click add web site, but if you want to have host name like on the picture:

If you create a MVC app by default, then you physical path should look like:

C:\Users\Stanko Milošev\Documents\Visual Studio 2010\Projects\MvcApplication1\MvcApplication1

MvcApplication1 is mentioned twice.

Then in your host file (C:\Windows\System32\drivers\etc\hosts) you have to add also host name (in my case test) something like:

127.0.0.1      test

Also, don't forget to change App pool to .NET 4.0 like:

Subcategories