Say I have an ASP.NET webpage and I also have a PHP Blog/BBS/Website. I want all logins to be done via the ASP.NET webpage. The ASP.NET Session State is stored in SQL. Is there any way I can read/decode the Session State from PHP to tell if a user is logged on if I have the Session State cookie?
4 回答
I don't think there's a supported way. You could reverse-engineer the store, but the database format may change with next .NET service pack and youe a'd be screwed then.
The only safe way would be to implement your own session state provider so you could guarantee that the database format doesn't change.
If all you need is to verify that the user is authenticated, it would be probably easier to send the user an encrypted cookie with the username and decrypt it in the PHP app.
除非您特别需要对整个 asp.net 会话状态的完全访问权限,否则最好将您知道两个应用程序需要直接共享的特定信息存储在共享数据库或文件中。
这样,您就可以忽略 asp.net 会话的大部分复杂性,而只需挑选您的应用程序需要相互共享的特定数据片段。
我从未尝试过,但如果您提供了一个简单的 Web 服务,它是您的 asp.net 应用程序的一部分,但只能从您的 PHP 站点访问。您现在应该能够通过网络服务读取会话中的任何内容。
这看起来很棘手,但请尝试阅读此处。这里的问题是知道 asp 编码和保存会话的方式,如果您可以阅读该格式,这可能会有所帮助。
我在想的另一种方法是向php创建一个对一些“登录”页面表单的请求,在那里你发送登录凭据并且php文件创建会话,但是如果你让它保持打开状态,这可能是不安全的,而且可能很慢,因为需要另一个请求。
另一方面,我看到很少有网站,一旦你登录,例如在主站点,你想去论坛,你点击一些链接,将表单提交到 php 登录页面(凭据是“硬编码的” " 对于该会话中的该用户)和 php 页面登录,您喜欢“常规”行为。
希望清楚