当前位置: 首页 > 面试题库 >

IIS中的CORS问题,使用Access-Control-Allow-Origin中的凭据和通配符

邓嘉致
2023-03-14
问题内容

我继承了一个相当基本的站点,该站点提供数据并处理一些套接字连接。它使用iisnode作为桥在IIS后面运行NodeJS。从“为正常页面提供”的角度来看,一切都很好。

问题的部分原因是,与服务器的实际连接来自桌面客户端,在桌面客户端中,内容是通过其他应用程序作为小工具加载的,还可能来自网络,移动设备等可能发生变化和变化的部分,例如-
客户端域数量未知。

我已经将Access-Control-Allow origin设置为*,只是打开了仓门,但现在在客户端出现以下错误:

11:29:57.668跨域请求被阻止:相同来源策略不允许读取位于’ http://server/socket.io/?EIO =
3&transport = polling&t =
1486150196479-0

‘ 的远程资源。(原因:如果CORS标头“ Access-Control-Allow-Origin”为“ *”,则不支持凭据)。1(未知)

我试图将Access-Control-Allow-
Credentials显式设置为false(以及true,并完全将其省略),但是我的尝试都没有让我克服这个问题。

当前,原始响应标头如下所示:

Access-Control-Allow-Credentials: false
Access-Control-Allow-Headers: Origin,Content-Type,Accept
Access-Control-Allow-Methods: GET,HEAD,PUT,POST,DELETE,OPTIONS
Access-Control-Allow-Origin: *
Cache-Control: no-cache
Content-Encoding: gzip
Content-Length: 969
Content-Type: text/html
Date: Fri, 03 Feb 2017 19:30:21 GMT
Server: Microsoft-IIS/8.5
Vary: Accept-Encoding
X-Powered-By: ASP.NET

在过去几天看了很多CORS网站和文章后,我似乎还是无法梳理一下,为什么它仍然抱怨凭证-更具体地说,我该如何解决?

谢谢!

更新2017-02-06

客户端代码并不十分令人兴奋。由于服务器是IIS之后的NodeJS,因此我要做的就是实现套接字连接:

var socket = io('http://' + currentServer, {path: '/broadcast/socket.io', reconnection: false, forceNew: true});
socket.on('update message', function (data) {
// do some fancy things
}

这在同一域内有效。

我还根据sideshowbarker的评论(使我引向本文)进行了一些进一步的挖掘。有一些额外的步骤来添加变量,还有一些其他的事情可以使该代码正常工作。

我的applicationHost.config当前包含以下部分:

<location path="Default Web Site">
    <system.webServer>
        <rewrite>
            <allowedServerVariables>
                <add name="CAPTURED_ORIGIN" />
                <add name="RESPONSE_Access-Control-Allow-Origin" />
            </allowedServerVariables>
        </rewrite>
    </system.webServer>
</location>

而我的web.config在这里:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
    <rewrite> 
        <rules>
            <rule name="Fail bad requests">
                <match url="." />
                <conditions>
                    <add input="{HTTP_HOST}" negate="true" pattern="localhost" />
                </conditions>
                <action type="AbortRequest" />
            </rule>
            <rule name="Capture Origin Header"> 
                <match url=".*" /> 
                <conditions> 
                    <add input="{HTTP_ORIGIN}" pattern=".+" /> 
                </conditions> 
                <serverVariables> 
                    <set name="CAPTURED_ORIGIN" value="{C:0}" /> 
                </serverVariables> 
                <action type="None" /> 
            </rule>
        </rules>
        <outboundRules> 
            <rule name="Set-Access-Control-Allow-Origin for known origins"> 
                <match serverVariable="RESPONSE_Access-Control-Allow-Origin" pattern=".+" negate="true" /> 
                <!--<action type="Rewrite" value="{C:0}" /> -->
            </rule> 
        </outboundRules> 
    </rewrite>
    <tracing>
        <traceFailedRequests>
            <add path="*">
                <traceAreas>
                    <add provider="ASP" verbosity="Verbose" />
                    <add provider="ASPNET" areas="Infrastructure,Module,Page,AppServices" verbosity="Verbose" />
                    <add provider="ISAPI Extension" verbosity="Verbose" />
                    <add provider="WWW Server" areas="Authentication,Security,Filter,StaticFile,CGI,Compression,Cache,RequestNotifications,Module,FastCGI,WebSocket" verbosity="Verbose" />
                </traceAreas>
                <failureDefinitions statusCodes="400-599" />
            </add>
        </traceFailedRequests>
    </tracing>
</system.webServer>
</configuration>

在outboundRules上,我当前已将操作type =“ Rewrite”行注释掉,因为当我启用它时,它将引发错误。

HTTP Error 500.52 - URL Rewrite Module Error.

The page cannot be displayed because an internal server error has occurred.

Most likely causes:
•IIS received the request; however, an internal error occurred during the processing of the request. The root cause of this error depends on which module handles the request and what was happening in the worker process when this error occurred.
•IIS was not able to access the web.config file for the Web site or application. This can occur if the NTFS permissions are set incorrectly.
•IIS was not able to process configuration for the Web site or application.
•The authenticated user does not have permission to use this DLL.
•The request is mapped to a managed handler but the .NET Extensibility Feature is not installed.

Detailed Error Information:
Module: RewriteModule 
Notification: SendResponse 
Handler: StaticFile 
Error Code: 0x80070585

Requested URL: http://localhost:80/iisstart.htm 
Physical Path: C:\inetpub\wwwroot\iisstart.htm 
Logon Method: Anonymous 
Logon User: Anonymous 
Request Tracing Directory: C:\inetpub\logs\FailedReqLogFiles

“失败的请求日志”并不太有用,它们显示以下警告信息:

411.  -MODULE_SET_RESPONSE_ERROR_STATUS 
ModuleName: RewriteModule 
Notification: SEND_RESPONSE 
HttpStatus: 500 
HttpReason: URL Rewrite Module Error. 
HttpSubStatus: 52 
ErrorCode: Invalid index. (0x80070585) 
ConfigExceptionInfo:

问题答案:

只是为了结束循环。关于此问题,以上发布的答案和建议对于仅IIS的网站来说效果很好。

我的问题是IIS-Node库中的某个错误,最终导致我不得不将整个堆栈迁移到NodeJS,并直接在Node中直接运行所有模块。



 类似资料:
  • XMLHttpRequest无法加载http://localhost:8080/nobelgrid/api/users/create/。请求的资源上没有“访问-控制-允许-来源”标头。因此,不允许访问源'http://localhost:63342'。响应的HTTP状态代码为500。 谁能帮帮我吗? 更新: 但我还有一个错误。我会做另一个问题,因为我认为这是一个不同的论点。 提前感谢!

  • 问题内容: 我有一个涉及的设置 前端服务器(Node.js,域:localhost:3000)<—>后端(Django,Ajax,域:localhost:8000) 浏览器<-webapp <-Node.js(为应用提供服务) 浏览器(webapp)-> Ajax-> Django(服务ajax POST请求) 现在,我的问题是CORS设置,Web应用程序使用它来对后端服务器进行Ajax调用。在C

  • Access-Control-Allow-Origin响应 header 指示是否该响应可以与具有给定资源共享原点。 Header type Response header Forbidden header name no 语法 Access-Control-Allow-Origin: *Access-Control-Allow-Origin: <origin> 指令 * 对于没有凭据的请求,服务

  • 我得到了低于误差。有没有人可以帮助我如何在spring boot和spring Security中配置cors。在AngularJS中有没有任何事情我必须从UI端做。 加载http://localhost:8080/springgeolocation/login失败:请求的资源上没有“access-control-allow-origin”标头。因此,不允许访问源“http://localhost

  • Response.AddHeader(“Access-Control-Allow-Origin”,“*”)是如何实现的;行设置多个标题时,包括,但没有当我删除它?

  • 我从ASP.NET表单中调用这个函数,在调用Ajax时在firebug控制台中得到以下错误。 跨源请求被阻止:同一源策略不允许读取http://anotherdomain/test.json上的远程资源。(原因:CORS标头“Access-Control-Allow-Origin”丢失)。 我做了其他的方法,但仍然找不到解决办法。 注意:我没有服务器权限进行服务器端(API/URL)更改。