0

我有一個路由配置文件,我試圖路由遵循公式.com/{a page}/{子頁面}的所有URL,以路由到特定頁面.com /默認/ Page.aspx。我的問題是,它爲所有頁面(即,.com/Account/Login.aspx)都這樣做。是否有一種方法可以指定我希望它只有在用戶將其輸入地址欄時才能發送到該頁面?只有當他們離開了.aspx擴展這是我到目前爲止有:ASP.NET路由所有頁面

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using Microsoft.AspNet.Membership.OpenAuth; 
using System.Web.Routing; 
using Microsoft.AspNet.FriendlyUrls; 

namespace CouponsForGiving 
{ 
    public static class RouteConfig 
    { 
     public static void RegisterRoutes(RouteCollection routes) 
     { 
      routes.Ignore("{resource}.axd/{*pathInfo}"); 
      routes.MapPageRoute("LearnMore", "LearnMore", "~/LearnMore.aspx"); 
      routes.MapPageRoute("DefaultPage", "{nponame}", "~/Default/NPOPage.aspx"); 
      routes.MapPageRoute("CampaignPage", "{nponame}/{campaignname}", "~/Default/CampaignPage.aspx"); //This one routes a lot of other pages 
      routes.EnableFriendlyUrls(); 
     } 
    } 
} 

感謝這裏

回答

0

問題與路由的首要如果有2種途徑與相同數量的!參數,如果沒有硬編碼值,則會始終考慮聲明的第一個路由。例如,如果註冊了以下2個路由,則

routeCollection.MapPageRoute("LearnMore", "{param1}/{param2}", "~/About.aspx"); 
routeCollection.MapPageRoute("DefaultPage", "{param3}/{param4}", "~/Account/Login.aspx"); 

在上面的例子中,LearnMore路由只會被視爲有效的請求About.aspx頁面。

你可以這樣做如下:

routeCollection.MapPageRoute("LearnMore", "learnmore/{param1}/{param2}", "~/About.aspx"); 
routeCollection.MapPageRoute("DefaultPage", "default/{param3}/{param4}", "~/Account/Login.aspx"); 

這將重定向到相應的頁面。有關URL路由的更多詳細信息,您可以瀏覽以下URL。

http://karmic-development.blogspot.in/2013/10/url-routing-in-aspnet-web-forms-part-2.html

感謝&問候, Munjal

+0

好了,但我的問題是,當我點擊我的網站的鏈接,比如一個登錄真實重定向。 – Jack

+0

老兄,你能不能請精心處理你的問題?我在上述評論中沒有得到你的觀點。 –