2

I am in NTLM hell here, hope you can help indentify what I am missing.

I am ultimately trying to deliver SSRS reports to a frame in a browser, and only the images within the reports are giving me much grief. They don't appear unless the user has Firefox and enters their credentials 2 times, first for the report, then a second time for the images in the report.

I am using HttpWebRequest to obtain the SSRS reports.

I am sending the webserver (IIS 7.5) a credential cache with "NTLM" and valid credentials to try and obtain an images from SSRS after I receive the HTML stream so that I can store them locally and refer to those, which would alleviate the users from having to re-enter credentials again and again.

I see in Fiddler that Type 1, 2 and 3 challenges are properly met during the NTLM hand shaking, however, the final response is 500 internal service error. The response text also indicates rsStreamNotFound, however, I find next to no info on what that means and I think it's misleading as to what the real problem may be.

When I use Firefox, Firefox prompts me for my network credentials for the report and then again for the images, and it gets through bringing the images back. My HttpWebRequest fails with 500 Internal Server Error, and rsStreamNotFound.

The only difference I can see in the request headers between Firefox requests and my requests is that the "keep-alive" property gets dropped from my programmatic request, and the Firefox requests have it in there.

Why do my "keep-alive" get dropped?

At this point, that is the only difference between my request and the request from Firefox, so I would like to eliminate that difference before jumping to any other conclusion.

I tried variations of:

req.KeepAlive = true;
req.PreAuthenticate = true;

and this gem:

var sp = req.ServicePoint;
var prop = sp.GetType().GetProperty( "HttpBehaviour", BindingFlags.Instance | BindingFlags.NonPublic );
prop.SetValue( sp, (byte)0, null );

Here is the CredentialCache:

CredentialCache credentialCache = new CredentialCache();
credentialCache.Add( new Uri( path ), "NTLM", NetCredentials );

... and "keep-alive" is not present in the request for my HttpWebRequest, and Firefox has it - why does mine get dropped?

Update:

I tried:

using (WebClient client = new WebClient()) {
     client.DownloadFile(url, filePath);
}

...and I got 401 Unauthorized, so I tried with credentials and get 500 Internal Server Error

4

1 回答 1

0

从您的问题中不清楚您在哪里运行代码。它是否作为可执行文件在桌面上运行?还是它作为某种activex控件或类似的东西在firefox中运行?

无论如何,我建议使用 .net tracelog 工具来获取您的事务日志,并查看日志文件。

<?xml version="1.0" encoding="UTF-8" ?>

    <configuration>
    <system.diagnostics>
    <trace autoflush="true" />

    <sources>
    <source name="System.Net">

    <listeners>
        <add name="System.Net"/>
    </listeners>
    </source>
    <source name="System.Net.Sockets">
    <listeners>
        <add name="System.Net"/>
    </listeners>
    </source>
    <source name="System.Net.Cache">
    <listeners>
        <add name="System.Net"/>
    </listeners>
    </source>
    </sources>
    <sharedListeners>
        <add
            name="System.Net"
            type="System.Diagnostics.TextWriterTraceListener"
            initializeData="System.Net.trace.log"
        />
    </sharedListeners>
    <switches>
        <add name="System.Net" value="Verbose" />
        <add name="System.Net.Sockets" value="Verbose" />               
        <add name="System.Net.Cache" value="Verbose" />
    </switches>
</system.diagnostics>
</configuration>

如果你的应用名称是app.exe,在exe所在目录下创建一个名为app.exe.config的文件,将上述内容放入其中。然后运行应用程序,应该会创建一个日志文件。

如果您遇到问题,此链接应包含有关获取日志文件的更多信息。

创建 system.net 跟踪日志

删除主机名、IP 地址等个人信息后,您可以将日志文件放在 pastebin 上。

另外,请给我们一段重现问题的代码。然后会更容易提供帮助。

于 2015-02-27T00:39:03.243 回答