Erstellen von Azure-Speichertabelle auf asp.net MVC
-
13-09-2019 - |
Frage
Ich folge dieses Blog-Post einen azurSpeicherTabelle zu erstellen: http: //blogs.msdn. com / jnak / Archiv / 2008/10/28 / Walkthrough-simple-table-storage.aspx
Es funktioniert auf einer asp.net Webformular web_role.
Ich habe das gleiche Projekt mit asp.net mvc als Web-Rolle neu erstellt, und es ist immer zum Scheitern verurteilte beim Start der Anwendung. diese Zeile:
StorageAccountInfo account = StorageAccountInfo.GetDefaultTableStorageAccountFromConfiguration();
scheint immer zum Scheitern verurteilt das Konto gemeinsam benutzten Schlüssel zu bekommen.
Wenn ich die Linie von den globalen asax Anwendung bewegen default.aspx starten, funktioniert es völlig in Ordnung.
Dies ist der Fehler Call-Stack von Ereignisanzeige
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)
Lösung
Überprüfen Sie die "Bemerkungen" unter http: //msdn.microsoft.com/en-us/library/microsoft.servicehosting.serviceruntime.rolemanager.aspx :
Die Windows Azure Gewebe läuft IIS 7.0 im integrierten Modus. in integrierten Modus, das Ereignis Application_Start tut kein Zugriff auf die Anfrage unterstützen Kontext oder die Mitglieder der Rolemanager-Klasse durch die bereitgestellten Windows Azure SDK Runtime API. Wenn du eine ASP.NET-Anwendung schreiben dass greift auf den Anforderungskontext oder ruft Methoden der Klasse Rolemanager von Ereignis Application_Start, Sie sollte es ändern in dem initialisieren Application_BeginRequest Veranstaltung statt.
Ein Beispiel, das zeigt, wie die Verwendung das Application_BeginRequest Ereignis, siehe PersonalWebSite Probe, Schiffe mit dem Windows Azure SDK.
Andere Tipps
Wenn Sie:
StorageAccountInfo account = StorageAccountInfo.GetDefaultTableStorageAccountFromConfiguration();
Normalerweise ist die Kontoinformationen in der Web.conf Datei gegeben.
<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"/>