.NET Remoting Security使用小结 – HttpChannel

 1.        如何设置HttpChannel 的安全性?

HttpChannel本身无安全性可言。它是通过将Remote ObjectIISHost,然后就利用IIS的安全设置。设置方法是:

1)         Authentication:右击IISRemote Object所在的虚拟目录,选“Properties-> Directory Security -> Anonymous access and authentication control -> Edit -> 去掉“Anonymous access”,选“Windows Integrated Authentication”。

2)         Encryption: 右击IISRemote Object所在的Web Site, 选“Properties-> Web Site -> SSL Port。(Note:在XP上该选项是Disable的,在Windows Server 2003上直接填上SSL端口号即可。)

 

2.       如何将Remote ObjectIISHost

首先要说明的是通常在开发Remoting程序时,需要产生三个模块:Server模块,Client模块和Remote Object模块。其中Server模块就是用于Host Remote Object的。这里需要由IISHost,所以可以去掉Server模块。

IISHost Remote Object的步骤是:

1)         IIS上创建一个虚拟目录(假设名字为HttpBinary),假设对应“C:\Test\RemoteIIS”。

2)         在“C:\Test\RemoteIIS”下建一个名为“bin”的子目录,将Remote Object所在的DLL(假设为RemoteHello.DLL)拷到该目录下。

3)         远程对象的配置只能通过配置文件来完成。在“C:\Test\RemoteIIS”创建一个名为“Web.config”文件,如内容如下:

<configuration>

   <system.runtime.remoting>

      <application>

         <service>

            <wellknown

               mode="SingleCall" objectUri="SecurityTest.rem"

               type="Spacer_Robot.RemotingTest.Hello, RemoteHello"/>

         </service>

         <channels>

            <channel ref="http"/>

         </channels>

      </application>

   </system.runtime.remoting>  

</configuration>

注意Remote ObjectURL必须以“.rem”结尾。在指定Remote Object的类型时,不要忘了前面的namespace

 

3.       Client如何访问该远程对象?

代码如下:

Hello obj = (Hello)Activator.GetObject(typeof(Hello), "http://machinename:80/HttpBinary/SecurityTest.rem");

                if (obj == null)

                {

                    Console.WriteLine("Could not lcoate server");

                    return;

                }

                IDictionary props = ChannelServices.GetChannelSinkProperties(obj);

                // Set domain, username, and password properties

                props["domain"] = "xxxxx";

                props["username"] = "xxxxx";

            props["password"] = "xxxxx";

然后就可以通过obj来调用远程函数了。需要注意的是这里用户名和密码的设置只能通过代码来完成,在配置文件中设没有用。

 

4.       Server端(IIS)如何获得Client端是用什么用户来调用的?

通过HttpContext.Current.User.Identity.Name获得。Server端拿到用户名后,可以决定是否允许该用户的调用,从而实现授权。

转载于:https://www.cnblogs.com/zsh_robot/articles/1345136.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值