Use ASP. NET to implement Web Attacks

Source: Internet
Author: User

Recently, we have to change a C/S structure program to a B/S structure. The problem of printing is encountered. After research, there are several web printing methods:

1. Use IE to print directly. This method is the most convenient, but the control capability is poor.

2. Using the active control, you can create an IE control to control printing.

3. Third-party tools such as Crystal Reports are expensive to purchase.

According to my requirements, I can use IE to print it directly. The purpose is to print the corresponding project at the corresponding position on an application form. The form also has only one page, which does not involve paging issues.

Let's take a look at the table to print the textbox content in a webform at the corresponding position.

 

First, let's talk about my idea: The program automatically generates a web page to be printed and passes the corresponding field value to this web page. The positions of each field are measured in advance, use <Div style = ""> to control the position of the corresponding field on the page. The following technologies are required:

1. Customize a printing class to automatically generate the page to be printed.

Using system;
Using system. Data;
Using system. configuration;
Using system. Web;
Using system. Web. Security;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Web. UI. webcontrols. webparts;
Using system. Web. UI. htmlcontrols;
Using system. text;
Using system. IO;
Using system. collections;

///
/// Summary of myprint
///
Public class myprint: system. Web. UI. Page
{
Public static string pageurlbase; // basic page url
Public string name;
Public String sex;
Public String brithday;
Public String country;
Public String cardname;
Public String cardnum;
Public String address;
Public String touchaddress;
Public String Tel;
Public String postcode;
Public string type;
Public String reg;
Public String oldreg;
///
/// Restore the print Template
///
///
///

Public void Clearview ()
{
Stringbuilder htmltext = new stringbuilder ();
Try
{
If (! File. exists (server. mappath (context. Request. applicationpath) + "// printmediaworkflow htm "))
{
Filestream FS = file. Create (server. mappath (context. Request. applicationpath) + "// printmediaworkflow htm ");
FS. Close ();
}
Using (streamwriter Sw = new streamwriter (server. mappath (context. Request. applicationpath) + "// printmediaworkflow htm", false, encoding. Default ))
{
String stabletitle = "";
Stabletitle = stabletitle + "<HTML>/N ";
Stabletitle = stabletitle + "Stabletitle = stabletitle + "<title> </title>/N ";
Stabletitle = stabletitle + "<meta http-equiv =/" Content-Type/"content =/" text/html; charset = gb2312/">/N ";
Stabletitle = stabletitle + "<SCRIPT lanage =/" javascript/"> ";
Stabletitle = stabletitle + "function Preview ()";
Stabletitle = stabletitle + "{";
Stabletitle = stabletitle + "window. Print (); window. Close ()} </SCRIPT> ";
Stabletitle = stabletitle + "

Stabletitle = stabletitle + "<body style =/" background-position: Left top; Background-image: URL (images/application table .jpg); left: 0px; width: 735px; position: absolute; top: 0px; Height: 1050px; /"ms_positioning =/" gridlayout/"topmargin =/" 0/"bottommargin =/" 0/"onLoad =/" Preview ();/">/N ";
// Stabletitle = stabletitle + "model/N ";
// Content of the official page
Stabletitle = stabletitle + "<font face =/" /"> ";
Stabletitle = stabletitle + "<Div style =/" Z-index: 100; left: 138px; position: absolute; top: 176px/">" + name + "</div> ";
// Stabletitle = stabletitle + " ";
Stabletitle = stabletitle + "<Div style =/" Z-index: 101; left: 395px; position: absolute; top: 176px/">" + sex + "</div> ";
Stabletitle = stabletitle + "<Div style =/" Z-index: 102; left: 488px; position: absolute; top: 176px/">" + brithday + "</div> ";
Stabletitle = stabletitle + "<Div style =/" Z-index: 103; left: 640px; position: absolute; top: 176px/">" + country + "</div> ";
Stabletitle = stabletitle + "<Div style =/" Z-index: 104; left: 138px; position: absolute; top: 200px/">" + cardname + "</div> ";
// Stabletitle = stabletitle + "<Div style =/" Z-index: 105; left: 272px; position: absolute; top: 200px/">" + cardnum + "</div> ";
Stabletitle = stabletitle + "<Div style =/" Z-index: 106; left: 136px; position: absolute; top: 256px/">" + address + "</div> ";
Stabletitle = stabletitle + "<Div style =/" Z-index: 107; left: 136px; position: absolute; top: 288px/">" + touchaddress + "</div> ";
Stabletitle = stabletitle + "<Div style =/" Z-index: 108; left: 136px; position: absolute; top: 320px/">" + Tel + "</div> ";
Stabletitle = stabletitle + "<Div style =/" Z-index: 109; left: 472px; position: absolute; top: 320px/">" + postcode + "</div> ";
Stabletitle = stabletitle + "<Div style =/" Z-index: 110; left: 352px; position: absolute; top: 352px/">" + Reg + "</div> ";
// Stabletitle = stabletitle + "<Div style =/" Z-index: 112; left: 119px; position: absolute; top: 358px/"> name </div> ";
// Determine whether it is the first application or the location
If (type = "initial application ")
Stabletitle = stabletitle + " ";
Else if (type = "added quasi-driving model ")
{
Stabletitle = stabletitle + " ";
Stabletitle = stabletitle + "<Div style =/" Z-index: 111; left: 600px; position: absolute; top: 352px/">" + oldreg + "</div> ";
}
Else if (type = "driving police license ")
{
Stabletitle = stabletitle + " ";
Stabletitle = stabletitle + "<Div style =/" Z-index: 111; left: 600px; position: absolute; top: 352px/">" + oldreg + "</div> ";

}
Else
{
Stabletitle = stabletitle + " ";
Stabletitle = stabletitle + "<Div style =/" Z-index: 111; left: 600px; position: absolute; top: 352px/">" + oldreg + "</div> ";

}
// Output ID card
Int length = cardnum. length;
Int start = 272;
For (INT I = 0; I <length; I ++)
{
Stabletitle = stabletitle + "<Div style =/" Z-index: 105; left: "+ start. tostring () + "PX; position: absolute; top: 200px/"> "+ cardnum. substring (I, 1) + "</div> ";
Start = start + 18;
}
Stabletitle = stabletitle + "</body>/N ";
Stabletitle = stabletitle + "Sw. writeline (stabletitle );
Sw. Flush ();
Sw. Close ();
}
}
Catch
{
Response. Write ("<SCRIPT> alert (& apos; An error occurred while reading the file! & Apos;) </SCRIPT> ");
}
}
Public myprint ()
{
//
// Todo: add the constructor logic here
//
Try
{
String urlsuffix = context. Request. url. Host;
Urlsuffix = urlsuffix + (context. Request. url. Port. tostring () = ""? "": ":" + Context. Request. url. Port );
Urlsuffix = urlsuffix + (context. Request. applicationpath. tostring () = "/"? "": Context. Request. applicationpath );
Pageurlbase = @ "http: //" + urlsuffix;
}
Catch
{

}
}
}

The Clearview function is used to automatically generate webpages. When the ID card is output in the table, the ID card is output exactly by bit.
2. Call Method
Print. Name = This. textbox2.text;
If (radiobutton1.checked)
Print. Sex = "male ";
Else
Print. Sex = "female ";
Print. brithday = This. textbox4.text;
Print. Tel = This. textbox5.text;
Print. Country = This. dropdownlist2.text;
Print. type = This. dropdownlist3.text;
Print. oldreg = This. dropdownlist4.text;
Print. Reg = This. dropdownlist6.text;
Print. Address = This. textbox13.text;
Print. touchaddress = This. textbox14.text;
Print. cardname = "ID card ";
Print. cardnum = This. textbox3.text;
Print. Clearview ();
String showopen = "<SCRIPT lanage = & apos; JavaScript & apos;> zookeeper open(&apos;print=20.htm & apos;, & apos; _ blank & apos;); </SCRIPT> ";
Scriptmanager. registerclientscriptblock (this. button4, this. GetType (), "verygood", showopen, false );
This is the response event of a "print" button on the submit page. First, pass the corresponding fields on the page to the print class, and then call Clearview to generate the webpage. Finally, open the webpage in a new window by registering a script. I used Ajax here, so I used
Scriptmanager. registerclientscriptblock (this. button4, this. GetType (), "verygood", showopen, false); this statement can be used without Ajax.
Registerclientscriptblock ("clientscript", showopen );
3. Javascript used
<Script language = "JavaScript">
Function Preview ()
{
Window. Print ();
Self. Close ();
}
</SCRIPT>
The window can be closed automatically after printing.

In this way, Web attacks are basically implemented. For more information, see http://www.cnblogs.com/hellosnoopy/articles/105475.html.

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/ausoldier/archive/2008/07/20/2680058.aspx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.