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控制器'以使用您配置的数据存储。 –