using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
namespace Utility.Helper
{
/// <summary>
/// App操作类
/// </summary>
public static class UrlAppHelper
{
public static string Url
{
get
{
if (HttpContext.Current.Request.Url.Port == 80)
return "http://" + HttpContext.Current.Request.Url.Host;
else
return "http://" + HttpContext.Current.Request.Url.Host + ":" + HttpContext.Current.Request.Url.Port;
}
}
/// <summary>
/// 应用程序路径,以/结尾
/// </summary>
/// <returns>如:/,/cms/</returns>
public static string Path
{
get
{
string _ApplicationPath = System.Web.HttpContext.Current.Request.ApplicationPath;
if (_ApplicationPath != "/")
_ApplicationPath += "/";
return _ApplicationPath;
}
}
}
}
本文介绍了一个简单的.NET实用工具类,用于获取当前应用程序的URL和路径信息。该工具通过读取HTTP上下文来确定应用是否运行在默认端口,并据此构造正确的URL。此外,还提供了一个方法来获取应用程序的根路径,并确保路径总是以斜杠(/)结尾。
442

被折叠的 条评论
为什么被折叠?



