ASPNETZERO - SelectPdf ConvertUrl() 中的身份验证来自 Angular 4/.Net Core
ASPNETZERO - Authentication in SelectPdf ConvertUrl() From Angular 4/.Net Core
我正在使用 ASPNETZERO 的 Angular 4 + .Net Core。
我有一个显示用户提交表单列表的网格和一个带有打印表单按钮的列。
这是我的打印功能;我正在为输入中的 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.'));
}
转换和下载文件的 过程 一切正常,但是,当我进行转换(如下)时,url 重定向到登录页面因为身份验证,它是正在转换的页面。
HtmlToPdf converter = new HtmlToPdf();
PdfDocument doc = converter.ConvertUrl(url);
doc.Save(file);
doc.Close();
我不知道如何将 SelectPdf 的身份验证选项与 ASPNETZERO 一起使用,我希望有人知道我可以通过当前 session/credentials 的方法或如何使用 SelectPdf 的身份验证选项之一,以便它转换已通过 url.
谢谢!
体重
你看过这个页面吗?
https://selectpdf.com/docs/WebPageAuthentication.htm
所有转换都在新会话中完成,因此您需要对转换器的用户进行身份验证。
在身份验证 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。
体重
我正在使用 ASPNETZERO 的 Angular 4 + .Net Core。
我有一个显示用户提交表单列表的网格和一个带有打印表单按钮的列。
这是我的打印功能;我正在为输入中的 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.'));
}
转换和下载文件的 过程 一切正常,但是,当我进行转换(如下)时,url 重定向到登录页面因为身份验证,它是正在转换的页面。
HtmlToPdf converter = new HtmlToPdf();
PdfDocument doc = converter.ConvertUrl(url);
doc.Save(file);
doc.Close();
我不知道如何将 SelectPdf 的身份验证选项与 ASPNETZERO 一起使用,我希望有人知道我可以通过当前 session/credentials 的方法或如何使用 SelectPdf 的身份验证选项之一,以便它转换已通过 url.
谢谢!
体重
你看过这个页面吗? https://selectpdf.com/docs/WebPageAuthentication.htm
所有转换都在新会话中完成,因此您需要对转换器的用户进行身份验证。
在身份验证 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。
体重