简体   繁体   English

需要了解简短的 ASP.NET 源代码

[英]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.我正在维护一个客户经典 ASP 网站,并且在特定位置找到了一些 ASP.NET 代码。

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.我需要有人帮助我理解每一行的含义,因为我必须用经典的 ASP 函数替换这段 ASP.NET 代码。

From my understanding, here is what the code performs :根据我的理解,以下是代码执行的操作:

  1. Get the Request.QueryString url , and put it into a variable named str获取 Request.QueryString url ,并将其放入名为str的变量中
  2. Redirect (send a HTTP 302) to the Url-Decoded value of str重定向(发送 HTTP 302)到strUrl-Decoded

I would be sure not missing anything else.我肯定不会错过任何其他东西。 Is my understanding full and complete ?我的理解完整吗?

Thank you all .NET folks :)谢谢所有 .NET 人 :)

<%@ 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.这是一个简单的 HTTP 处理程序,用于解码 URL 并将请求重定向到解码的位置。

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.这在许多现代网站中并不是严格要求的,但如果您的网站从第一主体或在您认为原始参数可能被双重编码的情况下执行了很多操作,则它是一种可以简化解释 url 参数的技巧。

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 .而是查看web.configglobal.asax.cs或者如果这些文件之一中的startup.cs是更新的查找应该是此处理程序的注册,请查找对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" .这是一个奇怪的问题, "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 ?我确定您有自己的业务原因,但您是否考虑过升级到 OWIN 实现,也许是使用ASP.Net Core This is usually the easier option if your requirement is to deploy to non IIS host.如果您的要求是部署到非 IIS 主机,这通常是更简单的选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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