2013-09-28 39 views
0

首先我很抱歉如果這個問題已經被問到,但我無法爲我的問題找到任何解決方案。 我正在使用ASP.NET 4.0 Wepforms網站,其中管理員將上傳圖片,並將其視爲帖子,如圖片博客。訪客可以使用fb評論評論每張圖片,並且可以喜歡它。目前iam使用每個帖子(圖片)的查詢字符串。但是現在我想讓每個網址都成爲SEO的好朋友。所以基本上我有兩個事情要處理:如何在ASP.NET 4.0中動態地製作SEO友好的無擴展網址webforms

  1. 使唯一網址爲每個圖片是管理員上傳,網址應該是它的標題,例如「www.example.com/posts/mexican-bulldog」一樣blogengine或nopCommerce。目前IAM使用下面的代碼在Global.asax中:

    void Application_Start(object sender, EventArgs e) 
        { 
          RegisterRoutes(RouteTable.Routes); 
    
        } 
        public static void RegisterRoutes(RouteCollection routeCollection) 
        { 
         routeCollection.MapPageRoute("RouteForCustomer", "Customer/{Id}", "~/Customer.aspx"); 
    
    
    
         routeCollection.MapPageRoute("RouteForHome", "home", "~/Default.aspx"); 
         routeCollection.MapPageRoute("RouteForTroll", "post", "~/post.aspx"); 
    }  
    

    上面的代碼沒有解決我的問題,在這我必須靜態分配的網址。

  2. 想要的職位之間進行導航即下一個和以前

thanx提前!

+0

要生成slug檢查了這一點:http://stackoverflow.com/questions/2920744/url-slugify-alrogithm-in-c添加編號1,2,3的邏輯獨特的slu depending取決於你現有的相似數量數據庫中的slu slu。 –

回答

1

請看看我剛剛按照您的要求實施的一種簡單方法。可能有更多的方法來做同樣的事情。

我創建了一個類:圖像

public class Images 
    {  
     public string CurrentImage { get; set; } 
     public string NextImage { get; set; } 
     public string PreviousImage { get; set; } 
     public string CurrentImagePhysicalName { get; set; } 
     public Images(string currentImagePhysicalName, string Current, string Next, string Previous) 
     { 
      this.CurrentImagePhysicalName = currentImagePhysicalName; 
      this.CurrentImage = Current; 
      this.NextImage = Next; 
      this.PreviousImage = Previous; 
     } 
    } 

註冊的路線,並在應用程序啓動時初始化圖像採集:

public class Global : HttpApplication 
    { 
     public static List<Images> col = new List<Images>(); 
     private void GetImages() 
     { 
      // Build this collection as per your requirement. This is just a sample. 
      // Logic is to store current, next, previous image details for current displaying image/page. 
      // Hope while storing image each will have unique name before saving and will have all details in db like path, display name, etc. 

      col.Add(new Images("orderedList0.png", "orderedList0", "orderedList1", "")); 
      col.Add(new Images("orderedList1.png", "orderedList1", "orderedList2", "orderedList0")); 
      col.Add(new Images("orderedList2.png", "orderedList2", "orderedList3", "orderedList1")); 
      col.Add(new Images("orderedList3.png", "orderedList3", "orderedList4", "orderedList2")); 
      col.Add(new Images("orderedList4.png", "orderedList4", "", "orderedList3")); 
     } 

     void Application_Start(object sender, EventArgs e) 
     { 
      GetImages();    
      RegisterRoutes(RouteTable.Routes); 
     } 

     public static void RegisterRoutes(RouteCollection routeCollection) 
     { 
      routeCollection.MapPageRoute("RouteForImage", "Posts/{Name}", "~/Posts.aspx"); 

     } 
} 

Posts.aspx

protected void Page_PreRender(object sender, EventArgs e) 
     { 
      string currentImage = RouteData.Values["Name"].ToString(); 
      if (!String.IsNullOrEmpty(currentImage)) 
      { 
       Images image = Global.col.Find(x => x.CurrentImage == currentImage); 
       // Get Current Image URL where actually it is stored using from image variable and render/set image path where you want to using image.CurrentImagePhysicalName 


       // Set Next - Previous Image urls 
       if (!String.IsNullOrEmpty(image.NextImage)) 
       { 
        hyperlink_next.Visible = true; 
        hyperlink_next.Text = image.NextImage; 
        hyperlink_next.NavigateUrl = GetRouteUrl("RouteForImage", new { Name = image.NextImage });      
       } 
       else 
        hyperlink_next.Visible = false; 

       if (!String.IsNullOrEmpty(image.PreviousImage)) 
       { 
        hyperlink_previous.Visible = true; 
        hyperlink_previous.Text = image.PreviousImage; 
        hyperlink_previous.NavigateUrl = GetRouteUrl("RouteForImage", new { Name = image.PreviousImage }); 
       } 
       else 
        hyperlink_previous.Visible = false; 
      } 
     } 

這僅僅是一個示例演示。這裏的主要想法是處理RouteData.Values["Name"].ToString()來處理動態網址。

希望這對你有用。

+0

thanx快速回復,似乎是對我的解決方案,實施後會讓你知道。 –