GibbsUSA.net Blogs  

Wednesday, September 08, 2010

 Logon   Blogs Home   GibbsUSA.net Home  


Personal blog for C#- Real problems- Real solutions!   

Search:

Archives
 Home... 
 May 2008 (1) 
 August 2007 (2) 
 December 2006 (1) 
 October 2006 (5) 
 
10/26/2006 4:53 PM:  I closed the forum so the code is here...

GibbsUSA.net smilie: grim For security reasons, I have closed the GibbsUSA.net forum...so I am using this blog to post my own comments and observations related to C#...

Comments (0) >>> Print >>> EMail >>>

10/26/2006 4:49 PM:  ASP.NET Debug Error 0×8013134b

I recently had the following error when trying to debug (locally) an ASP.NET C# project given to me by a contractor...

Auto-attach to process "[2440] w3wp.exe" on machine "SERVER1" failed. Error code 0×8013134b.

The problem turned out to be that I had installed .NET 2.0 which had registered ASP.NET 2.0 on the web site I was trying to debug !

The solution was:

- Run IIS
- Select the site with the issues, right click and select Properties then click on the ASP tab
- Change the ASP.NET version from 2.x to 1.x


Comments (0) >>> Print >>> EMail >>>

10/26/2006 4:47 PM:  Remove HTML tags using Regular Expressions

Recently I needed to remove specific HTML tags from a string obtained from a database. The use of Regular Expressions made this a single line of code using the Replace functionality:

string output = Regex.Replace(input, @"</?(?i:meta|embed|script|frameset|frame|iframe|object|link)(.|\n)*?>", ""); 
This code removes the following HTML tags:

meta
embed
script
frameset
frame
iframe
object
link

As you can see, this is easily changed to reflect any tags that you may want removing!

God I love those Regular Expressions!!!


Comments (0) >>> Print >>> EMail >>>

10/26/2006 4:34 PM:  Making URLs search engine friendly

Here is an example of turning a querystring into a search engine friendly URL..

The URL comes from a search engine in the format:

www.gibbsusa.net/develop/rss/blogs/showblog_page-ID-8.aspx

The code converts this transparently to the following URL:

www.gibbsusa.net/develop/rss/blogs/showblog.aspx?ID=8

The following snippet comes from the global.asax file

protected void Application_BeginRequest(Object sender, EventArgs e)
{
	// code to make blogs search engine friendly
	HttpContext incoming = HttpContext.Current;
	string oldpath = incoming.Request.Path.ToLower();
	if(oldpath.ToLower().IndexOf("_page-")>0)
	{
		string pageRedirect = oldpath.Substring(oldpath.LastIndexOf("/")+1);
		pageRedirect = pageRedirect.Substring(0,pageRedirect.ToLower().IndexOf("_page"));
		// extract the items
		string qsItemsTemp = oldpath.Substring(oldpath.ToLower().IndexOf("_page-")+6);
		qsItemsTemp = qsItemsTemp.Substring(0,qsItemsTemp.ToLower().IndexOf(".aspx"));
		string[] qsItems = qsItemsTemp.Split('-');
		string theQString = "";
		for (int i=0;i<=qsItems.GetUpperBound(0);i++)
		{
			if (theQString.Length>0)
			{
				theQString += "&";
			}
			theQString += qsItems[i].ToString() + "=" + qsItems[i+1].ToString();
			i++;
		}
		incoming.RewritePath (pageRedirect + ".aspx?" + theQString); 
	}
	else

	{
		// Display path if it doesn’t contain _pageX.aspx
		incoming.RewritePath(oldpath );
	}
}



Comments (0) >>> Print >>> EMail >>>

10/26/2006 4:28 PM:  Trapping dangerous client input (eg. cross site script HTML)

With the 1.1 framework, Microsoft introduced the HttpRequestValidationException Class (see HttpRequestValidationException Class).

This exception is thrown when a potentially dangerous input string is received from the client.

To use this class, simply override the System.Web.UI.Page OnError event. For example, add the following code to your page...

protected override void OnError(EventArgs e)
{
	System.Exception theError = Server.GetLastError();

	if(theError.GetBaseException() is System.Web.HttpRequestValidationException )
	{
		System.Diagnostics.Debug.Assert(false);
		Response.Write("<hr><p align=center>BAD BOY!!! You are trying to insert HTML tags or XSS script to the field.<br>Please use the button below to remove the tags from your input!<br><br>Thank you...</p>");
		Response.Write("<p align=center><input type=button language=javascript value='<< BACK' onclick ='window.history.go(-1);'></p><hr>");
		Response.StatusCode = 200;
		Response.End();        
	}       
}


Comments (0) >>> Print >>> EMail >>>

 


CLR v2.0.50727.3053


Please see the site Terms And Conditions and the site Privacy Statement.
This entire web site (and the software contents therein) is Copyright © Chris Gibbs 2000-2010.
Any reproduction or copying is expressly forbidden without the prior consent of Chris Gibbs.
For more information, please contact the site WebMaster (WebMaster@GibbsUSA.net).