- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我继承了一个相当基本的站点,该站点提供数据并处理一些套接字连接。它使用 iisnode 作为桥梁在 IIS 后面运行 NodeJS。从“提供正常页面”的角度来看,这一切都很好。
部分问题在于,与服务器的实际连接来自桌面客户端,其中内容作为小工具通过不同的应用程序加载,并且来自网络、移动设备等可能发生变化和变化的部分。即 - 未知数量的客户端域。
我已经将 Access-Control-Allow origin 设置为 * 以打开谷仓门,但现在客户端出现以下错误:
11:29:57.668 Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at ‘http://server/socket.io/?EIO=3&transport=polling&t=1486150196479-0’. (Reason: Credential is not supported if the CORS header ‘Access-Control-Allow-Origin’ is ‘*’). 1 (unknown)
我曾尝试将 Access-Control-Allow-Credentials 显式设置为 false(以及 true,以及完全忽略它),但我的所有尝试都无法解决这个问题。
当前原始响应 header 如下所示:
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 的评论进行了更多挖掘,这些评论让我想到了这个 article有一些额外的步骤来添加变量,还有一些其他的东西来让那部分工作。
我的 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 上,我目前将 action 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:
最佳答案
问题没有显示发送导致该错误的请求的客户端代码,但是:
客户端代码必须使用 XHR 或 Fetch API (或使用 jQuery 或调用其中之一的其他库),并且该代码正在设置 XHR withCredentials属性为 true
或正在调用 Fetch Request constructor使用将 credentials
选项设置为 include
的选项对象。
如果是这种情况并且服务器响应具有 Access-Control-Allow-Origin: *
header ,您的浏览器将记录问题中引用的错误。
因此,一种解决方案是更改 JavaScript 客户端代码,使其不将 XHR withCredentials
设置为 true
并且不使用 credentials: 'include 调用 Fetch Request 构造函数'
.
另一种解决方案是让您的服务器端代码采用 Origin
请求 header 值并将其回显到 Access-Control-Allow-Origin
响应 header 值.
对于 IIS,您可以使用 URL Rewrite Module通过将以下内容添加到您的 IIS 配置文件(%SystemDrive%\inetpub\wwwroot\
中的 Web.config
或 ApplicationHost.config
文件)。
<configuration>
<system.webServer>
<rewrite>
<rules>
<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="{CAPTURED_ORIGIN}" />
</rule>
</outboundRules>
</rewrite>
</system.webServer>
</configuration>
然后删除任何其他现有代码/配置正在设置 Access-Control-Allow-Origin: *
。
注意:以上是分步指南中示例配置文件的修改版本 Enable CORS for specific domains in IIS using URL Rewrite .
关于node.js - IIS 中的 CORS 问题与 Access-Control-Allow-Origin 中的凭据和通配符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42031885/
当我查看 IIS 日志文件时,我可以在一天中的不同时间看到标题行被写入日志文件。我唯一一次看到这种情况发生是在 IIS 重置时;或启动。 例如下面的标题行; #Software: Microsoft
有谁知道为什么以下 web.conig 更改不起作用: 在我添加 javascript 文件后仍然没有被压缩(gzip)。我折腾了几天,因为一开始我真的不知道问题是
目前,我们所有的网络应用程序都将其应用程序池标识设置为 ApplicationPoolIdentity。现在,当一个应用程序需要访问某些服务器上的某些资源时,比如添加/读取某些文件,该应用程序会在代码
在 IIS(特别是 6.0)中,在“主目录”选项卡下,如果我更改本地路径,是否会导致 IIS 重新启动或应用程序池回收? 相关的,是否有概述 IIS 元数据库的哪些更改将触发重新启动或应用程序池回收的
只要更改了任何 web.config 文件,AFAIK IIS 就会重新启动。 我创建了自己的配置文件(my.config,层次结构略有不同)。是否有可能让 IIS 自动(自动神奇地 :))重新启动,
你好, 我正在寻找 IIS 日志中列出的浏览器条目列表,以帮助识别访问我们网站的不同版本的浏览器。也许没有一个列表,而是一个应该用来识别不同浏览器及其版本的算法。 请注意,我不是在寻找日志分析器,而是
我想知道上次重新启动 iis 是什么时候。 IIS 是否保留了此日志,我在哪里可以找到此日志? 谢谢 最佳答案 打开事件查看器,导航到“Windows 日志”->“系统” 在右侧的“操作” Pane
在全新安装的带有 IIS 7 的 Windows Server 2008 R2 上,它会在 C:\inetpub\wwwroot 中创建一个默认网站。 .我确信对于存储网站文件的好位置有很多主观意见,
我已按照 this question 中的说明在 IIS 中实现动态内容压缩。 . 当我发送请求时,我看不到响应被 gzip 压缩的任何证据: IIS版本为7.5 有什么明显的我应该检查以解决此问题吗
这是场景: 服务器 A 托管“主”应用程序 (www.example.com) 服务器 B 托管支持应用程序 (b.example.com) 它们通过 192.* 地址在内部相互连接,并且都可以通过
是否有任何替代 IIS 管理 UI 可用于从程序重置 IIS?.. 现在我们已经创建了一个批处理文件,如果 iis 重置并每小时安排一次...... 我只是想要一些东西,这样我们就不能重置 iis..
我的 Windows Server 在 IIS 7.5 上运行 Web 应用程序。 我想知道为什么 IIS 应用程序池使用大量内存。 请参阅我从服务器捕获的屏幕截图。 在名为 TEST 2.0(.NE
我在 IIS 7.5 上运行的 ASP Classic 站点上收到服务器错误。 我将“向浏览器发送错误”设置为 True ,但是我仍然收到以下错误屏幕: 最佳答案 IIS 正在劫持您的经典 ASP 应
我正在尝试通过IIS上的反向代理连接到websockets服务器(websockify)。 IIS和Websockets服务器位于同一台物理服务器上(Windows Server 2012 R2,II
我需要让我的开发机器从本地机器商店读取证书 为此,我需要运行winhttpcertcfg.exe并指定我要提升的帐户 该帐户用于IIS表示什么? (对于IIS,它将是IWAM_MachineName)
我正在阅读特定命令(SET-WEBCONFIGURATIONPROPERTY),但出现"is not recognized as a cmdlet"错误。给我的建议是,即使我使用的是SharePoin
我已经为 IIS8 安装了静态和动态压缩并启用了它。 当我的CPU性能100%时,我的GZIP IIS不工作,为什么? 我可以清楚地看到 GZIP 没有在 Live HTTP header 中运行。我
我已经从官方镜像(https://hub.docker.com/r/microsoft/iis/)运行了IIS 在Windows Server 2016上 有什么方法可以从IIS管理器连接到该IIS,
你好, 如果 iis 未运行,我想编写一个状态为的代码。 最佳答案 从命令行启动 IIS: iisreset /start 从命令行停止 IIS: iisreset /stop 重新启动(停止和启动)
我已经为 IIS8 安装了静态和动态压缩并启用了它。 当我的CPU性能100%时,我的GZIP IIS不工作,为什么? 我可以清楚地看到 GZIP 没有在 Live HTTP header 中运行。我
我是一名优秀的程序员,十分优秀!