当前,我有提供SSE服务的程序,并且必须在IIS上进行部署。但是它不能正常工作, 这是我在没有IIS的情况下运行.exe的结果。
data: Hello, world
但是,当它在IIS中运行时,浏览器被卡住了。
我必须刷新事件Hello, world
数千次才能使IIS刷新结果发送到浏览器,并且它立即刷新,而不是像SSE那样进行增量更新。
这是我的web.config
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="httpplatformhandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
</handlers>
<httpPlatform processPath=".\sse_server.exe"
arguments="-port=%HTTP_PLATFORM_PORT% -environment development"
stdoutLogEnabled="false"
requestTimeout="00:05:00"
stdoutLogFile=".\sse_server_log">
</httpPlatform>
<urlCompression doStaticCompression="true" doDynamicCompression="false" />
<caching enabled="false" enableKernelCache="false" />
</system.webServer>
</configuration>
这是我的go
代码
func SSEHello(rw http.ResponseWriter, flusher http.Flusher) {
rw.Header().Set("Content-Type", "text/event-stream; charset=utf-8")
rw.Header().Set("Cache-Control", "no-cache")
rw.Header().Set("Connection", "keep-alive")
rw.WriteHeader(http.StatusOK)
for i := 0; i < 1000; i++ {
rw.Write([]byte("data:Hello, world\n\n"))
flusher.Flush()
time.Sleep(time.Millisecond * 100)
}
}
答案 0 :(得分:0)
实际上HttpPlatformHandler具有8kb output buffer,因此我的消息不会立即发送出去。
我必须更改HttpPlatformHandler to ASP.NET Core Module,
因此class Class1
{
FirefoxDriver d;
static void Main(string[] args)
{
d = new FirefoxDriver();
d.Manage().Window.Maximize();
d.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(60);
d.Url = "www.example.com";
Process.Start(@"C:\Users\Documents\AutoIt Scripts\Authentication_FireFox.exe");
//Now I would like to click on an element on my homepage which I am not able to do bcos of some exceptions.
WebDriverWait wait = new WebDriverWait(d, TimeSpan.FromSeconds(30));
wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable(d.FindElement(By.XPath("//span[@title='Start search']"))));
d.FindElement(By.XPath("//span[@title='Start search']")).Click();
}
必须对此进行更新。
web.config
要在 <?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath=".\sse_server.exe" />
</system.webServer>
</configuration>
上以go
的身份启动aspNetCore
的应用程序,该应用程序需要获取环境变量名称iis
,然后在该端口上启动http服务。
ASPNETCORE_PORT
仅此而已!