Asp.net mvc 使用WCF服务验证移动应用程序功能调用
我刚刚开始为我的移动应用程序创建WCF服务。目前我有多个项目在单一的解决方案Asp.net mvc 使用WCF服务验证移动应用程序功能调用,asp.net-mvc,wcf,wcf-security,Asp.net Mvc,Wcf,Wcf Security,我刚刚开始为我的移动应用程序创建WCF服务。目前我有多个项目在单一的解决方案 主要网站项目 Edmx项目 WCF lib项目 认证功能 public List<AuthenticateModel> Authenticate(string UserName, string Password) { SimpleMembershipInitializer _initialized = new SimpleMembersh
- 主要网站项目
- Edmx项目
- WCF lib项目
public List<AuthenticateModel> Authenticate(string UserName, string Password)
{
SimpleMembershipInitializer _initialized = new SimpleMembershipInitializer();
bool validate = System.Web.Security.Membership.ValidateUser(UserName, Password);
AuthenticateModel model = new AuthenticateModel();
if (validate)
{
model.userID = IDUser
}
Return model;
}
公共列表身份验证(字符串用户名、字符串密码)
{
SimpleMembershipInitializer _initialized=新SimpleMembershipInitializer();
bool validate=System.Web.Security.Membership.ValidateUser(用户名、密码);
AuthenticateModel model=新AuthenticateModel();
如果(验证)
{
model.userID=IDUser
}
收益模型;
}
现在我怎么知道同一个登录用户正在调用另一个函数。这里是否有任何方法可以将会话维护为web?或者传递任何证书或令牌进行验证(如果是,如何传递令牌并实现它)
[运营合同]
[WebInvoke(UriTemplate=“GetAllrecords/?paramId={paramId}”,Method=“GET”,ResponseFormat=WebMessageFormat.Json,RequestFormat=WebMessageFormat.Json,BodyStyle=WebMessageBodyStyle.Wrapped)]
列出GetAllrecords(int参数ID)
{
返回某物;//返回请求的数据
}
如果您有时间阅读,我们将不胜感激。 本文重点讨论web api,但讨论令牌的使用 在我们的身份验证方法中,我们返回一个生成的令牌,该令牌使用user和role保存在服务器上 webclient(在我们的例子中是使用angularjs构建的)使用请求头中的令牌组合请求。然后,我们检查web api中的每个请求,提取令牌并将其与持久化令牌进行比较 有很多解决方案,我们的解决方案不是很安全,但对我们来说已经足够了
[OperationContract]
[WebInvoke(UriTemplate = "GetAllrecords/?paramId={paramId}", Method = "GET", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
List<SomeModel> GetAllrecords(int paramId)
{
Return something; // Return requested data
}