DsJian.Mvc/Routing/RouteCollectionExtensions.cs

(完整代码) 1KB

// ================================================
// RouteCollectionExtensions.cs
// Copyright (C) 2010 Benking
// mail:ben.wangzj@gmail.com
// website:http://www.dsjian.com/
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// ================================================

using System.Web.Routing;

namespace DsJian.Mvc.Routing
{
    public static class RouteCollectionExtensions
    {
        public static string GetUrl(this RouteCollection routes, RequestContext context, string route, object values)
        {
            VirtualPathData pathData = routes[route].GetVirtualPath(context, new RouteValueDictionary(values));
            string path = "";

            if (pathData != null)
            {
                path = pathData.VirtualPath;

                if (!path.StartsWith("/"))
                    path = "/" + path;

                string appPath = context.HttpContext.Request.ApplicationPath;

                if (!path.StartsWith(appPath))
                    path = appPath + path;
            }

            return path;
        }
    }
}

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。