如何:启用 WCF 身份验证服务(摘录)

[ 2010-04-19 16:22:12 | 作者: 景裔 ]
字体大小: | |
启用身份验证服务

  如果还没有 ASP.NET Web 应用程序,请创建一个。

  向包含以下指令来引用 AuthenticationService 类的网站中添加一个服务文件 (.svc)。

  在 Web.config 文件中进行以下配置设置以配置服务及要求使用 SSL:

  在 authenticationService 元素中启用身份验证服务。

  在 services 元素中定义终结点协定,在 behaviors 元素中定义服务行为。在终结点协定中包括如以下示例所示的 bindingNamespace 属性,以防止在某些代理生成工具中出现异常。

  配置 serviceHostingEnvironment 元素以获得 ASP.NET 兼容性。

  在需要 SSL 的 bindings 元素中创建绑定。

  下面的示例演示 Web.config 文件中的 system.serviceModel 元素,该元素演示了上面列出的配置设置。
<system.web.extensions>
 <scripting>
 <webServices>
 <authenticationService enabled="true" 
 requireSSL = "true"/>
 </webServices>
 </scripting>
</system.web.extensions>
<system.serviceModel>
 <services>
 <service name="System.Web.ApplicationServices.AuthenticationService"
 behaviorConfiguration="AuthenticationServiceTypeBehaviors">
 <endpoint contract=
 "System.Web.ApplicationServices.AuthenticationService"
 binding="basicHttpBinding"
 bindingConfiguration="userHttps" 
 bindingNamespace="http:asp.net/ApplicationServices/v200"/>
 </service>
 </services>
 <bindings>
 <basicHttpBinding>
 <binding name="userHttps">
 <security mode="Transport" />
 </binding>
 </basicHttpBinding>
 </bindings>
 <behaviors>
 <serviceBehaviors>
 <behavior name="AuthenticationServiceTypeBehaviors">
 <serviceMetadata httpGetEnabled="true"/>
 </behavior>
 </serviceBehaviors>
 </behaviors>
 <serviceHostingEnvironment 
 aspNetCompatibilityEnabled="true"/>
</system.serviceModel>
配置 Forms 身份验证

  在 Web.config 文件中,配置 Web 应用程序以使用 Forms 身份验证。

  下面的示例演示 Web.config 文件中的 authentication 元素,该元素已配置为使用 Forms 身份验证。
<authentication mode="Forms">
 <forms cookieless="UseCookies" />
</authentication>
  身份验证服务需要 cookie。因此,在 authentication 元素中,应将 cookieless 属性设置为“UseCookies”。

永久地址 永久地址: http://blog.breakN.net/feed.asp?q=comment&id=506
UTF-8 Encoding 引用地址: http://blog.breakN.net/trackback.asp?id=506

此文还没有评论.

发表评论
表情
[smile] [confused] [cool] [cry]
[eek] [angry] [wink] [sweat]
[lol] [stun] [razz] [redface]
[rolleyes] [sad] [yes] [no]
[heart] [star] [music] [idea]
打开 UBB 编码
自动识别链接
显示表情
隐藏的评论
用户名:   密码:   注册?
验证码 * 请输入验证码