C#、.Net - 使用自定义用户验证实现表单身份验证
基本上,我有一个在现有 API 之上构建的 Web 应用程序,当用户登录时,用户名和密码通过 SOAP 调用传递以进行身份验证,并且我收到一个响应,告诉我用户是否有效带有状态代码(和其他信息)。
但仅此而已。我想实现基本的表单身份验证,使用此 API 调用来验证用户并让他登录到我的网络应用程序。现在我们只需要担心一个角色,因此每个登录的人都会看到同样的事情。
我不太确定从哪里开始......
Basically I have a web app that I'm building on top of an existing API and when the user logs in the userName and Password are passed via a SOAP call for authentication and I get a response telling me if the user is valid or not along with a status code (and other info).
But that's pretty much it. I'd like to implement basic Forms Authentication that uses this API call to validate the user and essentially log him in to my web app. Right now we only have to worry about one role, so everybody that logs in sees the same thing.
I'm not quite sure where to begin...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
实现自定义成员资格提供程序相当简单:请参阅此处:http://msdn.microsoft .com/en-us/library/f1kyba5e.aspx 了解详细信息。
您应该能够将其与 WCF 结合起来以获得您需要的东西。
对于不合适的方法,例如更改密码,则抛出
NotImplementedException
是正确的做法。Implementing a custom membership provider is fairly simple: see here: http://msdn.microsoft.com/en-us/library/f1kyba5e.aspx for details.
You should be able to combine this with WCF to get what you need.
For the methods that aren't appropriate, e.g. changing passwords, then throwing
NotImplementedException
is the right thing to do.当用户登录时,执行 SOAP 调用,如果成功,则调用
FormsAuthentication.SetAuthCookie(username, bool permanent)
。其他的都可以正常使用;在 Web.config 中设置
loginUrl
以指向您的自定义登录页面。When a user logs in, perform your SOAP call, and, if it succeeds, call
FormsAuthentication.SetAuthCookie(username, bool persistent)
.You can use everything else normally; set
loginUrl
in Web.config to point to your custom login page.