我正在使用
BotAuth nuget包登录我的机器人用户.最近,我按照
https://docs.microsoft.com/en-us/bot-framework/dotnet/bot-builder-dotnet-state-azure-table-storage中提到的步骤实现了Azure Table存储来存储和管理机器人的状态数据.
我的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模块注册.有没有人有这方面的工作样本.
最佳答案 正如@FeiHan在评论中指出的那样,这是一个公开的问题,在
richdizz/BotAuth. –
“Enabling custom state service causes authentication failure”.
此问题已于MicrosoftDX/botauth修复,因此首选使用此问题