Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the ways to use ashx files

2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains the "what is the use of ashx files", the content of the explanation is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "what is the use of ashx files" bar!

When it comes to Ashx files, we think of http handler and image loading (we usually used ASPX or Webservice to do it before). The general practice is as follows:

Handler.ashx:

The copy code is as follows:

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:

We modify the following and find that we can output not only pictures but also text:

Handler.ashx:

The copy code is as follows:

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:

Eject alert

You can also think of .ashx as a css file

Xml file

OrderDoc.load ("Handler.ashx")

You can also embed text:

Handler.ashx:

The copy code is as follows:

Using System

Using System.Web

Public class TestHandler: IHttpHandler {

Public void ProcessRequest (HttpContext context) {

Context.Response.ContentType = "text/plain"

Context.Response.Write ("[xss_clean] (\" Hello World\ ");")

}

Public bool IsReusable {

Get {

Return false

}

}

}

* .aspx:

When you want to access your Session from ashx or HttpHandler, you must implement the IReadOnlySessionState interface.

Code:

The copy code is as follows:

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"])

}

}

Thank you for your reading, the above is the content of "what is the use of ashx files?" after the study of this article, I believe you have a deeper understanding of the use of ashx files, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report