简体   繁体   中英

Need to understand short ASP.NET source code

I am maintaining a customer Classic ASP website, and some ASP.NET code was found in a specific place.

I need someone to help me understand the meaning of each line, because I will have to replace this ASP.NET code with Classic ASP functions.

From my understanding, here is what the code performs :

  1. Get the Request.QueryString url , and put it into a variable named str
  2. Redirect (send a HTTP 302) to the Url-Decoded value of str

I would be sure not missing anything else. Is my understanding full and complete ?

Thank you all .NET folks :)

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

using System;
using System.Web;

public class GenericHandler1 : IHttpHandler {

    public void ProcessRequest (HttpContext context) {
        string str = context.Request.QueryString.Get("url");
       // context.Response.Redirect( context.Server.UrlDecode(str));
        HttpContext.Current.Response.Redirect(context.Server.UrlDecode(str), false);
    }

    public bool IsReusable {
        get 
        {
            return false;
        }
    }

}

Your understanding is correct. This is a simple HTTP Handler that decodes URLs and redirects the request to the decoded location.

This is not strictly required in many modern sites but it is a hack that can simplify interpreting url parameters if your site does a lot of it from first principals or in scenarios where you believe the original parameters might be double encoded.

To fully replicate the implementation, you probably don't need to replicate this code at all, not in a global sense. Instead look into the web.config or global.asax.cs or if this is more recent look for startup.cs in one of those files should be the registration for this handler, look for any references to GenericHandler1 . When you find that code, you will have found the rest of the implementation detail that you may need to consider implementing.


This is a strange thing to ask, "replicate an ASP.Net website in classic ASP" . I'm sure you have your business reasons, but have you instead considered upgrading to an OWIN implementation, perhaps with ASP.Net Core ? This is usually the easier option if your requirement is to deploy to non IIS host.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM