获取正在访问我的使用bot框架开发的bot的用户的ip地址(使用c#)

时间:2018-12-03 16:18:39

标签: c# asp.net botframework

我想获取正在访问我的聊天机器人的用户的IP地址。我尝试了几种选择,但我正在获取托管我的机器人的服务器的IP地址。有没有办法获取用户的IP?

2 个答案:

答案 0 :(得分:1)

您无法使用默认方法Appointmentcreate table appointment (client_id bigint not null, lawyer_id bigint not null, primary key (client_id, lawyer_id)) create table client (id bigint generated by default as identity, primary key (id)) alter table appointment add constraint FK3gbqcfd3mnwwcit63lybpqcf8 foreign key (client_id) references client create table lawyer (id bigint generated by default as identity, primary key (id)) alter table appointment add constraint FKc8o8ake38y74iqk2jqpc2sfid foreign key (lawyer_id) references lawyer insert into client (id) values (null) insert into lawyer (id) values (null) select appointmen0_.client_id as client_i1_0_0_, appointmen0_.lawyer_id as lawyer_i2_0_0_ from appointment appointmen0_ where appointmen0_.client_id=? and appointmen0_.lawyer_id=? insert into appointment (client_id, lawyer_id) values (?, ?) insert into lawyer (id) values (null) insert into client (id) values (null) select appointmen0_.client_id as client_i1_0_0_, appointmen0_.lawyer_id as lawyer_i2_0_0_ from appointment appointmen0_ where appointmen0_.client_id=? and appointmen0_.lawyer_id=? insert into appointment (client_id, lawyer_id) values (?, ?) select client0_.id as id1_1_0_, appointmen1_.client_id as client_i1_0_1_, appointmen1_.lawyer_id as lawyer_i2_0_1_, lawyer2_.id as id1_2_2_, appointmen1_.lawyer_id as lawyer_i2_0_0__, appointmen1_.client_id as client_i1_0_0__ from client client0_ left outer join appointment appointmen1_ on client0_.id=appointmen1_.lawyer_id left outer join lawyer lawyer2_ on appointmen1_.lawyer_id=lawyer2_.id where client0_.id=? select client0_.id as id1_1_1_, appointmen1_.lawyer_id as lawyer_i2_0_3_, appointmen1_.client_id as client_i1_0_3_, appointmen1_.client_id as client_i1_0_0_, appointmen1_.lawyer_id as lawyer_i2_0_0_ from client client0_ left outer join appointment appointmen1_ on client0_.id=appointmen1_.lawyer_id where client0_.id=? select appointmen0_.client_id as client_i1_0_0_, appointmen0_.lawyer_id as lawyer_i2_0_0_ from appointment appointmen0_ where appointmen0_.client_id=? and appointmen0_.lawyer_id=? insert into appointment (client_id, lawyer_id) values (?, ?) select appointmen0_.client_id as client_i1_0_0_, appointmen0_.lawyer_id as lawyer_i2_0_0_ from appointment appointmen0_ where appointmen0_.client_id=? and appointmen0_.lawyer_id=? insert into appointment (client_id, lawyer_id) values (?, ?) 来检索用户IP地址,因为(Azure)Bot Connector服务介于两者之间。您与最终用户没有直接连接,并且Bot连接器服务未传递用户的公共IP地址。

  • Microsoft Teams完全不允许这样做,一种可能的解决方法是在弹出式窗口/选项卡/浏览器中打开自定义网站,并在其中记录当前用户的IP地址。

    默认情况下,
  • WebChat(具有DirectLine服务)不支持此功能,但是您可以leverage the backchannel发送IP地址作为自定义事件。


除了身份验证之外,我看不到为什么您需要用户的公共IP地址。如果需要使用它进行身份验证,则我的选择是使用Azure Active Directory或其他身份提供程序来实现身份验证。 Add authentication to your bot via Azure Bot Service

答案 1 :(得分:-3)

请尝试以下操作以获取客户端计算机的IP地址

   string VisitorsIPAddress = string.Empty;
   if (HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != null)
     {
        VisitorsIPAddress = 
      HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
     }
   else if (HttpContext.Current.Request.UserHostAddress.Length != 0)
     {
        VisitorsIPAddress = HttpContext.Current.Request.UserHostAddress;
     }
   else         
     {
         VisitorsIPAddress = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
     }