I've posted a few code snippets and some people noticed that there are references to unresolved methods.I am using a few helper classes. This post describes my HttpRequestHelper class.
using System;
using System.Text.RegularExpressions;
using System.IO;
using System.Diagnostics ;
using System.Net;
namespace FSHelperLib
{
using System;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
/// <summary>
/// Summary description for HttpRequestHelper.
/// </summary>
public class HttpRequestHelper
{
// Methods
public HttpRequestHelper()
{
}
// from http://groups.google.com.au/groups?hl=en&lr=&threadm=oOiDc.121011%24Sw.26011%40attbi_s51&rnum=1
public static bool IsBrowserOnServer()
{
bool foundIPmatchFlag = false; // Assume no match
string userHostAddr= HttpContext.Current.Request.UserHostAddress;
string serverhost = Dns.GetHostName(); // get name of server
IPHostEntry ipserverhost = Dns.GetHostEntry(serverhost);// GetHostByName
IPAddress[] addresses = ipserverhost.AddressList; // get list
// Look for an IP address match
foreach ( IPAddress address in addresses )
{
if (userHostAddr == address.ToString())
{
foundIPmatchFlag = true; // got a match
break;
}
}
if(foundIPmatchFlag == false) //try more options in case if DNS is not working
{
if (userHostAddr == "127.0.0.1")
{
foundIPmatchFlag = true; // got a match
}
else
{
string userhostName=HttpContext.Current.Request.UserHostName;
userhostName=userhostName.ToLower();
if ( (userhostName== "localhost")||(userhostName== serverhost.ToLower()) )
{
foundIPmatchFlag = true; // got a match
}
}
}
return foundIPmatchFlag;
}
//created 15/4/2005
public static string HttpURL(string ServerName, string VirtualDirectory, string ServiceUrl)
{
return UriHelper.CombineUrl(HttpBaseUrl(ServerName, VirtualDirectory), ServiceUrl); //8/5/2006 use CombineUrl
}
/// <summary>
/// Returns BaseUrl(e.g. http://Server/VirtualDirectory/" including tailing "/"
/// </summary>
/// <param name="ServerName"></param>
/// <param name="VirtualDirectory"></param>
/// <returns></returns>
public static string HttpBaseUrl(string ServerName, string VirtualDirectory)
{
string sBaseUrl=string.Format("{0}/{1}/", ServerName,VirtualDirectory);
if(false==sBaseUrl.ToLower().StartsWith("http://"))
{
sBaseUrl="http://"+sBaseUrl;
}
return sBaseUrl;
}
}
}