Creating an Azure storage table on asp.net MVC

I follow this blog post to create an azure storage table: http://blogs.msdn.com/jnak/archive/2008/10/28/walkthrough-simple-table-storage.aspx

It works great on asp.net web_role web page.

I re-created the same project using asp.net mvc as a web role and it always fails when the application starts. this line:

  StorageAccountInfo account = StorageAccountInfo.GetDefaultTableStorageAccountFromConfiguration (); 

It seems that it is always not possible to get the shared account key.

If I translate the line from the asax start global application to default.aspx, it works fine.

Is there a difference in initializing the storage table in azure asp.net mvc compared to webform? Why can't I get azure appsettings when I start the application?

This is a stack of error calls from the event viewer
  Exception information: 
     Exception type: HttpException 
     Exception message: No account key specified! 

 Request information: 
     Request URL: http://127.0.0.1►100/do.__rd_runtime_init__?shutdownEvent=1B671B93FD-4153-4834-9D5D-595EFC6C19EE1D 
     Request path: /do.__rd_runtime_init__ 
     User host address: 127.0.0.1 
     User:  
     Is authenticated: False 
     Authentication Type:  
     Thread account name: *****

 Thread information: 
     Thread ID: 6 
     Thread account name: *****
     Is impersonating: False 
     Stack trace: at System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode (HttpContext context, HttpApplication app)
    at System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS (IntPtr appContext, HttpContext context, MethodInfo [] handlers)
    at System.Web.HttpApplication.InitSpecial (HttpApplicationState state, MethodInfo [] handlers, IntPtr appContext, HttpContext context)
    at System.Web.HttpApplicationFactory.GetSpecialApplicationInstance (IntPtr appContext, HttpContext context)
    at System.Web.HttpApplicationFactory.GetPipelineApplicationInstance (IntPtr appContext, HttpContext context)
    at System.Web.Hosting.PipelineRuntime.InitializeApplication (IntPtr appContext)

thanks

+4
source share
2 answers

Check the "notes" at http://msdn.microsoft.com/en-us/library/microsoft.servicehosting.serviceruntime.rolemanager.aspx :

In a Windows Azure environment, IIS 7.0 runs in integrated mode. In integrated mode, the Application_Start event does not support access to the context request or members of the RoleManager class provided by the Windows Azure SDK API. if you are writing an ASP.NET application that accesses the request context or calls the methods of the RoleManager class from the Application_Start event, you must change it to initialize the Application_BeginRequest event instead.

For an example showing how to use the Application_BeginRequest event, see the PersonalWebSite example that ships with the Windows Azure SDK.

+2
source

If you use:

StorageAccountInfo account = StorageAccountInfo.GetDefaultTableStorageAccountFromConfiguration(); 

Typically, account information is provided in the Web.conf file.

 <add key="TableStorageEndpoint" value="http://127.0.0.1:10002/devstoreaccount1" /> <add key="AccountName" value="devstoreaccount1" /> <add key="AccountSharedKey" value="YOUR ACCOUNT KEY PROVIDED BY AZURE"/> 
0
source

Source: https://habr.com/ru/post/1286169/


All Articles