Response.Redirect в HttpModule - PullRequest
       2

Response.Redirect в HttpModule

0 голосов
/ 12 декабря 2011

Я пытаюсь перенаправить на URL-адрес из модуля HttpModule и, похоже, ничего не работает, я пробовал следующее

(sender as HttpApplication).Context.RewritePath(url);
(sender as HttpApplication).Response.Redirect(url, true);

Кто-нибудь знает правильный код?

Вот коддля модуля HttModule я перехватываю запросы на определенный PDF-документ в нашей CMS и добавляю дату в PDF-файл, сохраняю его в файловую систему и пытаюсь перенаправить на него

private void Application_EndRequest(object sender, System.EventArgs e)
{
    HttpContext context = HttpContext.Current;
    HttpApplication appContext = sender as HttpApplication;

    ADXSTUDIO.Documents.Document document = CmsContext.Current.Document;

    if (document != null && document.Type.Equals("adxResource.1"))
    {
        if (document.GetAttributeValue<bool>("AppendDateToPDF") && HttpContext.Current.Request.QueryString["a"] == null)
        {
            context.Response.Clear();

            string issueDate = "Issue Date: " + DateTime.Now.ToString("HH:mm dd/MM/yyyy");

            Guid id = Guid.NewGuid();
            string filepath1 = HttpContext.Current.Server.MapPath(string.Format("~/appforms/{0}_template.pdf", id));
            string filepath2 = HttpContext.Current.Server.MapPath(string.Format("~/appforms/{0}.pdf", id));
            string url = string.Format("/appforms/{0}.pdf", id);

            PdfReader reader = new PdfReader(document.Url + "&a=1");
            PdfStamper stamper = new PdfStamper(reader, new FileStream(filepath1, FileMode.Create));
            AddVerticalTextBox(stamper, "PageOneDownloadDate", 1);
            stamper.Close();
            reader.Close();

            reader = new PdfReader(filepath1);
            stamper = new PdfStamper(reader, new FileStream(filepath2, FileMode.Create));
            stamper.AcroFields.SetField("PageOneDownloadDate", issueDate);
            stamper.FormFlattening = true;
            stamper.FreeTextFlattening = true;
            stamper.Close();
            reader.Close();

            File.Delete(filepath1);

            //context.RewritePath(url);
            (sender as HttpApplication).Context.RewritePath(url);
            //(sender as HttpApplication).Response.Redirect(url, true);
        }
    }
}
...