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 is the aspx extension method for ASP.NET pages?

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

Share

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

This article mainly explains the "ASP.NET page aspx expansion method is what", the article explains the content 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 "ASP.NET page aspx expansion method is what" it!

Demand: due to business expansion, a website needs to be split into another site, the new and old sites have the same content, but the specific columns are not the same. The original website has been running for many years, and there are a large number of pictures, which will also be used on the new site. The tasks are:

Make sure that the picture content of the two websites is synchronized, that is, the original site adds a picture, and the new site can use this picture.

Analysis: assume that the domain names of the two sites are http://www.a_image.com/ and http://www.b_image.com/ respectively

1. Copy the pictures to two servers respectively, and then upload the pictures to both servers at the same time. This method is simple, but it takes up a lot of disk space and is troublesome to maintain.

2. Write the handle of the https://cache.yisu.com/upload/information/20210521/332/489802.jpg resource request directly on the http://www.b_image.com/ page:

The Verb list can be a comma-separated list of HTTP predicates (for example, "GET,PUT,POST") or the wildcard character "*"; the path path property can contain a single URL path or a simple wildcard string (such as * .aspx); and type specifies a comma-separated class / assembly combination. ASP.NET first searches for assembly DLL in the application's private\ bin directory, and then searches for assembly DLL in the system assembly cache.

At the code level, to implement a custom HTTP handle, you only need to implement an IhttpHandler interface, including IsReusable and ProcessRequest methods. The IsReusable method is used to return information about whether there are reusable class entities in the application pool, which can serve multiple requests at the same time, while the ProcessRequest method accepts a HttpContext entity as a parameter to get access to Request and Response.

Idea: when a request for www.b_image.com/images/book.jpg reaches IIS, ASP.NET initializes an image generator class in which the www.a_image.com/images/book.jpg is fetched through the HTTP port and the image is streamed back to the HTTP response. Receiving and processing HTTP requests is done in the ProcessRequest method. The client doesn't know what's actually going on.

Code:

Using System; using System.Net; using System.IO; using System.Web; using System.Drawing; using System.Drawing.Imaging; namespace WebHttpModule {public class ImageLink: IHttpHandler {public void ProcessRequest (HttpContext context) {string url = context.Request.Url.ToString () / / if request is http://www.b_image.com/, then changed to request http://www.a_image.com/ urlurl = url.Replace ("http://www.b_image.com/"," http://www.a_image.com/"); / / if you use a relative path, manually add the full url path if ("http://www.a_image.com/")")

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