简体   繁体   English

在两个应用程序间共享ASP.NET身份验

[英]Sharing ASP.NET Authentication between two applications

I have two web applications ASP.NET running on the same web server IIS 7.5/.NET 4.0. 我有两个Web应用程序ASP.NET在同一个Web服务器IIS 7.5 / .NET 4.0上运行。 The first app makes async calls through jquery to the second app, which acts as web service backend (connected to a database server). 第一个应用程序通过jquery对第二个应用程序进行异步调用,第二个应用程序充当Web服务后端(连接到数据库服务器)。 The two applications will be installed in intranet context, so I want to use integrated "Windows Authentication". 这两个应用程序将安装在Intranet上下文中,因此我想使用集成的“Windows身份验证”。

In both Web.config I have: 在两个Web.config中我都有:

<authentication mode="Windows" />

<authorization>
    <deny users="?" />
</authorization>

<identity impersonate="true" />

If I open a browser and I access a test page it's ok on both web apps: the browser asks for a user/password pair and IIS allows the page to be downloaded. 如果我打开浏览器并访问测试页面,则两个Web应用程序都可以:浏览器要求用户/密码对,IIS允许下载页面。 But if I access a test page of the first web app, which makes an async request to a web service installed on the second app, a 401 error code is returned. 但是,如果我访问第一个Web应用程序的测试页面,该测试页面会对第二个应用程序上安装的Web服务发出异步请求,则会返回401错误代码。 So it seems that the authentication is lost between the two applications. 因此,似乎两个应用程序之间的身份验证丢失了。

I tried also machineKey but nothing... 我也试过machineKey但没什么......

Any idea ? 任何想法 ?

Any help is appreciated, thanks in advance. 任何帮助表示赞赏,提前谢谢。

Alex 亚历克斯

You are probably trying to make an async request to a different domain, which isn't allowed . 您可能正在尝试向其他域发出异步请求,这是不允许的

You can get around this by creating a "proxy" call to the web service. 您可以通过创建对Web服务的“代理”调用来解决此问题。 You make the async call to your local asp.net application, which makes the call to the web service on your behalf. 您对本地asp.net应用程序进行异步调用,该应用程序代表您调用Web服务。 This avoids the same origin policy restriction discussed in the link above. 这避免了上面链接中讨论的相同的原始策略限制。

Another option, since you have control of the application on both ends, would be to look at JSONP . 另一个选择,因为您可以控制两端的应用程序,就是查看JSONP I don't have a lot of experience with it, but I have seen it used for making async calls across domains. 我没有很多使用它的经验,但我已经看到它用于跨域进行异步调用。

Good luck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM