HttpCookie.SameSite和FormsAuthentication。在IFrame中进行身份验证

时间:2020-04-23 11:44:02

标签: c# asp.net iis session-cookies forms-authentication

我正试图通过IFrame从另一个网站(abc.com)访问我的网站(example.com)

在IFrame中的abc.com网站上,他们正在按如下方式调用我的页面:

<iframe src="https://example.com/MyPageIframe.aspx?tokenid=12345678-1234-abcd-9d78-a3f9a5fb3d8d" frameborder="0" width="100%" height="850px"></iframe>

请求到达MyPageIframe.aspx页面后,我将验证令牌ID,然后以编程方式登录到系统,如下所示:

 bool IsAuthenticated= FormsAuthentication.Authenticate(userName, password);
 ErrorHandler.Singleton().logInforDetail("FormsAuthentication Status: "+ IsAuthenticated);
 FormsAuthentication.SetAuthCookie(userName,false); 

直到最近,这种方法都运行良好。我们已经更改了托管服务器,并且它具有新的Windows更新。 现在

FormsAuthentication.Authenticate(userName, password);

不起作用,它返回false。

我们正在使用.Net 4.5框架。

调试时,我发现相同站点被标记为松驰

Data

然后我尝试将 SameSite = None 设置为向FormsAuthentication.Authenticate()发送请求之前,如下所示:

if (HttpContext.Current.Response.Cookies["ASP.NET_SessionId"] != null)
{
       ErrorHandler.Singleton().logInforDetail("Cookie ASP.NET_SessionId");
       HttpContext.Current.Response.Cookies["ASP.NET_SessionId"].Path = "/; SameSite=None";              
}

if (HttpContext.Current.Response.Cookies[".ASPXAUTH"] != null)
{
       ErrorHandler.Singleton().logInforDetail("Cookie .ASPXAUTH");
       HttpContext.Current.Response.Cookies[".ASPXAUTH"].Path = "/; SameSite=None";
}

但是我仍然面临着同样的问题。在这里需要做什么?还是这是由于其他原因造成的?

编辑:

在web.config中,我启用了CORS

<httpProtocol>
    <customHeaders>
        <add name="Access-Control-Allow-Origin" value="*" />
        <add name="Access-Control-Allow-Headers" value="Origin, X-Requested-With, Content-Type, Accept" />
    </customHeaders>
</httpProtocol>

0 个答案:

没有答案