silverlight   发布时间:2022-05-04  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Silverlight+WCF登录验证源代码下载大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

对于简单的安全性不高的wcf如果寄宿在IIS中wcf的验证完全可基于asp.net 的窗体验证http://blog.csdn.net/shanyou/archive/2009/09/06/4680978.aspx 该文对“WCF服务中操作FormsAuthentication的Cookie”操作有详细的说明 C# code // 建立us

对于简单的安全性不高的wcf如果寄宿在IIS中wcf的验证完全可基于asp.net 的窗体验证http://blog.csdn.net/shanyou/archive/2009/09/06/4680978.aspx
该文对“WCF服务中操作FormsAuthentication的Cookie”操作有详细的说明

C# code
  
  
// 建立user wcf锲约 [serviceContract(Namespace = "" )] public interface IUser { [OperationContract] Loginmessage DoWork( String Name); [OperationContract] Loginmessage Login( String username, String pass); [OperationContract] void SignOut(); } /// <sumMary> /// login DataContract /// </sumMary> [DataContract] public class Loginmessage { [DataMember] public String Text; } // 实现接口 // 注意: 如果更改此处的类名 "User",也必须更新 App.config 中对 "User" 的引用。 [AspNetCompatibilityrequirements(requirementsMode = AspNetCompatibilityrequirementsMode.Allowed)] public class User : IUser { public Loginmessage DoWork( String Name) { Loginmessage a = new Loginmessage(); if (UserAuthenticate.isAuthenticate()) { a.Text = " Hello " + httpContext.Current.User.Identity.Name.Trim(); } else { a.Text = " notlogin " ; } return a; } public Loginmessage Login( String username, String pass) { Loginmessage a = new Loginmessage(); if (username == " xgr2004 " && pass == " 123456 " ) { UserAuthenticate.VerifyUser(username,pass); a.Text = " true " ; } else { a.Text = " false " ; } return a; } public void SignOut() { UserAuthenticate.SignOut(); } // 验证部分,这里拷了我给出连接 public class UserAuthenticate { static public String VerifyUser( String username, String password) { System.Web.Security.FormsAuthentication.SetAuthCookie(username, true ); // 创建验证票 System.Web.Configuration.FormsAuthenticationConfiguration formsConfig = new System.Web.Configuration.FormsAuthenticationConfiguration(); FormsAuthenticationTicket formAuthTicket = new FormsAuthenticationTicket( 1 , // 版本 username, // 用户名 datetiR_462_11845@e.Now, // 创建时间 datetiR_462_11845@e.Now.Addminutes(formsConfig.Timeout.@R_344_10586@lminutes), // 失效时间 true , "" ); // 用户数据 // 加密票 String encryptedTicket = FormsAuthentication.Encrypt(formAuthTicket); // 以加密票的密文存入Cookie httpCookie authCookie = new httpCookie(FormsAuthentication.FormsCookiename,encryptedTicket); authCookie.httpOnly = true ; authCookie.Path = FormsAuthentication.FormsCookiePath; authCookie.Secure = FormsAuthentication.requireSSL; if (FormsAuthentication.CookieDomain != null ) { authCookie.Domain = FormsAuthentication.CookieDomain; } if (formAuthTicket.IsPersistent) { authCookie.Expires = formAuthTicket.Expiration; } httpContext.Current.Response.Cookies.Add(authCookiE); FormsIdentity identity = new FormsIdentity(formAuthTicket); GenericPrincipal principal = new GenericPrincipal(identity, null ); httpContext.Current.User = principal; return "" ; return null ; } static public bool isAuthenticate() { return httpContext.Current.User.Identity.IsAuthenticated; } static public void SignOut() { FormsAuthentication.SignOut(); httpContext.Current.Session.Clear(); } }

@H_518_1058@
源代码下载

代码的相关介绍:
网上查阅了相关WCF的例子,一般都要证书,对于简单的安全性不高的wcf如果寄宿在IIS中wcf的验证完全可基于asp.net 的窗体验证http://blog.csdn.net/shanyou/archive/2009/09/06/4680978.aspx
该文对“WCF服务中操作FormsAuthentication的Cookie”操作有详细的说明
C# code
         
         
// 建立user wcf锲约 [serviceContract(Namespace = "" )] public interface IUser { [OperationContract] Loginmessage DoWork( String Name); [OperationContract] Loginmessage Login( String username, String pass); [OperationContract] void SignOut(); } /// <sumMary> /// login DataContract /// </sumMary> [DataContract] public class Loginmessage { [DataMember] public String Text; } // 实现接口 // 注意: 如果更改此处的类名 "User",也必须更新 App.config 中对 "User" 的引用。 [AspNetCompatibilityrequirements(requirementsMode = AspNetCompatibilityrequirementsMode.Allowed)] public class User : IUser { public Loginmessage DoWork( String Name) { Loginmessage a = new Loginmessage(); if (UserAuthenticate.isAuthenticate()) { a.Text = " Hello " + httpContext.Current.User.Identity.Name.Trim(); } else { a.Text = " notlogin " ; } return a; } public Loginmessage Login( String username, String pass) { Loginmessage a = new Loginmessage(); if (username == " xgr2004 " && pass == " 123456 " ) { UserAuthenticate.VerifyUser(username,pass); a.Text = " true " ; } else { a.Text = " false " ; } return a; } public void SignOut() { UserAuthenticate.SignOut(); } // 验证部分,这里拷了我给出连接 public class UserAuthenticate { static public String VerifyUser( String username, String password) { System.Web.Security.FormsAuthentication.SetAuthCookie(username, true ); // 创建验证票 System.Web.Configuration.FormsAuthenticationConfiguration formsConfig = new System.Web.Configuration.FormsAuthenticationConfiguration(); FormsAuthenticationTicket formAuthTicket = new FormsAuthenticationTicket( 1 , // 版本 username, // 用户名 datetiR_462_11845@e.Now, // 创建时间 datetiR_462_11845@e.Now.Addminutes(formsConfig.Timeout.@R_344_10586@lminutes), // 失效时间 true , "" ); // 用户数据 // 加密票 String encryptedTicket = FormsAuthentication.Encrypt(formAuthTicket); // 以加密票的密文存入Cookie httpCookie authCookie = new httpCookie(FormsAuthentication.FormsCookiename,encryptedTicket); authCookie.httpOnly = true ; authCookie.Path = FormsAuthentication.FormsCookiePath; authCookie.Secure = FormsAuthentication.requireSSL; if (FormsAuthentication.CookieDomain != null ) { authCookie.Domain = FormsAuthentication.CookieDomain; } if (formAuthTicket.IsPersistent) { authCookie.Expires = formAuthTicket.Expiration; } httpContext.Current.Response.Cookies.Add(authCookiE); FormsIdentity identity = new FormsIdentity(formAuthTicket); GenericPrincipal principal = new GenericPrincipal(identity, null ); httpContext.Current.User = principal; return "" ; return null ; } static public bool isAuthenticate() { return httpContext.Current.User.Identity.IsAuthenticated; } static public void SignOut() { FormsAuthentication.SignOut(); httpContext.Current.Session.Clear(); } }


 

Silverlight+WCF登录验证源代码下载


当点击登陆,用户名为xgr2004时就登陆,成功登陆后然后点操作就会显示Hello name的说明

反之如果没有登陆就显示notlogin

转载:http://www.cnblogs.com/Guroer/archive/2010/01/30/1660214.html

大佬总结

以上是大佬教程为你收集整理的Silverlight+WCF登录验证源代码下载全部内容,希望文章能够帮你解决Silverlight+WCF登录验证源代码下载所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。