婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識庫 > ashx文件的使用小結

ashx文件的使用小結

熱門標簽:地圖標注多少錢一張 電銷機器人 數據 400電話辦理信任翰諾科技 廣州銷售外呼系統定制 云狐人工智能電話機器人 宿遷智能外呼系統排名 ai電銷機器人對貸款有幫助嗎 福州人工智能電銷機器人加盟 怎樣給陜西地圖標注顏色

一提到Ashx文件,我們就會想到http handler以及圖片加載(在之前我們一般使用ASPX或者Webservice去做),一般做法如下:

Handler.ashx:

復制代碼 代碼如下:

%@ WebHandler Language="C#" Class="Handler" %>
using System;
using System.IO;
using System.Web;
public class Handler : IHttpHandler {

public bool IsReusable {
  get {
   return true;
  }
}
public void ProcessRequest (HttpContext context) {
  context.Response.ContentType = "image/jpeg";
  context.Response.Cache.SetCacheability(HttpCacheability.Public);
  context.Response.BufferOutput = false;
  PhotoSize size;
  switch (context.Request.QueryString["Size"]) {
   case "S":
    size = PhotoSize.Small;
    break;
   case "M":
    size = PhotoSize.Medium;
    break;
   case "L":
    size = PhotoSize.Large;
    break;
   default:
    size = PhotoSize.Original;
    break;
  }
  Int32 id = -1;
  Stream stream = null;
  if (context.Request.QueryString["PhotoID"] != null context.Request.QueryString["PhotoID"] != "") {
   id = Convert.ToInt32(context.Request.QueryString["PhotoID"]);
   stream = PhotoManager.GetPhoto(id, size);
  } else {
   id = Convert.ToInt32(context.Request.QueryString["AlbumID"]);
   stream = PhotoManager.GetFirstPhoto(id, size);
  }
  if (stream == null) stream = PhotoManager.GetPhoto(size);
  const int buffersize = 1024 * 16;
  byte[] buffer = new byte[buffersize];
  int count = stream.Read(buffer, 0, buffersize);
  while (count > 0) {
   context.Response.OutputStream.Write(buffer, 0, count);
   count = stream.Read(buffer, 0, buffersize);
  }
}
}


*.aspx:
img src="myHttpHander.ashx?id=123" width="20" height="20" />

我們變通以下,發現其實除了可以輸出圖片以外,還可以輸出文字:
Handler.ashx:

復制代碼 代碼如下:

%@ WebHandler Language="C#" Class="Handler" %>
using System;
using System.Web;
public class Handler : IHttpHandler {

    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";
        context.Response.Write("alert('hi')");
    }

    public bool IsReusable {
        get {
            return false;
        }
    }
}


*.aspx:
彈出alert
script src="Handler.ashx">/script>
也可以把.ashx當成css文件
link href="css/Handler.ashx" rel="stylesheet" type="text/css">

xml文件
orderDoc.load("Handler.ashx");

還可以嵌入文字:
Handler.ashx:

復制代碼 代碼如下:

%@ WebHandler Language="C#" Class="TestHandler" %>
using System;
using System.Web;
public class TestHandler : IHttpHandler {

    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";
        context.Response.Write("document.write(\"Hello World\");");
    }

 

    public bool IsReusable {
        get {
            return false;
        }
    }
}


*.aspx:
script type="text/javascript" src="TestHandler.ashx" />

當你希望從ashx或HttpHandler里訪問你的Session時,你必須實現IReadOnlySessionState接口.

代碼:

復制代碼 代碼如下:

using System;
using System.Web;
using System.Web.SessionState;

public class DownloadHandler : IHttpHandler, IReadOnlySessionState
{
   public bool IsReusable { get { return true; } }

   public void ProcessRequest(HttpContext ctx)
   {
       ctx.Response.Write(ctx.Session["fred"]);
   }
}


其實,學習的思路不應該這樣,以上除了圖片外,我們都用偏了,為什么用偏了呢,因為軟件以簡單、實用為主,我們只是把以上純粹看成可一項技術而沒有把它放到軟件的地位去考慮:)
具體的用途,大家可以參考Rewirte.dll (這個dll,可以使服務器支持偽靜態的)

您可能感興趣的文章:
  • ashx中使用session的方法(獲取session值)
  • ASP.NET ASHX中獲得Session的方法
  • Asp.net在ashx文件中處理Session問題解決方法
  • 在ashx文件中使用session的解決思路
  • ashx介紹以及ashx文件與aspx文件之間的區別
  • aspx與ascx,ashx的用法總結
  • 后綴為 ashx 與 axd 的文件區別淺析
  • 基于.NET中:自動將請求參數綁定到ASPX、ASHX和MVC的方法(菜鳥必看)
  • *.ashx文件不能訪問Session值的解決方法

標簽:綿陽 焦作 曲靖 新疆 延安 黃南 大興安嶺 宜春

巨人網絡通訊聲明:本文標題《ashx文件的使用小結》,本文關鍵詞  ashx,文件,的,使用,小結,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《ashx文件的使用小結》相關的同類信息!
  • 本頁收集關于ashx文件的使用小結的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 莱芜市| 托克托县| 安平县| 巨野县| 清丰县| 科尔| 塔河县| 兰坪| 九龙县| 淮北市| 永善县| 麦盖提县| 广昌县| 紫金县| 龙南县| 封丘县| 杂多县| 凉城县| 固阳县| 岳池县| 通渭县| 曲麻莱县| 松江区| 乌海市| 台山市| 兰溪市| 江城| 全椒县| 玉门市| 秦皇岛市| 谷城县| 佛教| 佛山市| 昭苏县| 沿河| 芷江| 阿拉尔市| 双牌县| 唐河县| 浮山县| 仪征市|