Skip to content
Browse files

Rewrite URL

  • Loading branch information...
1 parent cf10dec commit fadccd74ac41be596fe5a46122de78d744bae6be @anvh committed Apr 7, 2012
Showing with 84 additions and 16 deletions.
  1. +68 −0 App_Code/Extract.cs
  2. +3 −5 App_Code/RewriteUrlClass.cs
  3. +3 −3 List.aspx
  4. +3 −3 News.aspx
  5. +1 −1 Site.master
  6. +1 −4 Styles/main.css
  7. +5 −0 Web.config
View
68 App_Code/Extract.cs
@@ -0,0 +1,68 @@
+using System;
+using System.Collections.Generic;
+using System.Web;
+
+/// <summary>
+/// Summary description for Extract
+/// </summary>
+public class Extract
+{
+
+ private static readonly string[] VietnameseSigns = new string[]
+ {
+
+ "aAeEoOuUiIdDyY",
+
+ "áàạảãâấầậẩẫăắằặẳẵ",
+
+ "ÁÀẠẢÃÂẤẦẬẨẪĂẮẰẶẲẴ",
+
+ "éèẹẻẽêếềệểễ",
+
+ "ÉÈẸẺẼÊẾỀỆỂỄ",
+
+ "óòọỏõôốồộổỗơớờợởỡ",
+
+ "ÓÒỌỎÕÔỐỒỘỔỖƠỚỜỢỞỠ",
+
+ "úùụủũưứừựửữ",
+
+ "ÚÙỤỦŨƯỨỪỰỬỮ",
+
+ "íìịỉĩ",
+
+ "ÍÌỊỈĨ",
+
+ "đ",
+
+ "Đ",
+
+ "ýỳỵỷỹ",
+
+ "ÝỲỴỶỸ"
+ };
+
+
+
+ public static string RemoveSign4VietnameseString(string str)
+ {
+
+ //Tiến hành thay thế , lọc bỏ dấu cho chuỗi
+
+ for (int i = 1; i < VietnameseSigns.Length; i++)
+ {
+
+ for (int j = 0; j < VietnameseSigns[i].Length; j++)
+
+ str = str.Replace(VietnameseSigns[i][j], VietnameseSigns[0][i - 1]);
+
+ }
+
+ return str;
+
+ }
+
+ public static string format(string title){
+ return RemoveSign4VietnameseString(title).Replace(" ", "-");
+ }
+}
View
8 App_Code/RewriteUrlClass.cs
@@ -23,14 +23,12 @@ private static void Context_BeginRequest(object sender, EventArgs e)
string url = httpApplication.Request.RawUrl.ToLower();
// Nếu là Url ảo như sau"
- if (url.Contains("/news"))
+ if (url.Contains("-new.aspx"))
{
- string[] temp = url.Split('-');
- temp = url.Split('/');
+ string[] temp = url.Split('/');
temp = temp[temp.Length-1].Split('-');
- string id = temp[0].Split('?')[1];
-
+ string id = temp[temp.Length - 2];
httpApplication.Context.RewritePath("Detail.aspx?id=" + id);
}
View
6 List.aspx
@@ -29,14 +29,14 @@ Tin mới
<tr>
<td width="200" rowspan="3">
<div class='frame'>
- <a href='<%# Server.HtmlDecode(Eval("Image") as string) %>'>
+ <a target="_blank" href="<%# Extract.format(Server.HtmlDecode(Eval("Title") as string))%>-<%# Eval("id")%>-new.aspx" style="color:Black;">
<img src="<%# Server.HtmlDecode(Eval("Image") as string) %>" width="190px" height="140px">
</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div>
</td>
<td width="10px"></td>
<td height="6px" valign="top" style="font-size:13pt;font-weight:bold;">
- <a target="_blank" style='color:black;' href="News.aspx?<%# Eval("id")%>-<%# Server.HtmlDecode(Eval("Title") as string).Replace(" ","-") %> " >
+ <a target="_blank" href="<%# Extract.format(Server.HtmlDecode(Eval("Title") as string))%>-<%# Eval("id")%>-new.aspx" style="color:Black;">
<%# Server.HtmlDecode(Eval("Title") as string) %>
</a>
</td>
@@ -53,7 +53,7 @@ Tin mới
<tr>
<td></td>
<td valign="bottom" align=right>
- <div style='margin-top:-5px;margin-bottom:-5px;'>... <a target="_blank" href="News.aspx?<%# Eval("id")%>-<%# Server.HtmlDecode(Eval("Title") as string).Replace(" ","-") %>" > Chi tiết</a></div>
+ <div style='margin-top:-5px;margin-bottom:-5px;'>... <a target="_blank" href="<%# Extract.format(Server.HtmlDecode(Eval("Title") as string))%>-<%# Eval("id")%>-new.aspx" style="color:Black;"> Chi tiết</a></div>
<hr/>
</td>
</tr>
View
6 News.aspx
@@ -28,14 +28,14 @@ Tin tức
<tr>
<td width="200" rowspan="3">
<div class='frame'>
- <a target="_blank" href="news-<%# Eval("id")%>-<%# Server.HtmlDecode(Eval("Title") as string).Replace(" ","+") %>" style="color:Black;">
+ <a target="_blank" href="<%# Extract.format(Server.HtmlDecode(Eval("Title") as string))%>-<%# Eval("id")%>-new.aspx" style="color:Black;">
<img src="<%# Server.HtmlDecode(Eval("Image") as string) %>" width="190px" height="140px">
</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div>
</td>
<td width="10px"></td>
<td height="6px" valign="top" style="font-size:13pt;font-weight:bold;">
- <a target="_blank" href="news-<%# Eval("id")%>-<%# Server.HtmlDecode(Eval("Title") as string).Replace(" ","+") %>" style="color:Black;">
+ <a target="_blank" href="<%# Extract.format(Server.HtmlDecode(Eval("Title") as string))%>-<%# Eval("id")%>-new.aspx" style="color:Black;">
<%# Server.HtmlDecode(Eval("Title") as string) %>
</a>
</td>
@@ -52,7 +52,7 @@ Tin tức
<tr>
<td></td>
<td valign="bottom" align=right>
- <div style='margin-top:-5px;margin-bottom:-5px;'>... <a target="_blank" href="Detail.aspx?id=<%# Eval("id")%>&title=<%# Server.HtmlDecode(Eval("Title") as string).Replace(" ","+") %>" style="color:Black;"> Chi tiết</a></div>
+ <div style='margin-top:-5px;margin-bottom:-5px;'>... <a target="_blank" href="<%# Extract.format(Server.HtmlDecode(Eval("Title") as string))%>-<%# Eval("id")%>-new.aspx" style="color:Black;"> Chi tiết</a></div>
<hr/>
</td>
</tr>
View
2 Site.master
@@ -12,7 +12,7 @@
<meta name="copyright" content="Bản quyền © 2012 Công ty TNHH TM-DV xây dựng vận tải Thiên Việt"/>
<meta name="Designer" content="LamPV"/>
<meta name="keywords" content="van chuyen hang, van chuyen hang hoa, cong ty van tai, cong ty van chyen, dich vu van chuyen, van tai,
- vận chuyển hàng, vận chuyển hàng hóa, công ty vẩn tải, công ty vận chuyển, dịch vụ vận chuyển, vận tải"/>
+ vận chuyển hàng, vận chuyển hàng hóa, công ty vận tải, công ty vận chuyển, dịch vụ vận chuyển, vận tải"/>
<title>
<asp:ContentPlaceHolder ID="HeadContent" runat="server"></asp:ContentPlaceHolder>
View
5 Styles/main.css
@@ -6,11 +6,8 @@ body{
a{
text-decoration:none;
- color:orange;
-}
-a:hover{
-color:#FF8C00
}
+
.menu{
background-image:url('../Images/menu_nav.png');
height:55px;
View
5 Web.config
@@ -17,6 +17,11 @@
</credentials>
</forms>
</authentication>
+ <httpModules>
+ <!-- BEGIN: MY URL REWRITE -->
+ <add name="MyUrlRewriter" type="RewriteUrlClass" />
+ <!-- END: MY URL REWRITE -->
+ </httpModules>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>

0 comments on commit fadccd7

Please sign in to comment.
Something went wrong with that request. Please try again.