PDA

View Full Version : Lỗi khi lấy tất cả các Printer trên WEB!



hatred
15-08-2005, 17:13
Với dòng code sau:


PrinterSettings.InstalledPrinters


Trên WINFORM mình lấy được tất cả các máy in, nhưng trên WEB không biểu bị lỗi gì mình không lấy đủ máy in (thiếu cái máy in bình thường).

Thanks.

depgai_lamnha
18-08-2005, 00:52
Bác đang dùng Crystal report for web hử, default nó sẽ không cho lấy gì cả trừ cái máy in đã cài trực tiếp vào webserver , bác đọc thêm cái này nhá:

Printing to a printer installed to the Web server requires that the process under
which ASP.NET is running have sufficient permissions to access Network
printers. In order to provide these permissions, changes to the account that the
ASPNET worker process runs under are necessary as well as changes to the
registry on the Web server.
By default, ASP.NET runs with the permissions of the local “machine”
(ASPNET account for the ASPNET worker process) account. In order to
achieve network printing through IIS (Internet Information Services), the
Framework should be run under the local SYSTEM account. To make this
change, it is necessary to edit the default configuration settings in the
Machine.config file. This file is located by default at:
C:\WINNT\Microsoft.NET\Framework\<VersionNumber>\CONFIG\
Where <VersionNumber> is the version of the .NET Framework installed to the
computer. The account setting is contained within the <ProcessModel> tag of
this file. The default setting for the account is:
userName="machine" password="AutoGenerate"
This can be changed to:
userName="SYSTEM" password="AutoGenerate"
Then save the file.
It is now possible to give the local SYSTEM account on the server permissions
to print. If the printer is a network printer, we must expose the network printer
to the local SYSTEM account. The reason behind this is that when a printer is
installed to a computer, the settings for this printer are stored in the registry
under the HKEY_CURRENT_USER registry hive (Registry file). The IIS
process will never use this registry hive since it always runs under the context of
the local SYSTEM account and cannot be logged onto a server as a “Current
User”. By default, the SYSTEM account does not have any printers set up in
the registry. There are two Microsoft knowledge base articles, Q152451 and
Q184291 that explain how to expose the printer settings to the System account.
Both of these articles require editing the registry on the Web server and copying
the printer settings from the HKEY_CURRENT_USER hive to the
HKEY_USERS/.DEFAULT hive.

Đoạn text bold trên chắc là problem của bác hỉ?

Bác đọc thêm tài liệu trên ở đây nhá:
http://support.businessobjects.com/communityCS/TechnicalPapers/crnet_web_app_printing.pdf.asp

hatred
18-08-2005, 15:02
Thanks bác đúng là vây.
Ngay cả trên Windows Service mình cũng không lấy được các NetWork Printer mình thử cách này của bạn thử.

Có cách nào hay hơn cách này không nhỉ, vì mỗi lẫn đi cài App thì phải chui vào tận chú FrameWork để sửa thì hơi khó chịu nhỉ.

depgai_lamnha
18-08-2005, 16:34
Có 1 cách workaround: bác export cái report của bác ra pdf đi, khi đó user muốn in ở đâu cũng được. Browser printer bằng Adobe Acrobat thì easy, ở đâu nó cũng thấy cả.

hatred
19-08-2005, 09:47
Ở đây mình không có làm report, mình chỉ muốn list ra một list các NetWork Printer trên WEB thôi.
Thanks.

depgai_lamnha
19-08-2005, 12:31
Hì, trong trường hợp này mình chỉ biết có cách modify registry thôi, bác đọc thêm ở đây nhá:

You can set the default printer at design time in the report, and you can change the printer name at run time by setting the ReportDocument.PrintOptions.PrinterName property (the PrintOptions are also where you can assign page margins, portrait/landscape, etc.). Keep in mind that this method prints from the server itself, not from the client machine. This means that any printer you wish to use must be accessible from the server. You cannot print to a client's desktop printer using this method unless that printer is shared on the network and mapped to the server.

If your LAN has networked printers, you can make some guesses as to which printer to assign as the default in each report. For instance, if the Accounting Department has a departmental printer, that would be a good choice to use for the default in an accounting report. You can provide users the option to choose a networked printer by enumerating the printers mapped to the server and populating a drop-down list. The PrinterSettings.InstalledPrinters property returns a collection of installed printers, and can be bound to a DropDownList as below.


DropDownList1.DataSource = System.Drawing.Printing.PrinterSettings.InstalledP rinters
DropDownList1.DataBind()
Again, since this code is executing on the server, this will only enumerate the printers on the server mapped to the System user. If a printer does not appear in the drop-down list, you need to ensure that it is properly mapped to the System user (see below).

All printers and the .NET Framework need to be mapped to the System user in order for this to work. This is not a trivial task to configure. Printers can be mapped to the system account only by editing the registry, and since the Framework is mapped to the System user, you may need to reassign security permissions on files and folders. This process is outlined in the "Printing Web-Based Reports From the Server" article in the VS .NET help files (look up "Crystal Reports, printing" in the VS help index to link to the articles.) and also in Reference 3 (at the end of this article). The process is a little too intricate to cover here (leave comments if help is needed, and I can amend the article later).
Link to article: http://aspalliance.com/509
Hope it help.