⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 common.cs

📁 具有一般blog的相册、文章、作品等功能程序结构也比较清晰采用三层结构开发(利用了SQLHelper.cs(源码))采用了UrlReWrite技术后台采用FTB(FreeTextBox)编辑器
💻 CS
字号:
using System;
using System.Web;
using System.Text.RegularExpressions;

namespace liuwei.FrameWork
{
	/// <summary>
	/// 摘要说明。
	/// </summary>
	public class Common
	{
		public Common()
		{
			//
			// TODO: 在此处添加构造函数逻辑
			//
		}
		public static string GetUserIpAddress(HttpContext context)
		{
			string result = String.Empty;
			if (context == null) return result;

			result = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
			if (null == result || result == String.Empty)
				result = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];

			return result;
		}

		public static string CheckForUrl(string text)
		{
			
			if(text == null || text.Trim().Length == 0 || text.Trim().ToLower().StartsWith("http://"))
			{
				return text;
			}
			return "http://" + text;
		}

		public static string SafeFormat(string stringToTransform) 
		{
			stringToTransform = HttpContext.Current.Server.HtmlEncode(stringToTransform);

			return stringToTransform.Replace("\n", "<br>");
		}

		public static string SafeFormatWithUrl(string stringToTransform)
		{
			return EnableUrls(SafeFormat(stringToTransform));
		}

		public static string EnableUrls(string text)
		{
			string pattern = @"(http|ftp|https):\/\/[\w]+(.[\w]+)([\w\-\.,@?^=%&amp;:/~\+#]*[\w\-\@?^=%&amp;/~\+#])";
			MatchCollection matchs;
                        
			matchs = Regex.Matches(text,pattern, RegexOptions.IgnoreCase | RegexOptions.Compiled);
			foreach (Match m in matchs) 
			{
				text = text.Replace(m.ToString(), "<a target=\"_new\" href=\"" + m.ToString() + "\">" + m.ToString() + "</a>");
			}
			return text;			
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -