如何在winnovative中传递cookie

时间:2015-01-02 19:15:33

标签: cookies winnovative

首先,我想祝大家2015年快乐,为大家繁荣昌盛。 我想帮助我解决一个问题,我有一个cookie和Winnovative,问题是我正确的cookie中的数据,但当dll的过程到达获取数据到cookie的窗口时,白色没有数据。不是那时我做错了。 Confinued的附件代码:

            string apo = String.Empty;
            apo = Request.Cookies["dApoderados"].Value;
            HttpCookie datosApoderados = new HttpCookie("datosApoderados");

            string cadenaPDF = String.Empty;
            string ruta = String.Empty;
            ruta = ObtenerDireccionInformeSalida();
            ruta = ruta.Replace("../", "");
            GenerarQueryString();

            Response.Cookies["datosApoderados"].Value = apo;
            ruta = "http://localhost:10458/" + ruta;

            byte[] bytes = ObtenerPdfBytes(ruta);

那时我想处理,然后通过一个中间产品:

 public byte[] ObtenerPdfBytes(string ruta)
    {
        string datosClientes = Request.Cookies["datosCliente"].Value;
        string datosApoderados = Request.Cookies["datosApoderados"].Value;
        datosClientes = "?DATOS=" + datosClientes;

        ruta = ruta + datosClientes;

        PdfConverter pdfConverter = new PdfConverter();

        HttpCookie prueba = new HttpCookie("prueba");
        Response.Cookies["prueba"].Value = datosApoderados;

        if (Context.Request.Cookies[FormsAuthentication.FormsCookieName] != null)
        {
            pdfConverter.HttpRequestHeaders = String.Format("prueba : {0}={1}",
            FormsAuthentication.FormsCookieName, Request.Cookies[FormsAuthentication.FormsCookieName].Value);
        }

        pdfConverter.LicenseKey = ClaveGeneradorPdf;
        pdfConverter.PdfDocumentOptions.ShowFooter = true;

        pdfConverter.PdfFooterOptions.PageNumberText = TextoPagina;
        pdfConverter.PdfFooterOptions.PageNumberTextFontType = PdfFontType.HelveticaBold;
        pdfConverter.PdfFooterOptions.PageNumberTextFontSize = 8;
        pdfConverter.PdfFooterOptions.ShowPageNumber = true;
        pdfConverter.PdfDocumentOptions.PdfPageSize = PdfPageSize.Legal;
        pdfConverter.PdfFooterOptions.FooterHeight = AltoPie;
        pdfConverter.PdfDocumentOptions.LeftMargin = MargenIzquierdo;
        pdfConverter.PdfDocumentOptions.RightMargin = MargenDerecho;
        pdfConverter.PdfDocumentOptions.TopMargin = MargenSuperior;
        pdfConverter.PdfDocumentOptions.BottomMargin = MargenInferior;
        pdfConverter.PdfDocumentOptions.PdfPageOrientation = PDFPageOrientation.Portrait;
        pdfConverter.PdfFooterOptions.FooterText = "texto";
        pdfConverter.PdfFooterOptions.FooterTextFontType = PdfFontType.HelveticaBold;
        pdfConverter.PdfFooterOptions.FooterTextFontSize = 8;
        pdfConverter.PdfDocumentOptions.ShowHeader = false;

        byte[] pdfBytes = pdfConverter.GetPdfBytesFromUrl(ruta);
        return pdfBytes;
    }

当我到达下一行时,cookie丢失的地方:   byte [] pdfBytes = pdfConverter.GetPdfBytesFromUrl(path);

public override void Pagina_PrimeraCarga(object sender, EventArgs e)
    {
        string prueba = Request.Cookies["prueba"].Value;
        string datosRequest = Request.QueryString["DATOS"];
        char delimitadores = ';';
        string[] datos = datosRequest.Split(delimitadores);

        imgBanco.Attributes.Add("ImageUrl", "~/App_Themes/Imagenes/Logo.gif");
        DateTime fechaHoy = DateTime.Now;
        lblDia.Text = Convert.ToString(fechaHoy.Day);
        lblMes.Text = Convert.ToString(fechaHoy.Month);
        lblAno.Text = Convert.ToString(fechaHoy.Year);

在后一段代码中从cookie加载数据: string test = Request.Cookies [“test”] Value。; 这是空的,没有数据

1 个答案:

答案 0 :(得分:0)

转换器有一个可以使用的HttpRequestCookies集合。 Winnovative网站上有a complete example for cookies。以下是从那里复制的相关代码:

// Create a HTML to PDF converter object with default settings
HtmlToPdfConverter htmlToPdfConverter = new HtmlToPdfConverter();

// Set license key received after purchase to use the converter in licensed mode
// Leave it not set to use the converter in demo mode
htmlToPdfConverter.LicenseKey = "fvDh8eDx4fHg4P/h8eLg/+Dj/+jo6Og=";

// Add custom HTTP cookies

if (cookie1NameTextBox.Text.Length > 0 && cookie1ValueTextBox.Text.Length > 0)
    htmlToPdfConverter.HttpRequestCookies.Add(cookie1NameTextBox.Text, cookie1ValueTextBox.Text);

if (cookie2NameTextBox.Text.Length > 0 && cookie2ValueTextBox.Text.Length > 0)
    htmlToPdfConverter.HttpRequestCookies.Add(cookie2NameTextBox.Text, cookie2ValueTextBox.Text);

if (cookie3NameTextBox.Text.Length > 0 && cookie3ValueTextBox.Text.Length > 0)
    htmlToPdfConverter.HttpRequestCookies.Add(cookie3NameTextBox.Text, cookie3ValueTextBox.Text);

if (cookie4NameTextBox.Text.Length > 0 && cookie4ValueTextBox.Text.Length > 0)
    htmlToPdfConverter.HttpRequestCookies.Add(cookie4NameTextBox.Text, cookie4ValueTextBox.Text);

if (cookie5NameTextBox.Text.Length > 0 && cookie5ValueTextBox.Text.Length > 0)
    htmlToPdfConverter.HttpRequestCookies.Add(cookie5NameTextBox.Text, cookie5ValueTextBox.Text);

// Convert the HTML page to a PDF document in a memory buffer
byte[] outPdfBuffer = htmlToPdfConverter.ConvertUrl(urlTextBox.Text);

// Send the PDF as response to browser

// Set response content type
Response.AddHeader("Content-Type", "application/pdf");

// Instruct the browser to open the PDF file as an attachment or inline
Response.AddHeader("Content-Disposition", String.Format("attachment; filename=HTTP_Cookies.pdf; size={0}", outPdfBuffer.Length.ToString()));

// Write the PDF document buffer to HTTP response
Response.BinaryWrite(outPdfBuffer);

// End the HTTP response and stop the current page processing
Response.End();