2010-03-24 13 views
5

öncesi süreç querystrings Biz e-posta yoluyla müşterilere kayıt URL'ler göndermek nasıl. e-posta istemcileri bazıları Kullanıcıların kendi üzerlerine hangi e-posta istemcisi yeniden formatlar Ör (belki) orijinal emüdahale ve Asp.Net

işaret e-posta iletmek zaman bu oluyor olabilir düşünüyorum

url <url> 

Url'nin dönüyor kodda ben bu örnekleri müdahale gereken yerde bir potansiyel olarak tehlikeli İstek.SorgulamaDizesi değeri

algılandı:

https://my.app.com/login.aspx?param=var

haklı System.Web.HttpRequestValidationException üretir

https://my.app.com/login.aspx?param=var%20%3Chttps://my.app.com/login.aspx?param=var%3E

Oldu kullanıcı uRL orijinal form üzerine yeniden yönlendirilir ve böylece ve uRL santize?

global.asax? Page_Init? HttpHandler? Boru Hattı?

cevap

2

Global Application_BeginRequest veya HttpModule aynı olay yakalayabilirsin.

Küresel

using System; 
using System.Web; 

namespace MassageIncomingRequestUrl 
{ 
    public class Global : HttpApplication 
    { 
     protected void Application_BeginRequest(object sender, EventArgs e) 
     { 
      var app = (HttpApplication) sender; 
      string path = app.Context.Request.Url.PathAndQuery; 
      int pos = path.IndexOf("%20%3C"); 
      if (pos > -1) 
      { 
       path = path.Substring(0, pos); 
       app.Context.RewritePath(path); 
      } 
     } 
    } 
} 

Modül

using System; 
using System.Web; 

namespace MassageIncomingRequestUrl 
{ 
    public class UrlMungeModule : IHttpModule 
    { 
     #region IHttpModule Members 

     public void Init(HttpApplication context) 
     { 
      context.BeginRequest += BeginRequest; 
     } 

     public void Dispose() 
     { 
      //nop 
     } 

     #endregion 

     private static void BeginRequest(object sender, EventArgs e) 
     { 
      var app = (HttpApplication)sender; 
      string path = app.Context.Request.Url.PathAndQuery; 
      int pos = path.IndexOf("%20%3C"); 
      if (pos>-1) 
      { 
       path = path.Substring(0,pos); 
       app.Context.RewritePath(path); 
      } 

     } 
    } 
} 

Bu isteğiniz olursa olsun tarayıcı adresinde gördükleriniz arasında, Request doğru sorgu dizesi ile işlenmiş alacak. Çöpü rapor edilen URL'den çıkarmak için ek adımlar atabilirsiniz, ancak bu sadece bir estetiktir.

+0

sayesinde bu deneyin verecek ... –

İlgili konular