1

我在受 Extranet 安全性(基于 ASP.Net Membership)保护的页面上使用 Winnovatives PDFConverter 时遇到问题。

我尝试了几种不同的方法,但以下我可以在我的本地机器上工作,但不能在其他任何地方工作。

登录页面的代码,此代码应绕过登录过程:

 // check that the current "user" isn't logged in and is the Winnovative UserAgent
 if (!Sitecore.Context.IsLoggedIn && Request.UserAgent.Contains(".NET CLR"))
        {
            //Login with a dummy user I've created
            Sitecore.Security.Authentication.AuthenticationManager.Login("extranet\\pdf", "pdf", true);
            //redirect to former page
        }

生成 PDF 的页面使用以下代码: private void PDFPrint(string url) {

        PdfConverter pdfConverter = new PdfConverter();           

        pdfConverter.LicenseKey = "our license";            

        url = Request.Url.Scheme + "://" + Request.Url.Host + url;
        byte[] downloadBytes = pdfConverter.GetPdfFromUrlBytes(url);

        HttpResponse response = HttpContext.Current.Response;
        response.Clear();
        response.AddHeader("Content-Type", "binary/octet-stream");
        response.AddHeader("Content-Disposition", "attachment; filename=" + Sitecore.Context.Item.Name + ".pdf" + "; size=" + downloadBytes.Length.ToString());
        response.Flush();
        response.BinaryWrite(downloadBytes);
        response.Flush();
        response.End();
    }

我得到的例外是:

“无法从 url 获取元文件。无法从 url 获取图像。无法访问 URL ..”

我也尝试过 Winnovative 常见问题解答中的这个技巧,但无济于事: http: //www.winnovative-software.com/FAQ.aspx#authenticationQ

我还尝试使用 WebClient 或 HttpWebRequest 来检索内容。

但我所做的似乎除了在本地工作之外没有任何作用。

基本上,我想创建一种让 Winnovatives 转换器使用当前登录用户的方法,我的自定义“pdf”用户以及从响应中获取 html 的其他方式。

我希望这个问题不会太模糊,但我觉得很难问。但基本上我想从我控制的 Sitecore 解决方案的页面中获取一些 html 内容,该解决方案受 Sitecore 正常的外联网安全保护。此 html 内容应为字符串或字节 [] 格式。

帮帮我 Stackoverflowers,你是我唯一的希望!:P

4

2 回答 2

2

我联系了 Sitecore 询问他们是否有解决方案。

他们的解决方案是创建一个处理器,该处理器将根据某些标准设置活跃用户。

这是我为我的网站制作的代码(它可能不是最好的解决方案,因为 UserAgent 可以被欺骗):

public class MyResolver : HttpRequestProcessor
    {
        // Methods
        public override void Process(HttpRequestArgs args)
        {

            var userAgent = args.Context.Request.UserAgent ?? "";
            SiteContext site = Sitecore.Context.Site;
            if (site.Name == "site_name_in_webconfig" && userAgent.Contains("this_should_only_be_in_thepdfcreators_userAgent"))
            {
                Sitecore.Security.Accounts.User pdfuser = Sitecore.Security.Accounts.User.FromName("extranet\\theUser", true);
                AuthenticationManager.SetActiveUser(pdfuser);
            }

        }
    }

然后将以下内容添加到 web.config,在 UserResolver 之前:

<processor type="Namespace.MyResolver, Assembly" />

我希望这会帮助其他一些人。

于 2011-06-09T10:13:56.243 回答
1

我在 ASP.NET 论坛上发现了一个类似的问题,答案是使用更新版本的 PDF 工具:SessionState Problems ?

于 2011-06-03T16:03:42.820 回答