4
我正在使用BotAuth nuget包登錄我的機器人用戶。最近,我按照https://docs.microsoft.com/en-us/bot-framework/dotnet/bot-builder-dotnet-state-azure-table-storage中提到的步驟執行Azure Table存儲以存儲和管理機器人狀態數據。BotAuth與Azure表存儲錯誤
我的Global.asax.cs文件看起來像這樣:
public class WebApiApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
var store = new TableBotDataStore(CloudStorageAccount.DevelopmentStorageAccount);
Conversation.UpdateContainer(builder =>
{
builder.Register(c => store)
.Keyed<IBotDataStore<BotData>>(AzureModule.Key_DataStore)
.AsSelf()
.SingleInstance();
builder.Register(c => new CachingBotDataStore(store,
CachingBotDataStoreConsistencyPolicy
.ETagBasedConsistency))
.As<IBotDataStore<BotData>>()
.AsSelf()
.InstancePerLifetimeScope();
});
GlobalConfiguration.Configure(WebApiConfig.Register);
}
}
而且MessagesController是一樣的人在BOT模板:現在
[BotAuthentication]
public class MessagesController : ApiController
{
/// <summary>
/// POST: api/Messages
/// Receive a message from a user and reply to it
/// </summary>
public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
{
if (activity.Type == ActivityTypes.Message)
{
await Conversation.SendAsync(activity,() => new Dialogs.RootDialog());
}
else
{
HandleSystemMessage(activity);
}
var response = Request.CreateResponse(HttpStatusCode.OK);
return response;
}
private Activity HandleSystemMessage(Activity message)
{ ...... }
}
,在測試它,我得到如預期的登錄卡和點擊並完成授權過程後,我在瀏覽器中出現以下錯誤:
{
"message": "An error has occurred.",
"exceptionMessage": "Object reference not set to an instance of an object.",
"exceptionType": "System.NullReferenceException",
"stackTrace": " at BotAuth.AADv1.ADALAuthProvider.<GetTokenByAuthCodeAsync>d__4.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at BotAuth.Controllers.CallbackController.<Callback>d__3.MoveNext()"
}
我錯過了什麼?它是一些autofac模塊註冊。有沒有人有任何工作示例。
能否請您發表您的消息控制器呢? – JasonSowers
加入@JasonSowers。消息控制器與bot初始模板中的相同。我沒有做任何改變。 –
我在github上發現[這個問題:「***啓用自定義狀態服務導致身份驗證失敗***」](https://github.com/richdizz/BotAuth/issues/8),你可以參考weshackett的評論和嘗試修改'CallBack控制器'以使用您配置的數據存儲。 –