首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Sitecore Extranet登录和PDF转换器或Webclient

Sitecore Extranet登录和PDF转换器或Webclient
EN

Stack Overflow用户
提问于 2011-06-03 20:33:41
回答 2查看 1.2K关注 0票数 1

我在受外联网安全(基于ASP.Net成员资格)保护的页面上使用Winnovatives时遇到了问题。

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

登录页面的代码,此代码应绕过以下内容的登录过程:

代码语言:javascript
复制
 // 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) {

代码语言:javascript
复制
        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.The获取图像URL不可访问。”

我也尝试了Winnovative常见问题解答中的这个技巧,但没有效果:http://www.winnovative-software.com/FAQ.aspx#authenticationQ

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

但我所做的一切似乎都是在本地进行的。

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

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

帮我,你是我唯一的希望!

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-06-09 18:13:56

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

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

这是我为我的站点编写的代码(这可能不是最好的解决方案,因为UserAgent可能会被欺骗):

代码语言:javascript
复制
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);
            }

        }
    }

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

代码语言:javascript
复制
<processor type="Namespace.MyResolver, Assembly" />

我希望这会对其他人有所帮助。

票数 2
EN

Stack Overflow用户

发布于 2011-06-04 00:03:43

我在ASP.NET论坛上发现了一个类似的问题,解决方法是使用更新版本的SessionState Problems ?

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6227141

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档