milosev.com
  • Home
    • List all categories
    • Sitemap
  • Downloads
    • WebSphere
    • Hitachi902
    • Hospital
    • Kryptonite
    • OCR
    • APK
  • About me
    • Gallery
      • Italy2022
    • Curriculum vitae
      • Resume
      • Lebenslauf
    • Social networks
      • Facebook
      • Twitter
      • LinkedIn
      • Xing
      • GitHub
      • Google Maps
      • Sports tracker
    • Adventures planning
  1. You are here:  
  2. Home
  3. ASP.NET
  4. MVC 3

Local or cloud configuration

Details
Written by: Stanko Milosev
Category: MVC 3
Published: 10 October 2013
Last Updated: 30 November -0001
Hits: 3678

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:

Local blob storage

Details
Written by: Stanko Milosev
Category: MVC 3
Published: 10 October 2013
Last Updated: 10 October 2013
Hits: 3967

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.

 

Foreign key

Details
Written by: Stanko Milosev
Category: MVC 3
Published: 16 April 2013
Last Updated: 16 April 2013
Hits: 4507

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; }
}

Add web site to IIS

Details
Written by: Stanko Milosev
Category: MVC 3
Published: 09 April 2013
Last Updated: 09 April 2013
Hits: 4785

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:

  1. WADLogsTable
  2. The type or namespace name 'Schema' does not exist in the namespace 'System.ComponentModel.DataAnnotations' (are you missing an assembly reference?)
  3. DropDownList - disabled
  4. AccountController

Subcategories

Razor

Page 1 of 6

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6