如何在ASP.Net中的网络共享打印机上打印标签 [英] How to print label on network shared printer in ASP.Net

查看:95
本文介绍了如何在ASP.Net中的网络共享打印机上打印标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我正在开发一个使用C#.Net的项目。在应用程序内部,它需要在网络上的不同Zebra标签打印机上打印标签。我使用了一个shell

脚本,但它只在本地服务器上运行。有谁知道

怎么办?


谢谢,


Hi,

I am development a project using C#.Net. Inside application, it needs to
print labels on different Zebra label printers on the network. I used a shell
script, but it only worked on the server machine locally. Anybody knows how
to do it?

Thanks,
Peng

推荐答案



我刚刚完成了这个......

我到达那里之前已经走了几个死路。 ...


我最初在ZPL中将我的斑马标签格式化为txt文件,并使用CMD

行TYPE label.txt> \\computername \ Printershare


打印好的标签。但是,然后我开始使用interop

来调用Win32 API来直接打印。


打印没有发生,我感到很困惑。我不知道为什么它没有打印出来,所以我将我的代码shell发送到CMD行,然后运行相同的

TYPE重定向到打印机。

这个没用!!它是从我自己的命令行工作的,但是当代码

炮轰它时....


这是一个权限问题。 ASPNET帐户没有权限在公司网络环境中使用

打印机。

为了解决这个问题,我在web.config中添加了以下行

< Identity Impersonate = true />


这使得服务器上的请求在Web的安全上下文中运行

请求者(即一个有效的用户,而不是ASPNET帐户)


我希望这个工作.....但它没有......: - ((


问题是我还在炮轰执行TYPE,当你这样做时,该帐户又在ASPNET下运行!!!

我在Windows中重新设置了我的直接打印代码,它立即起作用了!


总结:

- add< ; identity impersonate = true />到你的web.config文件

- 对Win32 API进行互操作调用,以执行直接打印到

打印机共享。 br />

我有一些示例代码,如果你愿意的话祝你好运..祝你好运.. HTH

Paul

MCSD,MCDBA

" peng"写道:
Hi
I''ve just done exactly this.....
I went down a few dead ends before getting there....

I initially formatted my Zebra label in ZPL in a txt file, and used a CMD
line TYPE label.txt > \\computername\printershare

The label printed fine. However, I then started to code this using interop
making calls to the Win32 API to direct print.

The prints did not happen, and I was baffled. I wasn''t sure why it wasn''t
printing, so I then had my code shell out to a CMD line, and run the same
TYPE redirect to the printer.
This didn''t work!! It worked from my own command line, but not when the code
shelled it....

Its a permission problem. The ASPNET account doesn''t have permissions to the
printer in a corporate network environment.
To get round this I added the following line to web.config
<Identity Impersonate = true />

This makes the requests on the server run in the security context of the web
requestor (ie. a valid user, and not the ASPNET account)

I expected this to work..... but it did not..... :-((

The problem was that I was still shelling out to execute the TYPE, and when
you do this, the account runs under ASPNET again!!!
I re-instated my direct print code in windows, and it worked straight away!!!

To summise:
- add <identity impersonate = true /> to your web.config file
- make an interop call back to the Win32 API to execute direct printing to a
printer share.

I have some sample code if you would like it.

Good luck.. HTH
Paul
MCSD, MCDBA
"peng" wrote:


我正在开发一个使用C#.Net的项目。在应用程序内部,它需要在网络上的不同Zebra标签打印机上打印标签。我使用了shell
脚本,但它只能在本地服务器上运行。有人知道怎么做吗?

谢谢,
Hi,

I am development a project using C#.Net. Inside application, it needs to
print labels on different Zebra label printers on the network. I used a shell
script, but it only worked on the server machine locally. Anybody knows how
to do it?

Thanks,
Peng





Paul向我提供了示例代码,并将其应用到我的应用程序中。它是美元的
工作得很好!!非常感谢,保罗!





" Paul Aspinall"写道:

Paul provided me with the sample code and I applied it to my application. It
worked beautifully!! Thanks a lot, Paul!

Peng

"Paul Aspinall" wrote:

我刚刚完成了这个.....
我到达那里之前已经走了几个死路......

我最初在ZPL中将我的Zebra标签格式化为txt文件,并使用了CMD
line TYPE label.txt> \\computername \ Printershare

标签打印好了。但是,然后我开始使用interop
调用Win32 API来编写代码来直接打印。

打印没有发生,我感到很困惑。我不知道为什么它不打印,所以我将我的代码shell发送到CMD行,然后运行相同的
TYPE重定向到打印机。
这个没工作!!它可以从我自己的命令行开始工作,但是当代码将它炮轰起来时却没有....

它是一个权限问题。 ASPNET帐户没有在公司网络环境中对
打印机的权限。
为了解决这个问题,我将以下行添加到web.config
< Identity Impersonate = true / >

这使得服务器上的请求在web
请求者的安全上下文中运行(即有效用户,而不是ASPNET帐户)

>我希望这可以工作.....但它没有.....: - ((

问题是我还在炮轰执行TYPE,当时我在Windows中重新设置了我的直接打印代码,它立即起作用了!

总结:
- 将< identity impersonate = true />添加到您的web.config文件中
- 对Win32 API进行互操作调用,以执行直接打印到
打印机共享。

如果您愿意,我会提供一些示例代码。

祝您好运.. HTH

Paul
MCSD,MCDBA

&q UOT;彭"写道:
Hi
I''ve just done exactly this.....
I went down a few dead ends before getting there....

I initially formatted my Zebra label in ZPL in a txt file, and used a CMD
line TYPE label.txt > \\computername\printershare

The label printed fine. However, I then started to code this using interop
making calls to the Win32 API to direct print.

The prints did not happen, and I was baffled. I wasn''t sure why it wasn''t
printing, so I then had my code shell out to a CMD line, and run the same
TYPE redirect to the printer.
This didn''t work!! It worked from my own command line, but not when the code
shelled it....

Its a permission problem. The ASPNET account doesn''t have permissions to the
printer in a corporate network environment.
To get round this I added the following line to web.config
<Identity Impersonate = true />

This makes the requests on the server run in the security context of the web
requestor (ie. a valid user, and not the ASPNET account)

I expected this to work..... but it did not..... :-((

The problem was that I was still shelling out to execute the TYPE, and when
you do this, the account runs under ASPNET again!!!
I re-instated my direct print code in windows, and it worked straight away!!!

To summise:
- add <identity impersonate = true /> to your web.config file
- make an interop call back to the Win32 API to execute direct printing to a
printer share.

I have some sample code if you would like it.

Good luck.. HTH
Paul
MCSD, MCDBA
"peng" wrote:


我正在开发一个使用C#.Net的项目。在应用程序内部,它需要在网络上的不同Zebra标签打印机上打印标签。我使用了shell
脚本,但它只能在本地服务器上运行。有人知道怎么做吗?

谢谢,
Hi,

I am development a project using C#.Net. Inside application, it needs to
print labels on different Zebra label printers on the network. I used a shell
script, but it only worked on the server machine locally. Anybody knows how
to do it?

Thanks,
Peng



你好保罗,


我可以提供您的代码吗?我不明白你的意思是让一个

互操作回调给Win32 API执行直接打印到打印机

分享


我在尝试从ASP.net应用程序打印到共享打印机时遇到同样的问题

。 impersonate = true并不单独帮助...谢谢

提前。我立刻需要你的解决方案......


你真诚的,


凯??汉欧克


Paul Aspinall写道:
Hi Paul,

May I have your code please? I didn''t understand what you mean with "make an
interop call back to the Win32 API to execute direct printing to a printer
share"

I''m experiencing the same problem when trying to print to a shared printer
from an ASP.net application. impersonate=true doesn''t help alone... Thanks in
advance. I need your solution immediately...

Yours sincerely,

Kay?±han Onuk

"Paul Aspinall" wrote:

我刚刚完成了这个.....
我到达那里之前已经走了几个死路......

我最初在ZPL中将我的Zebra标签格式化为txt文件,并使用了CMD
line TYPE label.txt> \\computername \ Printershare

标签打印好了。但是,然后我开始使用interop
调用Win32 API来编写代码来直接打印。

打印没有发生,我感到很困惑。我不知道为什么它不打印,所以我将我的代码shell发送到CMD行,然后运行相同的
TYPE重定向到打印机。
这个没工作!!它可以从我自己的命令行开始工作,但是当代码将它炮轰起来时却没有....

它是一个权限问题。 ASPNET帐户没有在公司网络环境中对
打印机的权限。
为了解决这个问题,我将以下行添加到web.config
< Identity Impersonate = true / >

这使得服务器上的请求在web
请求者的安全上下文中运行(即有效用户,而不是ASPNET帐户)

>我希望这可以工作.....但它没有.....: - ((

问题是我还在炮轰执行TYPE,当时我在Windows中重新设置了我的直接打印代码,它立即起作用了!

总结:
- 将< identity impersonate = true />添加到您的web.config文件中
- 对Win32 API进行互操作调用,以执行直接打印到
打印机共享。

如果您愿意,我会提供一些示例代码。

祝您好运.. HTH

Paul
MCSD,MCDBA

&q UOT;彭"写道:
Hi
I''ve just done exactly this.....
I went down a few dead ends before getting there....

I initially formatted my Zebra label in ZPL in a txt file, and used a CMD
line TYPE label.txt > \\computername\printershare

The label printed fine. However, I then started to code this using interop
making calls to the Win32 API to direct print.

The prints did not happen, and I was baffled. I wasn''t sure why it wasn''t
printing, so I then had my code shell out to a CMD line, and run the same
TYPE redirect to the printer.
This didn''t work!! It worked from my own command line, but not when the code
shelled it....

Its a permission problem. The ASPNET account doesn''t have permissions to the
printer in a corporate network environment.
To get round this I added the following line to web.config
<Identity Impersonate = true />

This makes the requests on the server run in the security context of the web
requestor (ie. a valid user, and not the ASPNET account)

I expected this to work..... but it did not..... :-((

The problem was that I was still shelling out to execute the TYPE, and when
you do this, the account runs under ASPNET again!!!
I re-instated my direct print code in windows, and it worked straight away!!!

To summise:
- add <identity impersonate = true /> to your web.config file
- make an interop call back to the Win32 API to execute direct printing to a
printer share.

I have some sample code if you would like it.

Good luck.. HTH
Paul
MCSD, MCDBA
"peng" wrote:


我正在开发一个使用C#.Net的项目。在应用程序内部,它需要在网络上的不同Zebra标签打印机上打印标签。我使用了shell
脚本,但它只能在本地服务器上运行。有人知道怎么做吗?

谢谢,
Hi,

I am development a project using C#.Net. Inside application, it needs to
print labels on different Zebra label printers on the network. I used a shell
script, but it only worked on the server machine locally. Anybody knows how
to do it?

Thanks,
Peng



这篇关于如何在ASP.Net中的网络共享打印机上打印标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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