asp.net-mvc – 在asp.net MVC上创建Azure存储表

我正在关注此博客文章以创建一个azure存储表:

http://blogs.msdn.com/jnak/archive/2008/10/28/walkthrough-simple-table-storage.aspx

它在asp.net webform web_role上工作正常.

我使用asp.net mvc作为Web角色重新创建了同一个项目,并且它始终在应用程序启动时失败.这一行:

StorageAccountInfo account = StorageAccountInfo.GetDefaultTableStorageAccountFromConfiguration();

似乎总是无法获得帐户共享密钥.

如果我将该行从全局asax应用程序启动移动到default.aspx,它可以正常工作.

>与webform相比,在azure asp.net mvc中初始化存储表有什么不同吗?
>为什么我不能在应用程序启动时获得azure appsettings?

这是来自事件查看器的错误调用堆栈

Exception information: 
    Exception type: HttpException 
    Exception message: No account key specified! 

Request information: 
    Request URL: http://127.0.0.1:5100/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)

最佳答案 查看
http://msdn.microsoft.com/en-us/library/microsoft.servicehosting.serviceruntime.rolemanager.aspx的“备注”:

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

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

点赞