日韩天天综合网_野战两个奶头被亲到高潮_亚洲日韩欧美精品综合_av女人天堂污污污_视频一区**字幕无弹窗_国产亚洲欧美小视频_国内性爱精品在线免费视频_国产一级电影在线播放_日韩欧美内地福利_亚洲一二三不卡片区

ASP.NET筆記之 Request 、Response 與Server的使用_.Net教程

編輯Tag賺U幣

推薦:ASP.NET編程的十大技巧
1、在使用Visual Studio .NET時(shí),除直接或非引用的對象外,不要使用缺省的名字。 .NET帶來的好處之一是所有的源代碼和配置文件都是純文本文件,能夠使用Notepad或WordPad等任意的文本編輯器進(jìn)行編輯。如果不愿意,我們并非一定要使用Visual Studio .NET作為集成開發(fā)環(huán)

1、Request

下面做一個(gè)實(shí)例,通過Request的一些方法來判斷瀏覽圖片是不是在內(nèi)部瀏覽,還是直接按網(wǎng)址瀏覽或者被外部使用

復(fù)制代碼 代碼如下:www.hl5o.cn

<%@ WebHandler Language="C#" Class="image_Test" %>

using System;
using System.Web;

public class image_Test : IHttpHandler {

public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "image/JPEG";
//如果直接訪問URLreferrer 就是null ,如果嵌入到頁面中請求
//URLreferrer就是頁面的地址
string picPath=HttpContext.Current.Server.MapPath("DSCF0738.JPG");
using (System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(picPath)) {
using (System.Drawing.Graphics graphic = System.Drawing.Graphics.FromImage(bitmap))
{
//不過還是太脆弱,因?yàn)閁rlReferrer還是由客戶端提交
//迅雷破解毫無鴨梨
if (context.Request.UrlReferrer == null)
{
graphic.Clear(System.Drawing.Color.White);
graphic.DrawString("禁止直接瀏覽圖片", new System.Drawing.Font("宋體", 15),
System.Drawing.Brushes.Red, 0, 0);

}
//http://127.0.0.1:32581/WebSite_zzl01/vivideo_test/request/Request.aspx

else if (context.Request.UrlReferrer.Host != "localhost")
{
graphic.Clear(System.Drawing.Color.White);
graphic.DrawString("圖片只允許在博客園內(nèi)部查看", new System.Drawing.Font("宋體", 15),
System.Drawing.Brushes.Red, 0, 0);
}
//轉(zhuǎn)化成流格式輸出
bitmap.Save(context.Response.OutputStream,System.Drawing.Imaging.ImageFormat.Jpeg);

}
}
}

public bool IsReusable {
get {
return false;
}
}

}

html

<img src="image_Test.ashx" />啦啦啦啦

2、Response

(1)返回 流,以流的形式返回給客戶端
* 每次write,往緩存里存,不是直接給瀏覽器,等到存滿了或者處理完成才發(fā)送到瀏覽器
* Flush方法,立即發(fā)給瀏覽器

(2)反盜鏈等:不往下執(zhí)行了在aspx寫較好
context.Response.End();

(3)aspx 和ashx

像輸出文本、圖片、下載地址最后是寫在ashx里面,而html內(nèi)容則寫在aspx里面

(4)重定向 Redirect

Flush實(shí)例:

復(fù)制代碼 代碼如下:www.hl5o.cn

<%@ WebHandler Language="C#" Class="response" %>

using System;
using System.Web;

public class response : IHttpHandler {

public void ProcessRequest (HttpContext context) {

//如果是plain則<br/>無效果
context.Response.ContentType = "text/html";
//耗時(shí)操作
for (int i = 0; i < 20; i++)
{
System.Threading.Thread.Sleep(500);
context.Response.Write("第"+i+"步開始執(zhí)行<br/>");
//采用Flush,立即發(fā)給客戶端,效果很明顯!
context.Response.Flush();
}
}

public bool IsReusable {
get {
return false;
}
}

}


3、server

(1)Server.Transfer和 Response.Redirect的區(qū)別

*transfer訪問只能是內(nèi)部網(wǎng)站,不能是外部的,而redirect可以

* transfer是網(wǎng)站內(nèi)部接管的,只執(zhí)行一次http請求,而Redirect則是轉(zhuǎn)幾次就執(zhí)行幾次http請求并在地址欄中顯示

* transfer會直接把各種信息傳過去而Redirect不會
* 不能重新定向到ashx transfo

實(shí)例:

復(fù)制代碼 代碼如下:www.hl5o.cn

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class vivideo_test_server_server : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string text=Request["id"];
if (text == "1") {
Response.Write("一");
}
else if(text=="2"){
//請求的信息都會傳入服務(wù)器
Server.Transfer("DSCF0738.JPG");
}
else if (string.IsNullOrEmpty(text))
{
Response.Write("空");
}
else {
//不會取到傳過來的參數(shù)
Response.Redirect("蘋果.jpg");
//除非自己給它穿過去
//Response.Redirect("aaa.aspx?id=1");

}
}
}

分享:使用Fiddler調(diào)試visual studion多個(gè)虛擬站點(diǎn)的問題分析
本篇文章小編為大家介紹,使用Fiddler調(diào)試visual studion多個(gè)虛擬站點(diǎn)的問題分析。需要的朋友參考下

來源:模板無憂//所屬分類:.Net教程/更新時(shí)間:2013-04-25
相關(guān).Net教程