服务器端pdf生成,并且asp.net进行身份验证 [英] Server side pdf generation, and asp.net forms authentication

查看:95
本文介绍了服务器端pdf生成,并且asp.net进行身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我花了几天的时间来尝试获取一个PDF生成应用程序,以使用Forms Athentication从ASP.NET密码保护的站点生成PDF.问题实际上是如何通过表单身份验证来授权任何第三方应用程序?

这是供应商对如何做的解释,我不该知道.

在大多数身份验证下,将为后续请求返回会话ID,因此不需要重新身份验证.您可能希望查看响应中的cookie,并设置cookie,以便ABCpdf的请求中包含会话ID cookie.
要获取cookie,您将需要使用新的WebRequest(HttpWebRequest)从您的目标站点请求某些内容.您可以传递所需的任何凭据,并且在获取响应之前,需要初始化请求的CookieContainer属性(以使该属性不为null).然后,您可以使用WinINet函数InternetSetCookie从CookieContainer设置cookie."

他们试图提供帮助,但这超出了我的范围.任何人都可以在受密码保护的网站上工作,该网站可以帮助...请吗?

问题是读取ULR.我可以生成PDF,但是我得到的只是login.aspx的PDF.表单身份验证将不允许ABCPDF.NET打开网页.

I have spent days trying to get a PDF generating application to generate PDF''s from an ASP.NET password protected site using Forms Athentication. The question is really how can any 3rd party application be authorised under forms authentication?

Here is the suppliers explanation of what to do, which I do not undersatnd.

"Under most authentication, a session ID is returned for subsequent requests so re-authentication is not needed. You may want to look at the cookies in the response and set the cookies so that ABCpdf''s request contains the session-ID cookies.
To obtain the cookies, you''ll need to use a new WebRequest (HttpWebRequest) to request something from your target site. You can pass in whatever credentials desired and you''ll need to initialize the request''s CookieContainer property (so that the property is not null) before you get the response. You can then set the cookies from CookieContainer with the WinINet function InternetSetCookie."

They have tried to help, but this is beyond me. Has anyone got this working under a password protected site that can help...please?

The problem is reading the ULR. I can generate a PDF, but all I get is a PDF of login.aspx. Forms Authentication will not let ABCPDF.NET open the web page.

Dim theDoc As Doc = New Doc()

theDoc.AddImageUrl("http://XXXXXXXX/App_Auth_Print.aspx")
theDoc.Save(Server.MapPath("htmlimport1.pdf"))
theDoc.Clear()



始终将未经授权的请求"theDoc.AddImageUrl"重定向到login.aspx.



"theDoc.AddImageUrl" as an unauthorised request is always redirected to login.aspx.

推荐答案

只能在temp目录中完成进程内文件写入(至少默认情况下).

您可以通过 System.IO.Path.GetTempPath 找到该目录.

如果要允许写入其他目录,则必须授予IUSR_写入权限,尽管我衷心建议再次这样做.

因此,对您问题的简短回答是

  • 生成pdf进程外文件(例如将请求发送到NT服务等)
  • 在temp目录中生成PDF.不过,您将需要读入文件并将其分别发送给客户端,因为用户将无法通过URL来访问该文件.
The only place in-process file writing can be done is in the temp directory (at least by default).

You can find this Directory with System.IO.Path.GetTempPath.

If you want to allow writing to other directories you will have to give IUSR_ write permissions, though I heartily recommend AGAINST doing that.

So the short answer to your question is either

  • Generate the pdf out of process (like send the request to an NT Service etc.)
  • Generate the PDF in the temp directory. You will need to read the file in and send it to the client separately though, since the user won''t be able to be able to get to the file via a URL.


阿拉里语,

感谢您的答复,非常感谢您的宝贵时间.但是我可以使用ABCPDF.NET创建PDF文件.我已经创建了至少100次文件,但是它始终是登录页面的文件! ABCPDF需要以下代码才能在网站上打开页面,并将HMTL转换为PDF图像.

Alaric,

Thank you for the reply, I really appreciate your time. But I can create the PDF files using ABCPDF.NET. I have created the file at least 100 times, but its always of the login page! ABCPDF requires the following code to open a page in the website, and convert the HMTL to a PDF image.

Dim theDoc As Doc = New Doc()

theDoc.AddImageUrl("http://XXXXXXXXX/App_Auth_Print.aspx")
theDoc.Save(Server.MapPath("htmlimport1.pdf"))
theDoc.Clear()




问题是"theDoc.AddImageUlr尚未通过授权过程,因此被重定向到login.aspx.

我对Cookie和授权不是很有信心,我尝试使用FormsAuthentication.Authenticate(username.Text,password.Text)以编程方式授权此请求,并通过PrintSecurityID Querystring传递刻写的用户名和密码.但是我得到的只是登录屏幕(PDF)!真让我发疯!




The problem is "theDoc.AddImageUlr has not been through the authorisation process, and is therefore redirected to login.aspx.

I am not very confident with cookies and authorisation, and I have tried to programmatically authorise this request using FormsAuthentication.Authenticate(username.Text, password.Text), passing the username and password encripted via the PrintSecurityID Querystring. But all I get is the login screen as a PDF! Its driving me mad!


我明白了,我误解了这个问题.从本质上讲,您的问题似乎是您从不是用户的会话进入的,因此它总是将您引导到登录屏幕.

在这种情况下,您要处理Cookie,身份验证Cookie.这超出了我的专业知识,但我发现了.

使用ASP.NET的通过安全认证(单点登录)

这个(看起来更像你想要的)

如何:在两个ASP.NET应用程序之间通过身份验证

就我个人而言,我认为我将启用瞬间绕过".创建一个唯一的令牌,该令牌会在几秒钟后超时,并在"post"中传递它.因此,我可以绕过登录.

您可能要尝试的最后一件事是WCF身份验证服务.
I see, I misunderstood the problem. Essentially your problem here seems to be that you are coming in from session that isn''t the users, thus it is always directing you to the login screen.

In this case you are dealing with cookies, authentication cookies. And this is a little beyond my expertise but I found this.

Pass-Through Security Authentication (Single Sign-on) using ASP.NET

and this (which looks more like what you want)

How To: Pass Authentication Between Two ASP.NET Applications

Personally I think I would enable a ''momentary bypass''. Create a unique token, one that times out in a few seconds and pass it in a "post". Thus allowing me to bypass the login.

The last thing you might try is the WCF authentication service.


这篇关于服务器端pdf生成,并且asp.net进行身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆