• Downloading from our site will require you to have a paid membership. Upgrade to a Premium Membership from 10$ a month today!

    Dont forget read our Rules! Also anyone caught Sharing this content will be banned. By using this site you are agreeing to our rules so read them. Saying I did not know is simply not an excuse! You have been warned.

Hướng dẫn rewrite url trong ASP.NET

Admin

Well-Known Member
Staff member
Administrator
Kỹ thuật rewrite URL là kỹ thuật dùng để che giấu url thật nhằm chống lại khả năng tấn công vào url.

Ví dụ: thật sự bạn cần đưa ra 1 url như sau:
(1) domain/?product.aspx?productID=123&ProductType=Hardware

Nhưng thực tế trên thanh địa chỉ của trình duyệt thì phải là:
(2) domain/Product/Hardware/123 chẳng hạn.

Lúc này RewiteURL đã làm cái việc chuyển đổi (2) -> (1) theo một quy tắc người lập trình quy định.

Ví dụ dưới kèm theo sẽ minh họa cách rewrite những Url aspx thành aspvn

Cách bước thực hiện như sau:

  1. Tạo 1 class có tên là RewriteUrlClass thừa kế từ IHttpModule
    Code:
    [COLOR=black][FONT=Courier New] [COLOR=blue]using[/COLOR] System;
     [COLOR=blue]using[/COLOR] System.Web;
      
     [COLOR=blue]public[/COLOR] [COLOR=blue]class[/COLOR] RewriteUrlClass : IHttpModule
     {
     [COLOR=blue]    #region[/COLOR] IHttpModule Members
      
         [COLOR=blue]public[/COLOR] [COLOR=blue]void[/COLOR] Dispose()
         {
         }
      
         [COLOR=blue]public[/COLOR] [COLOR=blue]void[/COLOR] Init(HttpApplication context)
         {
             context.BeginRequest += Context_BeginRequest;
         }
      
         [COLOR=blue]private[/COLOR] [COLOR=blue]static[/COLOR] [COLOR=blue]void[/COLOR] Context_BeginRequest([COLOR=blue]object[/COLOR] sender, EventArgs e)
         {
             HttpApplication httpApplication = (HttpApplication) sender;
             [COLOR=blue]string[/COLOR] url = httpApplication.Request.RawUrl.ToLower();
      
             [COLOR=green]// Nếu là Url ảo như sau"[/COLOR]
             [COLOR=blue]if[/COLOR] (url.Contains("/default.aspvn"))
             {
                 [COLOR=green]// Thì Url thực mà Server cần xử lý là:[/COLOR]
                 httpApplication.Context.RewritePath("Default.aspx");
             }
      
             [COLOR=green]// Nếu là Url ảo như sau"[/COLOR]
             [COLOR=blue]if[/COLOR] (url.Contains("/login.aspvn"))
             {
                 [COLOR=green]// Thì Url thực mà Server cần xử lý là:[/COLOR]
                 httpApplication.Context.RewritePath("Login.aspx");
             }
      
             [COLOR=green]// Tùy thuộc vào quy tắt Rewrite mà chúng ta xử lý.[/COLOR]
             [COLOR=green]// Một trong những cách hiệu quả nhất là dùng Regex Expression.[/COLOR]
      
         }
      
     [COLOR=blue]    #endregion[/COLOR]
     }
     [/FONT][/COLOR]
  2. Đăng kývào httpModules trong Web.config như dưới đây:

    Code:
    [COLOR=black][FONT=Courier New][COLOR=black][FONT=Courier New] [COLOR=blue]<[/COLOR]system.web[COLOR=blue]>[/COLOR]
     [COLOR=blue]        <[/COLOR]httpModules[COLOR=blue]>[/COLOR]
     [COLOR=blue]            <!--[/COLOR][COLOR=green] BEGIN: MY URL REWRITE [/COLOR][COLOR=blue]-->[/COLOR]
     [COLOR=blue]            <[/COLOR]add[COLOR=blue] [/COLOR][COLOR=red]name[/COLOR][COLOR=blue]=[/COLOR]"[COLOR=blue]MyUrlRewriter[/COLOR]"[COLOR=blue] [/COLOR][COLOR=red]type[/COLOR][COLOR=blue]=[/COLOR]"[COLOR=blue]RewriteUrlClass[/COLOR]"[COLOR=blue]/>[/COLOR]
     [COLOR=blue]            <!--[/COLOR][COLOR=green] END: MY URL REWRITE [/COLOR][COLOR=blue]-->[/COLOR]
     [COLOR=blue]        </[/COLOR]httpModules[COLOR=blue]>[/COLOR]
             .
             .
             .
     [/FONT][/COLOR]
      [/FONT][/COLOR]
        [COLOR=black][FONT=Courier New] [COLOR=blue]</[/COLOR]system.web[COLOR=blue]>[/COLOR]
    [/FONT][/COLOR]
  3. Chạy thử với các url có nằm trong quy tắc rewite RewriteUrlClass trong class có phần mở rộng là aspvn
Download tuoitreit.vn_RewiteUrlExample.zip (3.62 KB)
 

Facebook Comments

Similar threads
Thread starter Title Forum Replies Date
K Share Hướng Dẫn Mod Rewrite Url Cho Johncms Full All Shared Scripts 0
Admin Hướng dẫn rewrite url cho phpbb seo trên nginx VPS & Dedicated Server 0
C Help Ai thông tạo ReWrite URL WordPress giúp em với Wordpress 3
Admin Hướng dẫn mod rewrite url chuẩn cho wapka Wap builder, wapego, xtgem, wen.ru, wapka, wap4 0
Admin Hướng dẫn rewrite url cho wapka Wap builder, wapego, xtgem, wen.ru, wapka, wap4 0
V Hỏi Cần giúp về mod rewrite url Johncms 1
D Share Hướng dẫn mod Rewrite Url cho JohnCMS 4.4.0 Full Johncms 0
Admin Hướng dẫn mod rewrite url cho grab Johncms 0
Admin Share blog mod rewrite url for johncms Johncms 0
G [help] Rewrite url bằng .htaccess Chuyên đề htaccess 1
N Khắc phục lỗi mod thank khi sử dụngmod seo rewrite url Phpbb3x 0
X Mod Rewrite Url cho JohnCMS 4.4 Full Johncms 0
Admin Hướng dẫn mod Rewrite URL JohnCMS 4.4 Johncms 2
H Share mod sitemap rewrite cho john cms Johncms 0
Smobi Share Rewrite username tag sử dụng với tên thành viên Johncms 0
Admin Share mod rewrite profile johncms haycuc Johncms 0
Admin Tham khảo vài tham số trong mod rewrite của htaccess Chuyên đề htaccess 0
C URL OBFUSCATOR Tut, tool, mmo 0
cuongpro9x Share Link Download Premium URL Shortener All Shared Scripts 0
C Google URL Parser v4.0 Tut, tool, mmo 0
C MONSTER SQL MAP HELPER | VULERABLE URL GEN v0.1 Tut, tool, mmo 0
Admin [OzzModz] Remove Additional URL Fields From Resources Xenforo 0
Admin Upload Avatar From URL xenforo 2 Xenforo 0
N URL To Dork Converter & Parameter Converter Tool By PlusUltra SQL injection 1
N URL To Dork Converter & Parameter Converter Tool By PlusUltra SQL injection 0
N URL To Dork Converter & Parameter Converter Tool By PlusUltra SQL injection 0
N Share [ FREE ] EZ DORK SCANNER | Best Get URL Tools | WORKING 2020 Tut, tool, mmo 0
N Share All URL Grabber Hacking 0
N Share URL String Filter Hacking 0
N Ultimate URL ScraperSQLi Scanner Hacking 0
T Share Code TOOL MOD Game Java Full Qua Url PHP 3
G Hỏi [vbb] upload ảnh avatar qua url bị báo Access denied. Vbulletin 0
C Code Lấy Url Trực Tiếp Khi Upload Ảnh Lên Wapka Wap builder, wapego, xtgem, wen.ru, wapka, wap4 0
Admin Social Buttons with Short Share URL Vbb tutorial 0
Admin Hướng dẫn tạo url không dấu cho IPB PHP 0
Admin GoodForNothing Url Anonymizer/Redirector - Tạo trang chuyển tiếp xenforo Xenforo 0
Admin vt.Lai Url Khong Dau 1.2 | Url không dấu cho Xenforo 1.2 | SEO link không dấu XenForo Xenforo 0
Admin Thay đổi đường dẫn url xenforo với route changer Xenforo 0
Admin vt.Lai Url Khong Dau 1.0 | Url không dấu cho Xenforo 1.0 Xenforo 0
Admin Title Tag Fetcher (Auto Replace URL with Titletag) Add-ons 0
J Hỏi Zip bi loi url ae oi huhu Wap builder, wapego, xtgem, wen.ru, wapka, wap4 5
B [Bán] code filelist url thân thiện xgem Thảo luận wap việt 2
Admin vt.Lai VBB Unique Link 1.1 - Loại bỏ tham số ?p=*** trên url forum vBulletin Add-ons 1
Admin Hướng dẫn bỏ forum.php và index.php ở url triệt để Vbb tutorial 2
Admin Short.Url.Script.v2.1.PHP.NULL-DGT - Code rút gọn link Mã nguồn web 0
Admin Share url shortener script page v1.5 - code rút gọn link cool Mã nguồn web 2
blog4me 3 dịch vụ rút ngắn địa chỉ URL phổ biến hiện nay Thảo luận wap việt 0
Admin iTrader - Automatically add "Deal URL" to rating page Vbb tutorial 0
Admin Share mã nguồn tạo link rút gọn giống ****** - Premium URL Shortener Mã nguồn web 0
Admin Share zip ảnh hot girl part 2 93 pic 15,1 mb + link url Wap builder, wapego, xtgem, wen.ru, wapka, wap4 1

Similar threads

New posts New threads New resources

Back
Top