需要帮助以打开当前用户的pdf文件 [英] Need help to open the pdf file for the current user

查看:120
本文介绍了需要帮助以打开当前用户的pdf文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我创建了具有许多用户的表,每个用户都有自己的pdf文件.

而我创建了登录页面,因此在用户登录后,我想单击按钮以从网页(C#)中的该表中打开他的pdf文件.

我应该在该按钮中键入什么代码才能为当前用户打开pdf文件?

我知道我尝试过的东西太错了,我真的需要帮助来修复它.

我尝试过的事情:

Okay I create table with many users and each user have his own pdf file.

and I make login page so after the user logged in I wanna make button to open his pdf file from that table in webpage(C#).

what is the code should I type in that button to open the pdf file for the current user?

I know it''s so wrong what I tried and I really need help to fix it.

What I have tried:

protected void Button1_Click(object sender, EventArgs e)
   {


       SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DatabaseConnectionString1"].ConnectionString);
       conn.Open();
       SqlCommand com = new SqlCommand("Select * From table ", conn);



       System.Diagnostics.Process.Start("Select pdf from users where ID=Current.User");

  conn.Close();

   }

推荐答案

网页无法使用Process.Start打开客户端进程-所有C#代码都在服务器上运行,而不是在客户端上运行,因此您启动的所有进程也将在服务器上运行.出于安全原因,您无法从您的网站启动客户端流程.

安全是您要解决的整个问题的一部分:您不能强制在客户端读取PDF文件-您可以将其下载给他,但是他可以选择丢弃,查看或保存文件(取决于他使用的浏览器以及他的配置方式).您无法告诉客户端浏览器打开文件-请仔细考虑:如果可以,则恶意网站也可以.

将PDF下载到用户非常简单: ASP.Net将文件下载到客户端浏览器-堆栈溢出 [ ^ ]-但是正如我所说的,这取决于用户和他的浏览器从那里发生了什么.
Webpages can''t use Process.Start to open client processes - all C# code runs on the server, not the client so all processes you start will also run on the server. You cannot start a client process from your website for security reasons.

And security is part of the whole problem you are going to have: you can''t force a PDF file to be read at the client - you can download it to him, but he will have the option to discard, view, or save the file (depending on the browser he is using and how he has it configured). You cannot tell the client browser to open a file - think about it: if you could do that, so could malicious sites.

To download the PDF to the user is pretty simple: ASP.Net Download file to client browser - Stack Overflow[^] - but as I said it''s up yto teh user and his browser what happens to it from there.


这篇关于需要帮助以打开当前用户的pdf文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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