ADO.NET Data Service 访问权限设置
例子下载: https://files.cnblogs.com/wxwinter/power.rar
http://www.cnblogs.com/foundation/archive/2008/11/18/1335583.html
很多朋友询问我如何设置ADO.NET Data Service的权限.其实设置ADO.NET Data Service的权限与正常设置ASPNET网站的资源访问权限方式一样.
下面我就已ADO.NET Data Service文中的例子为原型,说明一下该如何设置资源访问权限
先规划一下ASPNET网站的资源结构
在Web.config中按如上设计进行权限配置
<authentication mode="Forms"> <forms name="poweridtag" loginUrl="publicweb/login.aspx" /> </authentication> <authorization> <deny users="?"> </deny> </authorization> |
<location path="ClientBin"> <system.web> <authorization> <allow users="*"> </allow> </authorization> </system.web> </location> <location path="publicweb"> <system.web> <authorization> <allow users="*"> </allow> </authorization> </system.web> </location> |
在publicweb中添加一loginService.svc服务,用于提供登录
[ServiceContract(Namespace = "")] [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] public class loginService { [OperationContract] public string login(string userID ,string password) { //判断 userID 与 password System.Web.Security.FormsAuthentication.SetAuthCookie("dbadmin", false); return "ok"; }
} |
在SilverlightApplication中添加对loginService.svc服务的引用,并用如下方式完成登录
private void login_Click(object sender, RoutedEventArgs e) { loginServer.loginServiceClient lsr = new SilverlightApplication.loginServer.loginServiceClient();
lsr.loginCompleted += new EventHandler<SilverlightApplication.loginServer.loginCompletedEventArgs>(lsr_loginCompleted);
lsr.loginAsync(this.userID.Text,this.password.Text);
}
void lsr_loginCompleted(object sender, SilverlightApplication.loginServer.loginCompletedEventArgs e) { if (e.Result == "ok") { MessageBox.Show("登录成功"); } } |
看一下效果