سؤال

لدي تقرير محفوظ على خادم تقارير SQL2005، وأريد إرجاع ملف PDF معروض لهذا التقرير.لقد اكتشفت ذلك عند العمل مع ملف *.rdlc محلي (ولقد قمت بالتدوين حول هذا الموضوع)، ولكن ليس عندما يكون *.rdl موجودًا على خادم التقارير.أنا أحصل على 401 غير مصرح به خطأ في السطر...

reportViewer.ServerReport.SetParameters(reportDefinition.ReportParameters);

وإليك الطريقة المستخدمة لتقديم التقرير.

public byte[] Render(IReportDefinition reportDefinition)
{
    var reportViewer = new ReportViewer();
    byte[] renderedReport;
    try
    {
        var credentials = new WindowsImpersonationCredentials();
        reportViewer.ServerReport.ReportServerUrl = new Uri("http://myssrsbox", UrlKind.Absolute);
        reportViewer.ServerReport.ReportServerCredentials = credentials;
        reportViewer.ServerReport.ReportPath = reportDefinition.Path;
        // Exception is thrown on the following line...
        reportViewer.ServerReport.SetParameters(reportDefinition.ReportParameters);

        string mimeType;
        string encoding;
        string filenameExtension;
        string[] streams;
        Warning[] warnings;

        renderedReport = reportViewer.ServerReport.Render(reportDefinition.OutputType, reportDefinition.DeviceInfo, out mimeType, out encoding, out filenameExtension, out streams, out warnings);
    }
    catch (Exception ex)
    {
        // log the error...
        throw;
    }
    finally
    {
        reportViewer.Dispose();
    }
    return renderedReport;
}

الشيء الآخر الذي تفتقده هو فئة WindowsImpersonationCredentials.

public class WindowsImpersonationCredentials : IReportServerCredentials
{
    public bool GetFormsCredentials(out Cookie authCookie, out string userName, out string password, out string authority)
    {
        authCookie = null;
        userName = password = authority = null;
        return false;
    }

    public WindowsIdentity ImpersonationUser
    {
        get { return WindowsIdentity.GetCurrent(); }
    }

    public ICredentials NetworkCredentials
    {
        get { return null; }
    }

    public override string ToString()
    {
        return String.Format("WindowsIdentity: {0} ({1})", this.ImpersonationUser.Name, this.ImpersonationUser.User.Value);
    }
}

أشياء أخرى قد تحتاج إلى معرفتها...

  • يتم تشغيل هذا على إنترانت، ويتم تشغيل الانتحال.
  • يشير التسجيل إلى أنه تم تعيين مستخدم الانتحال بشكل صحيح.
  • هذا تعمل عند التشغيل في Visual Studio (http://localhost:devport)، وعليه تعمل عند التشغيل على صندوق التطوير الخاص بي (http://localhost/myApplication).هو - هي لا يعمل عند التشغيل على خوادم الاختبار أو الإنتاج لدينا.
  • لقد قمت بتجربة الحلول مع وبدون إعدادات system.net.defaultProxy في web.config.لا يعمل.

ما الخطأ الذي افعله؟هل هو إعداد الخادم؟هل هو رمز؟هل هو web.config؟

هل كانت مفيدة؟

المحلول

لقد اكتشفنا المشكلة أخيرًا.لقد قام مسؤولو الشبكة لدينا بتعطيل التنقل المزدوج، لذا بينما كان انتحال الهوية متصلاً بشكل صحيح domain\jmeyer, ، كان التطبيق لا يزال يحاول الاتصال بمربع SRS باستخدام domain\web01$.لماذا تم إعداده هكذا؟لأن التنقل المزدوج يمثل ثغرة أمنية هائلة.(أو هكذا قيل لي.هل يبدو هذا وكأنه شيء ستقرأه ديلي وتف?)

كان حلنا هو إنشاء عام domain\ssrs_report_services المستخدم، والتواصل مع هذا المستخدم باستخدام بيانات اعتماد الشبكة التالية

public class CustomCredentials : IReportServerCredentials
{
    public bool GetFormsCredentials(out Cookie authCookie, out string userName, out string password, out string authority)
    {
        authCookie = null;
        userName = password = authority = null;
        return false;
    }

    public WindowsIdentity ImpersonationUser
    {
        get { return null; }
    }

    public ICredentials NetworkCredentials
    {
        get { return new NetworkCredential("ssrs_report_services", "password", "domain") ; }
    }    
}

ما ورد أعلاه هو الحل النموذجي الكلاسيكي الذي يمكنك العثور عليه في جميع أنحاء شبكات الإنترنت.

نصائح أخرى

يُسمح بـ "التنقل المزدوج" - مع مصادقة Kerberos ...(طالما أنه يعمل بشكل صحيح!)

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top