/*
Kooboo is a content management system based on ASP.NET MVC framework. Copyright 2009 Yardi Technology Limited.
This program is free software: you can redistribute it and/or modify it under the terms of the
GNU General Public License version 3 as published by the Free Software Foundation.
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.
You should have received a copy of the GNU General Public License along with this program.
If not, see http://www.kooboo.com/gpl3/.
*/
using System;
using System.Web;
using System.Web.Mvc;
using System.IO;
using System.Web.Hosting;
namespace Everest.Library.Web{
public class UrlConvertor
{
///// <summary>
///// Toes the absolute URL.
///// </summary>
///// <param name="url">The URL.</param>
///// <returns></returns>
//public static string ToAbsoluteUrl(string url)
//{
// if (!url.StartsWith("/"))
// {
// return "/" + url;
// }
// return url;
//}
public static string ResolveUrl(string url)
{
if (HttpContext.Current != null)
{
string applicationPath = HttpContext.Current.Request.ApplicationPath;
if (applicationPath == "/")
{
return url.Replace("~", "");
}
else
{
return url.Replace("~", applicationPath);
}
}
return url;
}
public static string MakeRelativeUrl(string url)
{
url = url.Replace("\\", "/");
if (url.StartsWith("~/"))
{
return url;
}
if (url.StartsWith("/"))
{
return "~" + url;
}
return "~/" + url;
}
/// <summary>
/// Pathes to URL.
/// </summary>
/// <param name="path">The path.</param>
/// <returns></returns>
public static string PathToUrl(string path)
{
return path.Replace("\\", "/");
}
/// <summary>
/// Absolutes the path to URL.
/// </summary>
/// <param name="absolutePath">The absolute path.</param>
/// <returns></returns>
public static string AbsolutePathToRelativeUrl(string absolutePath)
{
var relativePath = absolutePath.ToLower().Replace(AppDomain.CurrentDomain.BaseDirectory.ToLower(), "~/");
return PathToUrl(relativePath);
}
/// <summary>
/// Absolutes the path to absolute URL.
/// </summary>
/// <param name="absolutePath">The absolute path.</param>
/// <returns></returns>
public static string AbsolutePathToAbsoluteUrl(string absolutePath)
{
return ResolveUrl(AbsolutePathToRelativeUrl(absolutePath));
}
/// <summary>
/// Maps the path.
/// </summary>
/// <param name="path">The path.</param>
/// <returns></returns>
public static string MapPath(string path)
{
return HostingEnvironment.MapPath(path);
}
}
}
|