50 lines
1.6 KiB
C#
50 lines
1.6 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Web;
|
||
|
||
namespace VRS
|
||
{
|
||
public class QueryStringModule : IHttpModule
|
||
{
|
||
public void Init(HttpApplication context)
|
||
{
|
||
context.BeginRequest += Context_BeginRequest;
|
||
}
|
||
|
||
private void Context_BeginRequest(object sender, EventArgs e)
|
||
{
|
||
HttpApplication application = (HttpApplication)sender;
|
||
HttpContext context = application.Context;
|
||
HttpRequest request = context.Request;
|
||
HttpResponse response = context.Response;
|
||
|
||
// 假设我们要处理的querystring参数名为"id"
|
||
string compress = request.QueryString["compress"];
|
||
|
||
if (!string.IsNullOrEmpty(compress))
|
||
{
|
||
// 这里可以添加处理id的逻辑
|
||
// ...
|
||
|
||
// 如果需要重定向到一个新的URL,可以这样做
|
||
// response.Redirect("newurl?param=" + id);
|
||
|
||
// 如果需要修改querystring参数,可以这样做
|
||
// context.RewritePath("page.aspx?param=" + id);
|
||
|
||
if ( !Int32.TryParse(compress,out int temp))
|
||
{
|
||
// var strURL = request.RawUrl + "&compress=" +"1";
|
||
var strURL = request.RawUrl.Replace("compress="+ compress, "compress=1");
|
||
response.Redirect(strURL);
|
||
}
|
||
}
|
||
}
|
||
|
||
public void Dispose()
|
||
{
|
||
// 清理代码,如果有必要的话
|
||
}
|
||
}
|
||
} |