我正在使用ASPNETZERO的角4+ .Net核心。
我有一个网格,它显示用户提交的表单的列表,还有一个带有按钮的列来打印表单。
下面是我的print函数;我在输入中传递ConvertUrl()方法的url:
print(item: FormSummaryDto) {
this.beginTask();
let formUrl = AppConsts.appBaseUrl + '/#/app/main/form/' + item.formType.toLowerCase() + '/' + item.id + '/print';
let input = new ExportFormInput({ formId: item.id, formUrl: formUrl, includeAttachments: true });
this.service.exportFormToPdf(input)
.finally(() => { this.endTask(); })
.subscribe((result) => {
if (result == null || result.fileName === '') {
return;
}
this._fileDownloadService.downloadTempFile(result);
}, error => console.log('downloadFile', 'Could not download file.'));
}但是,对于转换和下载文件的process,一切都很好,但是,当我完成转换(下面)时,url由于身份验证而重定向到登录页面,并且该页面正在转换。
HtmlToPdf converter = new HtmlToPdf();
PdfDocument doc = converter.ConvertUrl(url);
doc.Save(file);
doc.Close();我不知道如何在ASPNETZERO中使用SelectPdf的身份验证选项,我希望有人知道我可以传递当前会话/凭据的方法,或者如何使用SelectPdf的身份验证选项之一,以便转换传递的url。
谢谢!
工作组
发布于 2018-09-18 23:43:43
在身份验证cookie的SelectPdf文档中,让我无法理解的是示例中的System.Web.Security.FormsAuthentication.FormsCookieName,我认为它应该是什么。
// set authentication cookie
converter.Options.HttpCookies.Add(
System.Web.Security.FormsAuthentication.FormsCookieName,
Request.Cookies[FormsAuthentication.FormsCookieName].Value);但我有以下例外:
System.TypeLoadException: Could not load type 'System.Web.Security.FormsAuthentication' from assembly 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.我最终意识到,我需要通过ASPNETZERO身份验证cookie (在查看cookie文件夹后,它是"Abp.AuthToken")。我没有尝试在服务方法中获取cookie值,而是在调用参数中传递了它:
print(item: FormSummaryDto) {
this.beginTask();
let formUrl = AppConsts.appBaseUrl + '/#/app/main/form/' + item.formType.toLowerCase() + '/' + item.id + '/print';
let authToken = abp.utils.getCookieValue('Abp.AuthToken');
let input = new ExportFormInput({ formId: item.id, formUrl: formUrl, authToken: authToken, includeAttachments: true });
this.service.exportFormToPdf(input)
.finally(() => { this.endTask(); })
.subscribe((result) => {
if (result == null || result.fileName === '') {
return;
}
this._fileDownloadService.downloadTempFile(result);
}, error => console.log('downloadFile', 'Could not download file.'));
}最后,在方法中添加转换器HttpCookies选项:
HtmlToPdf converter = new HtmlToPdf();
converter.Options.HttpCookies.Add("Abp.AuthToken", authToken);
PdfDocument doc = converter.ConvertUrl(url);
doc.Save(file);
doc.Close();在此之后,我成功地转换了url。
工作组
发布于 2018-09-17 06:09:48
你看过这一页吗?https://selectpdf.com/docs/WebPageAuthentication.htm
所有转换都是在新会话中完成的,因此需要对转换器的用户进行身份验证。
https://stackoverflow.com/questions/52350538
复制相似问题