2013-07-10 50 views
1

使用ViewPath屬性時,我注意到它返回的URL大小與輸入的大小相同。例如,如果我的Views設置爲Views/Some/Path,那麼當某人在瀏覽器中輸入/some/path時,ViewPath將返回​​而不是~/Views/Some/PathWebFormView ViewPath大小寫

任何想法如何正確獲取該信息大寫?我只需要知道正在呈現的視圖,所以只要我能夠獲得正確的視圖路徑,我就可以接受其他想法。

回答

1

根據自己的路由到System.Web.Routing.Route的轉換路徑,在標題的情況下你可以寫,是這樣的:從here

public class LowercaseRoute : System.Web.Routing.Route 
{ 
public LowercaseRoute(string url, IRouteHandler routeHandler) 
    : base(url, routeHandler) { } 
public LowercaseRoute(string url, RouteValueDictionary defaults, IRouteHandler routeHandler) 
    : base(url, defaults, routeHandler) { } 
public LowercaseRoute(string url, RouteValueDictionary defaults, RouteValueDictionary constraints, IRouteHandler routeHandler) 
    : base(url, defaults, constraints, routeHandler) { } 
public LowercaseRoute(string url, RouteValueDictionary defaults, RouteValueDictionary constraints, RouteValueDictionary dataTokens, IRouteHandler routeHandler) 
    : base(url, defaults, constraints, dataTokens, routeHandler) { } 

public override VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary values) 
{ 
    VirtualPathData path = base.GetVirtualPath(requestContext, values); 
    TextInfo ti = new CultureInfo("en-US",false).TextInfo; 

    if (path != null) 
     path.VirtualPath = ti.ToTitleCase(path.VirtualPath); 

    return path; 
} 
} 

想法。