1.
<%@ Page Language="C#" %> <html> <body> <form id="form1" runat="server"> <% for(int i = 0; i < 6; i++) %> <% { Response.Write("<br>" + i.ToString()); }%> </form> </body> </html>
HttpCookie MyCookie = new HttpCookie("LastVisit"); DateTime now = DateTime.Now; MyCookie.Value = now.ToString(); MyCookie.Expires = now.AddHours(1); Response.Cookies.Add(MyCookie);HttpCookie myCookie = new HttpCookie("UserSettings"); myCookie["Font"] = "Arial"; myCookie["Color"] = "Blue"; myCookie.Expires = DateTime.Now.AddDays(1d); Response.Cookies.Add(myCookie);Response.Cookies["UserSettings"]["Font"] = "Arial"; Response.Cookies["UserSettings"]["Color"] = "Blue"; Response.Cookies["UserSettings"].Expires = DateTime.Now.AddDays(1d);Response.StatusCode = 301; Response.Status = "301 Moved Permanently"; Response.RedirectLocation = "http://www.newurl.com "; Response.End();Response.Cookies["userName"].Value = "patrick"; Response.Cookies["userName"].Expires = DateTime.Now.AddDays(1); HttpCookie aCookie = new HttpCookie("lastVisit"); aCookie.Value = DateTime.Now.ToString(); aCookie.Expires = DateTime.Now.AddDays(1); Response.Cookies.Add(aCookie);2.
<%@ Page Language="C#" %> <script runat=server> protected String GetTime() { return DateTime.Now.ToString("t"); } </script> <html> <body> <form id="form1" runat="server"> Current server time is <% =GetTime()%>. </form> </body> </html>3.<%@ Page Language="C#" %> <%@ import Namespace="System.Drawing" %> <%@ import Namespace="System.Drawing.Imaging" %> <%@ import Namespace="System.Drawing.Drawing2D" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> private void Page_Load(object sender, EventArgs e) { // Set the page's content type to JPEG files // and clears all content output from the buffer stream. Response.ContentType = "image/jpeg"; Response.Clear(); // Buffer response so that page is sent // after processing is complete. Response.BufferOutput = true; // Create a font style. Font rectangleFont = new Font( "Arial", 10, FontStyle.Bold); // Create integer variables. int height = 100; int width = 200; // Create a random number generator and create // variable values based on it. Random r = new Random(); int x = r.Next(75); int a = r.Next(155); int x1 = r.Next(100); // Create a bitmap and use it to create a // Graphics object. Bitmap bmp = new Bitmap( width, height, PixelFormat.Format24bppRgb); Graphics g = Graphics.FromImage(bmp); g.SmoothingMode = SmoothingMode.AntiAlias; g.Clear(Color.LightGray); // Use the Graphics object to draw three rectangles. g.DrawRectangle(Pens.White, 1, 1, width-3, height-3); g.DrawRectangle(Pens.Aquamarine, 2, 2, width-3, height-3); g.DrawRectangle(Pens.Black, 0, 0, width, height); // Use the Graphics object to write a string // on the rectangles. g.DrawString( "ASP.NET Samples", rectangleFont, SystemBrushes.WindowText, new PointF(10, 40)); // Apply color to two of the rectangles. g.FillRectangle( new SolidBrush( Color.FromArgb(a, 255, 128, 255)), x, 20, 100, 50); g.FillRectangle( new LinearGradientBrush( new Point(x, 10), new Point(x1 + 75, 50 + 30), Color.FromArgb(128, 0, 0, 128), Color.FromArgb(255, 255, 255, 240)), x1, 50, 75, 30); // Save the bitmap to the response stream and // convert it to JPEG format. bmp.Save(Response.OutputStream, ImageFormat.Jpeg); // Release memory used by the Graphics object // and the bitmap. g.Dispose(); bmp.Dispose(); // Send the output to the client. Response.Flush(); } </script> <html xmlns="http://www.w3.org/1999/xhtml" > <head> <title>ASP.NET Example</title> </head> <body> <form id="form1" runat="server"> </form> </body> </html>4.<%@ Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> private void Page_Load(object sender, EventArgs e) { // Check whether the browser remains // connected to the server. if (Response.IsClientConnected) { // If still connected, redirect // to another page. Response.Redirect("Page2CS.aspx", false); } else { // If the browser is not connected // stop all response processing. Response.End(); } } </script> <html xmlns="http://www.w3.org/1999/xhtml" > <head> <title>ASP.NET Example</title> </head> <body> <form id="form1" runat="server"> </form> </body> </html>5.<%@ Page Language="C#" %> <%@ Import Namespace="System.IO" %> <%@ import Namespace="Samples.AspNet.CS.Controls" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> private void Page_Load(object sender, EventArgs e) { // Filter the text to be rendered as all uppercase. Response.Filter = new UpperCaseFilterStream(Response.Filter); // Convert a virtual path to a fully qualified physical path. string fullpath = Request.MapPath("~\\TestFile.txt"); try { // Read the contents of the file using a StreamReader. using (StreamReader sr = new StreamReader(fullpath)) while (sr.Peek() >= 0) { Response.Write((char)sr.Read()); } Message.Text = "Reading the file was successful."; } catch (Exception ex) { Message.Text = "The process failed."; } } </script> <html xmlns="http://www.w3.org/1999/xhtml" > <head> <title>HttpResponse.MapPath Example</title> </head> <body> <form id="form1" runat="server"> <asp:Label id="Message" runat="server"/> </form> </body> </html>6.<%@ Page Language="C#" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> private void Page_Load(object sender, EventArgs e) { // Check whether the browser remains // connected to the server. if (Response.IsClientConnected) { // If still connected, redirect // to another page. Response.Redirect("Page2CS.aspx", false); } else { // If the browser is not connected // stop all response processing. Response.End(); } } </script> <html xmlns="http://www.w3.org/1999/xhtml" > <head> <title>ASP.NET Example</title> </head> <body> <form id="form1" runat="server"> </form> </body> </html>7.<%@ Page Language="C#" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> // When the page is posted back, the text box's // Text property value is HTML encoded and sent // sent to the current Response. void btnSubmit_Click(object sender, EventArgs e) { if (IsPostBack) { Server.HtmlEncode(txtSubmitString.Text, Response.Output); } } </script> <html xmlns="http://www.w3.org/1999/xhtml" > <head> <title>ASP.NET Example</title> </head> <body> <form id="form1" runat="server"> <p style="font-family:Tahoma; font-size:12"> Enter your comments here: </p> <p> <asp:TextBox id="txtSubmitString" runat="server" Width="181px" TextMode="MultiLine"></asp:TextBox> </p> <p> <asp:Button id="btnSubmit" onclick="btnSubmit_Click" runat="server" Text="Submit"></asp:Button> </p> <p> <asp:Label id="lblEncodedString" runat="server"></asp:Label> </p> </form> </body> </html>8.<%@ Page Language="C#" %> <%@ import Namespace="System.Drawing" %> <%@ import Namespace="System.Drawing.Imaging" %> <%@ import Namespace="System.Drawing.Drawing2D" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> private void Page_Load(object sender, EventArgs e) { // Set the page's content type to JPEG files // and clears all content output from the buffer stream. Response.ContentType = "image/jpeg"; Response.Clear(); // Buffer response so that page is sent // after processing is complete. Response.BufferOutput = true; // Create a font style. Font rectangleFont = new Font( "Arial", 10, FontStyle.Bold); // Create integer variables. int height = 100; int width = 200; // Create a random number generator and create // variable values based on it. Random r = new Random(); int x = r.Next(75); int a = r.Next(155); int x1 = r.Next(100); // Create a bitmap and use it to create a // Graphics object. Bitmap bmp = new Bitmap( width, height, PixelFormat.Format24bppRgb); Graphics g = Graphics.FromImage(bmp); g.SmoothingMode = SmoothingMode.AntiAlias; g.Clear(Color.LightGray); // Use the Graphics object to draw three rectangles. g.DrawRectangle(Pens.White, 1, 1, width-3, height-3); g.DrawRectangle(Pens.Aquamarine, 2, 2, width-3, height-3); g.DrawRectangle(Pens.Black, 0, 0, width, height); // Use the Graphics object to write a string // on the rectangles. g.DrawString( "ASP.NET Samples", rectangleFont, SystemBrushes.WindowText, new PointF(10, 40)); // Apply color to two of the rectangles. g.FillRectangle( new SolidBrush( Color.FromArgb(a, 255, 128, 255)), x, 20, 100, 50); g.FillRectangle( new LinearGradientBrush( new Point(x, 10), new Point(x1 + 75, 50 + 30), Color.FromArgb(128, 0, 0, 128), Color.FromArgb(255, 255, 255, 240)), x1, 50, 75, 30); // Save the bitmap to the response stream and // convert it to JPEG format. bmp.Save(Response.OutputStream, ImageFormat.Jpeg); // Release memory used by the Graphics object // and the bitmap. g.Dispose(); bmp.Dispose(); // Send the output to the client. Response.Flush(); } </script> <html xmlns="http://www.w3.org/1999/xhtml" > <head> <title>ASP.NET Example</title> </head> <body> <form id="form1" runat="server"> </form> </body> </html>9.using System; using System.Data; using System.Web; using System.Web.Security; using System.Web.UI; // Module that sets Response.SubStatusCode in PostAuthenticateRequest event handler. namespace Samples { public class ModuleExampleTestCS : IHttpModule { public ModuleExampleTestCS() { // Constructor } public void Init(HttpApplication app) { app.PostAuthenticateRequest += new EventHandler(PostAuthenticateRequest_Handler); } public void Dispose() { } public void PostAuthenticateRequest_Handler(object source, EventArgs e) { HttpApplication app = (HttpApplication)source; HttpContext context = app.Context; // Set a SubStatusCode for Failed Request Tracing in IIS7 context.Response.SubStatusCode = 99; } } }// Check whether the request is sent // over HTTPS. If not, do not send // content to the client. if (!Request.IsSecureConnection) { Response.SuppressContent = true; }
No comments:
Post a Comment