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

发布于 2024-07-24 04:49:11 字数 1960 浏览 6 评论 0原文

我按照这篇博客文章创建一个天蓝色存储表: 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?

  • This is the error call stack from event viewer

    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)
    

    I'm following 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 fine on an asp.net webform web_role.

    I've re-created the same project using asp.net mvc as the web role, and it's always failing on application start. this line:

    StorageAccountInfo account = StorageAccountInfo.GetDefaultTableStorageAccountFromConfiguration();

    seem to always fail getting the account shared key.

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

  • Is there any difference in initializing a storage table in azure asp.net mvc compared to webform?
  • Why can't I get the azure appsettings on application start?
  • This is the error call stack from event viewer

    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)
    

    如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

    扫码二维码加入Web技术交流群

    发布评论

    需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

    评论(2

    纸短情长 2024-07-31 04:49:12

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

    Windows Azure 结构运行 IIS 7.0
    在集成模式下。 在综合
    模式下,Application_Start 事件执行
    不支持访问请求
    上下文或成员
    RoleManager 提供的类
    Windows Azure SDK 运行时 API。 如果你
    正在编写 ASP.NET 应用程序
    访问请求上下文或
    调用 RoleManager 类的方法
    从 Application_Start 事件中,您
    应该修改它以在中初始化
    Application_BeginRequest 事件
    相反。

    有关如何使用的示例
    Application_BeginRequest 事件,
    请参阅 PersonalWebSite 示例
    随 Windows Azure SDK 一起提供。

    Check out the "remarks" at 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.

    御守 2024-07-31 04:49:12

    如果使用:

    StorageAccountInfo account = StorageAccountInfo.GetDefaultTableStorageAccountFromConfiguration();
    

    通常帐户信息在 Web.conf 文件中给出。

    <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"/>
    

    If you use:

    StorageAccountInfo account = StorageAccountInfo.GetDefaultTableStorageAccountFromConfiguration();
    

    Usually the account information is given 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"/>
    
    ~没有更多了~
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文