我用 MS Bot SDK 创建了一个机器人。然后,我想获取我托管机器人的页面 URL。我只是将脚本注入(inject)页面以托管机器人。但是,有谁知道如何从 C# 获取当前页面的 URL 吗?
我可以看到有人正在尝试使用 Activity 获取 URL,但我无法从 Activity 中找到正确的属性。
最佳答案
I just inject the script to a page to host the bot. But, does anyone who knows how to get the current page URL from C#?
如果你embed webchat in your web site并且您想获取嵌入网络聊天的网页的 URL,您可以尝试以下方法来获取 URL 并将其传递给您的机器人。
将 URL 传递给机器人:
<script>
var urlref = window.location.href;
BotChat.App({
directLine: { secret: "{directline_secret}" },
user: { id: 'You', pageurl: urlref},
bot: { id: '{bot_id}' },
resize: 'detect'
}, document.getElementById("bot"));
</script>
在机器人应用程序中检索 URL:
if (activity.From.Properties["pageurl"] != null)
{
var urlref= activity.From.Properties["pageurl"].ToString();
}
关于c# - MS Bot 获取当前页面 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50111251/