2

このコードを使用してSSRSからPDFレポートを作成およびダウンロードしていますが、次のエラーが発生します。

リモートサーバーがエラーを返しました:(401)許可されていません。

私のコードは次のとおりです。

protected void Page_Load(object sender, EventArgs e)
{
    MemoryStream ms;
    // this name is what the user will see when they are prompted for download.
    string customFileName = "NewFileName.pdf";

    if (!this.IsPostBack)
    {
        try
        {
            string strRequest = "http://myServer.com/ReportServer?%2fmetadata_report%2fMetadataReport1&rs%3aCommand=Render&rs%3AFormat=PDF&grpId=3";
            WebRequest request = WebRequest.Create(strRequest);
            request.ContentType = "application/pdf";

            string userName = "username";
            string password = "password";
            string domain = "myServer.com";

            // Create and then pass in network credentials to acecss the reporting server
            System.Net.NetworkCredential credentials = new NetworkCredential(userName, password, domain);
            request.Credentials = credentials;

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            using (response)
            {
                // Get the stream from the server
                using (Stream stream = response.GetResponseStream())
                {
                    // Use the ReadFully method from the link above:
                    byte[] data = ReadFully(stream, response.ContentLength);

                    // Return the memory stream.
                    ms = new MemoryStream(data);
                }
            }

            // Clear out the headers that may already exist, then set content type and add a header to name the file
            Response.Clear();
            Response.ContentType = "application/pdf";
            Response.AddHeader("content-disposition", "inline; ");

            //// Write the memory stream containing the pdf file directly to the Response object that gets sent to the client
            ms.WriteTo(Response.OutputStream);
        }
    }
}

どんな助けでも大歓迎です。

4

3 に答える 3

1

パーミッションの問題です。

これらを確認してください:

http://jhonatantirado.wordpress.com/2011/04/16/reporting-services-2008-asking-for-username-and-password/

http://forums.asp.net/p/1202398/2103516.aspx

Sql Report Server 2008 に資格情報を渡す

于 2012-09-13T22:13:28.363 に答える
1

これを試すことができますか?

// Create and then pass in network credentials to acecss the reporting server
CredentialCache cc = new CredentialCache();
cc.Add(new Uri("http://myServer.com/"), "Negotiate", new NetworkCredential("Username", "Password", "Domain"));
request.Credentials = cc;
于 2012-09-13T22:22:23.963 に答える