在PHP和ASP.Net之间传递会话或身份验证状态

时间:2023-01-07 16:48:45

We have a current (legacy) PHP based website that is unlikely to be redeveloped for the next year or so, that acts as our main portal.

我们有一个当前(遗留)基于PHP的网站,不太可能在明年左右重新开发,作为我们的主要门户网站。

We would like to develop new applications in ASP.Net, and plug them into the current portal - but we do not want our website users to have to log in twice.

我们想在ASP.Net中开发新的应用程序,并将它们插入当前的门户网站 - 但我们不希望我们的网站用户必须登录两次。

Whats the best way to share authentication state between the two platforms? They do not share the same server, database backend or even proxy.

什么是在两个平台之间共享身份验证状态的最佳方式?它们不共享相同的服务器,数据库后端甚至代理。

3 个解决方案

#1


Read this article from Microsoft on sharing session state between classic ASP and ASP.NET:

阅读Microsoft关于在经典ASP和ASP.NET之间共享会话状态的文章:

http://msdn.microsoft.com/en-us/library/aa479313.aspx

Conceptually, I think this is pretty similar to what you're trying to do, though I don't know just how helpful the above document will be to your specific case. Definitely worth a look though.

从概念上讲,我认为这与您尝试做的非常相似,但我不知道上述文档对您的具体案例有多大帮助。绝对值得一看。

#2


I guess your best bet is a separate database or memory backed server to handle session state. Either you could use ASP.NET's built in SQL Server-based session state and add hook it up to PHP manually or use a custom solution.

我想你最好的选择是一个单独的数据库或内存支持服务器来处理会话状态。您可以使用ASP.NET内置的基于SQL Server的会话状态,并手动将其连接到PHP或使用自定义解决方案。

#3


I needed to this a while back for a fairly large project. The languages were ASP.Net and ASP, but the method I ended up with would work just as well if it were PHP instead of ASP.

我需要一段时间来做一个相当大的项目。这些语言是ASP.Net和ASP,但是如果它是PHP而不是ASP,那么我最终使用的方法也会起作用。

Can you abstract out the places your PHP application modifies session variables?

你可以抽象出PHP应用程序修改会话变量的位置吗?

I found that even for large web applications, there were only a handful of places session variables were updated. For instance; Login, Logout, some sought of change group action, etc. For me, there were less than 6 scripts that needed to be modified.

我发现即使对于大型Web应用程序,也只有少数几个地方会话变量被更新。例如;登录,注销,一些寻求更改组操作等。对我来说,需要修改的脚本少于6个。

For each script that modify session variables, add a server redirect to a new ASP.Net script. Hence the PHP script would do all it had to do and the final thing would be a PHP redirect ( mabye PHP Header("Location:...") call at the end.

对于修改会话变量的每个脚本,将服务器重定向添加到新的ASP.Net脚本。因此,PHP脚本将完成所有必须做的事情,最后的事情将是PHP重定向(最后的mabye PHP Header(“Location:...”)调用。

Your receiving ASP.Net script updates the ASP.Net session variables in the same manner the PHP script update its session. Luckily in my case the original scripts did not output any data, but rather redirected to "success" pages.

您接收的ASP.Net脚本以与PHP脚本更新其会话相同的方式更新ASP.Net会话变量。幸运的是,在我的情况下,原始脚本没有输出任何数据,而是重定向到“成功”页面。

i.e. The original scripts were the Controller code in a MVC design, and they redirected to the View code. This allowed me to neatly insert my ASP.Net scripts between the ASP controller and the view scripts. If your receiving script outputs data, then you will have to split that up into 2 pages.

即原始脚本是MVC设计中的Controller代码,并且它们重定向到View代码。这使我能够在ASP控制器和视图脚本之间整齐地插入我的ASP.Net脚本。如果您的接收脚本输出数据,那么您必须将其拆分为2页。

That's it. In effect, doing this for Login, Logout, and a few pages effectively caused the two session scopes to stay in sync.

而已。实际上,对Login,Logout和几个页面执行此操作有效地导致两个会话范围保持同步。

#1


Read this article from Microsoft on sharing session state between classic ASP and ASP.NET:

阅读Microsoft关于在经典ASP和ASP.NET之间共享会话状态的文章:

http://msdn.microsoft.com/en-us/library/aa479313.aspx

Conceptually, I think this is pretty similar to what you're trying to do, though I don't know just how helpful the above document will be to your specific case. Definitely worth a look though.

从概念上讲,我认为这与您尝试做的非常相似,但我不知道上述文档对您的具体案例有多大帮助。绝对值得一看。

#2


I guess your best bet is a separate database or memory backed server to handle session state. Either you could use ASP.NET's built in SQL Server-based session state and add hook it up to PHP manually or use a custom solution.

我想你最好的选择是一个单独的数据库或内存支持服务器来处理会话状态。您可以使用ASP.NET内置的基于SQL Server的会话状态,并手动将其连接到PHP或使用自定义解决方案。

#3


I needed to this a while back for a fairly large project. The languages were ASP.Net and ASP, but the method I ended up with would work just as well if it were PHP instead of ASP.

我需要一段时间来做一个相当大的项目。这些语言是ASP.Net和ASP,但是如果它是PHP而不是ASP,那么我最终使用的方法也会起作用。

Can you abstract out the places your PHP application modifies session variables?

你可以抽象出PHP应用程序修改会话变量的位置吗?

I found that even for large web applications, there were only a handful of places session variables were updated. For instance; Login, Logout, some sought of change group action, etc. For me, there were less than 6 scripts that needed to be modified.

我发现即使对于大型Web应用程序,也只有少数几个地方会话变量被更新。例如;登录,注销,一些寻求更改组操作等。对我来说,需要修改的脚本少于6个。

For each script that modify session variables, add a server redirect to a new ASP.Net script. Hence the PHP script would do all it had to do and the final thing would be a PHP redirect ( mabye PHP Header("Location:...") call at the end.

对于修改会话变量的每个脚本,将服务器重定向添加到新的ASP.Net脚本。因此,PHP脚本将完成所有必须做的事情,最后的事情将是PHP重定向(最后的mabye PHP Header(“Location:...”)调用。

Your receiving ASP.Net script updates the ASP.Net session variables in the same manner the PHP script update its session. Luckily in my case the original scripts did not output any data, but rather redirected to "success" pages.

您接收的ASP.Net脚本以与PHP脚本更新其会话相同的方式更新ASP.Net会话变量。幸运的是,在我的情况下,原始脚本没有输出任何数据,而是重定向到“成功”页面。

i.e. The original scripts were the Controller code in a MVC design, and they redirected to the View code. This allowed me to neatly insert my ASP.Net scripts between the ASP controller and the view scripts. If your receiving script outputs data, then you will have to split that up into 2 pages.

即原始脚本是MVC设计中的Controller代码,并且它们重定向到View代码。这使我能够在ASP控制器和视图脚本之间整齐地插入我的ASP.Net脚本。如果您的接收脚本输出数据,那么您必须将其拆分为2页。

That's it. In effect, doing this for Login, Logout, and a few pages effectively caused the two session scopes to stay in sync.

而已。实际上,对Login,Logout和几个页面执行此操作有效地导致两个会话范围保持同步。