After a comment that an anonymous reader made I have revised and updated the ASP.NET Image Upload and Resize article. So BIG thanks to Anonymous for that one!
I''m struggling to finish the couple of posts i've started about recent activities so in absence of any real new content why not check out some of my other C# posts.
Tuesday, 26 August 2008
Monday, 11 August 2008
Photoshop CS3 (Wndows XP) Crashes when I open more than one document.
The last couple of weeks at work have been HELL! All of a sudden Photoshop started bombing out any time I tried to have more than one image open at a time.
If I opened 2 or more images at the same time... CRASH!
If I created two new images... CRASH!
If I created one image then opened another from disk... CRASH!
If I opened an image from disk then created a new one... CRASH!
Why? Because I'd recently deleted a printer and set a new one as my default.
I just reinstalled Photoshop.. still the same.
Simply changing the default printer however; That sorted it out...
Come on Adobe, such an amature piece of codeing... How can opening multiple documents rely on the default printer... sort it out!
Check out http://kb.adobe.com/selfservice/viewContent.do?externalId=kb402704
If I opened 2 or more images at the same time... CRASH!
If I created two new images... CRASH!
If I created one image then opened another from disk... CRASH!
If I opened an image from disk then created a new one... CRASH!
Why? Because I'd recently deleted a printer and set a new one as my default.
I just reinstalled Photoshop.. still the same.
Simply changing the default printer however; That sorted it out...
Come on Adobe, such an amature piece of codeing... How can opening multiple documents rely on the default printer... sort it out!
Check out http://kb.adobe.com/selfservice/viewContent.do?externalId=kb402704
Saturday, 2 August 2008
Saturday Morning: Website Security Time...
Recently a couple of our sites have been subject to SQL Injection Attacks but non have suffered so hard as the one I'm currently securing.
I spent all day yesterday on it and I've been up since 9AM when the head IT guy from our client called (and woke) me.
So after I get this thing done, and then enjoy what is left of my weekend I plan on writing up my learnings and educating my co-workers. Keep an eye out for a blog post or two.
I spent all day yesterday on it and I've been up since 9AM when the head IT guy from our client called (and woke) me.
So after I get this thing done, and then enjoy what is left of my weekend I plan on writing up my learnings and educating my co-workers. Keep an eye out for a blog post or two.
Monday, 21 July 2008
twentysix Leeds are recruiting again!
We're looking for a couple of graduate Flash monkeys/developers to come in and help us out on some top class work for about a 6 month period.
Applicants should be strong annimators with good ActionScript skills.
We're looking for people who can start ASAP!
So if you're in the Leeds area, rock Flash daily and want some high profile work at an ACE digital agency, then hit me up at greg.brant@twentysixleeds.com and check out our work. www.twentysixleeds.com
Applicants should be strong annimators with good ActionScript skills.
We're looking for people who can start ASAP!
So if you're in the Leeds area, rock Flash daily and want some high profile work at an ACE digital agency, then hit me up at greg.brant@twentysixleeds.com and check out our work. www.twentysixleeds.com
Shout out's...
Just a quick shout out to Gav who's just got his blog up and running by the looks of things.
Check out http://www.sublunary.co.uk/
And to the inyerface folks for another excellent production this Friday and Saturday at the Library Theater in Sheffield.
Check out http://www.sublunary.co.uk/
And to the inyerface folks for another excellent production this Friday and Saturday at the Library Theater in Sheffield.
Labels:
Friends,
Internet,
inyerface theatre company
Tuesday, 15 July 2008
PHP Search plugin link updated
We just moved offices (Photo's here and here) and as such some of our IP addresses changed.
I've recently had a couple of hits to the "Firefox PHP function search plugin" post. So I updated the link so you can now download it again. Sorry for the slight outage.
I've recently had a couple of hits to the "Firefox PHP function search plugin" post. So I updated the link so you can now download it again. Sorry for the slight outage.
Labels:
PHP,
Search Providers,
twentysix Leeds
Thursday, 26 June 2008
How to move the viewstate to the bottom of your page source (C# ASP.NET 2.0, 3.0, 2.5, Visual Studio 2005, Visual Studio 2008)
Last week one of our new SEO bod, Ryan, asked Sel to move the viewstate to the bottom of the page source for the rest assured site. This helps to improve your SEOness as a lot of search engines only take so much of your source into account when spidering. So you really don't want to be feeding them 32k of base64 encoded gibberish when you could be giving them some beautifully crafted copy!
Andy did a couple of Google's and found some code which did the trick perfectly.
This was ace and so today when I was asked to upload some ammends to a couple more of our clients sites I thought I would implement this for the same reasons as it only takes two seconds.
While it worked a treat on one of the sites, the other was not so good. Here's what the page should look like:
And here's what I got:

What has happened is this. The un-styled UL that you can see at the top of the page is the top half of the left hand navigation you can see in the 1st picture. This menu was implemented as a .NET user control and as such is treated like a page all of its own. The reason this happened is because the page was rendering out via our overridden method, but the control was not. So the HTML that the control generated was getting written to the output stream before the HTML of the Page ("Page" in the .NET Class sense, not the "web page" sense).
So this got me thinking, wouldn't it be nice to be able to have a single piece of code that could be applied to a site once, regardless of UserControls, MasterPages or any other intricacy, that would take care of moving the ViewState on every page of the site!?!
The answer: Yes!
The solution: an HttpModule...
An HttpModule is a piece of code that sits between your web application and IIS on the web server. What this module is going to do is intercept every response our application makes to a client and then, if the response is a HTML (read ASPX) page, look for and move the ViewState.
To do this we will filter the response stream using the Response.Filter property. I'll leave the full code until the end of the post but here are the main bits.
1) Create a new class that implements IHttpModule.
Andy did a couple of Google's and found some code which did the trick perfectly.
protected override void Render(System.Web.UI.HtmlTextWriter writer) {
System.IO.StringWriter stringWriter = new System.IO.StringWriter();
HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter);
base.Render(htmlWriter);
string html = stringWriter.ToString();
int StartPoint = html.IndexOf("<input type="hidden" name="__VIEWSTATE");
if (StartPoint >= 0) {
int EndPoint = html.IndexOf("/>", StartPoint) + 2;
string viewstateInput = html.Substring(StartPoint, EndPoint - StartPoint);
html = html.Remove(StartPoint, EndPoint - StartPoint);
int FormEndStart = html.IndexOf("</form>") - 1;
if (FormEndStart >= 0) {
html = html.Insert(FormEndStart, viewstateInput);
}
}
writer.Write(html);
}This was ace and so today when I was asked to upload some ammends to a couple more of our clients sites I thought I would implement this for the same reasons as it only takes two seconds.
While it worked a treat on one of the sites, the other was not so good. Here's what the page should look like:
And here's what I got:
What has happened is this. The un-styled UL that you can see at the top of the page is the top half of the left hand navigation you can see in the 1st picture. This menu was implemented as a .NET user control and as such is treated like a page all of its own. The reason this happened is because the page was rendering out via our overridden method, but the control was not. So the HTML that the control generated was getting written to the output stream before the HTML of the Page ("Page" in the .NET Class sense, not the "web page" sense).
So this got me thinking, wouldn't it be nice to be able to have a single piece of code that could be applied to a site once, regardless of UserControls, MasterPages or any other intricacy, that would take care of moving the ViewState on every page of the site!?!
The answer: Yes!
The solution: an HttpModule...
An HttpModule is a piece of code that sits between your web application and IIS on the web server. What this module is going to do is intercept every response our application makes to a client and then, if the response is a HTML (read ASPX) page, look for and move the ViewState.
To do this we will filter the response stream using the Response.Filter property. I'll leave the full code until the end of the post but here are the main bits.
1) Create a new class that implements IHttpModule.
public sealed class IHttpViewstateMover : IHttpModule {2) Add an event handler to the current request. This even then decides weather to add our filter to the response stream based on if it is outputting HTML.
public void Init (HttpApplication context) {
context.ReleaseRequestState += new EventHandler(context_ReleaseRequestState);
}
void context_ReleaseRequestState (object sender, EventArgs e) {
HttpResponse response = HttpContext.Current.Response;
if ( response.ContentType == "text/html" ) {
response.Filter = new ViewstateMover(response.Filter);
}
}
3) If the entire HTML file has been output ...
Regex eof = new Regex("</html>", RegexOptions.IgnoreCase);
if ( !eof.IsMatch(strBuffer) ) {
// code to follow...re-position the viewstate and output the altered HTML to the stream.
string finalHtml = _output_buffer.ToString();
int StartPoint = finalHtml.IndexOf("<input type="hidden" name="__VIEWSTATE");
if ( StartPoint >= 0 ) {
int EndPoint = finalHtml.IndexOf("/>", StartPoint) + 2;
string viewstateInput = finalHtml.Substring(StartPoint, EndPoint - StartPoint);
finalHtml = finalHtml.Remove(StartPoint, EndPoint - StartPoint);
int FormEndStart = finalHtml.IndexOf("</form>") - 1;
if ( FormEndStart >= 0 ) {
finalHtml = finalHtml.Insert(FormEndStart, viewstateInput);
}
}
byte[] data = UTF8Encoding.UTF8.GetBytes(finalHtml);
_output_stream.Write(data, 0, data.Length);Simple as!Now all you need to do us take the full code listing (below) and paste it into a C# file. Then add the following to your web.config inside the
// Source code for IHttpViewstateMover.cs
using System;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;
/// <summary>
/// IHttpViewstateMover is a HttpModule that moves the viewstate
/// to the bottom of the HTML source to help with SEO
/// </summary>
public sealed class IHttpViewstateMover : IHttpModule {
// the class is sealed so it cannot be inherited
public void Dispose () {
// nothing to dispose
}
public void Init (HttpApplication context) {
context.ReleaseRequestState += new EventHandler(context_ReleaseRequestState);
}
void context_ReleaseRequestState (object sender, EventArgs e) {
HttpResponse response = HttpContext.Current.Response;
// Uncomment the following line if you only want to recieve a single call to ViewstateMover.Write
// context.Response.Buffer = true;
if ( response.ContentType == "text/html" ) {
response.Filter = new ViewstateMover(response.Filter);
}
}
/// <summary>
/// ViewstateMover is the workhorse of the IHttpViewstateMover
/// </summary>
private class ViewstateMover : Stream {
// this class is private as it serves no real purpose outside this implementation
private Stream _output_stream;
private long _position;
private StringBuilder _output_buffer;
/// <summary>
/// Creates a new instance of the ViewstateMover class
/// </summary>
/// <param name="input_stream">The HttpResponse.Filter to work with</param>
public ViewstateMover (Stream input_stream) {
_output_stream = input_stream;
_output_buffer = new StringBuilder();
}
#region Stream Members
public override bool CanRead {
get { return true; }
}
public override bool CanSeek {
get { return true; }
}
public override bool CanWrite {
get { return true; }
}
public override void Close () {
_output_stream.Close();
}
public override void Flush () {
_output_stream.Flush();
}
public override long Length {
get { return 0; }
}
public override long Position {
get { return _position; }
set { _position = value; }
}
public override long Seek (long offset, SeekOrigin origin) {
return _output_stream.Seek(offset, origin);
}
public override void SetLength (long length) {
_output_stream.SetLength(length);
}
public override int Read (byte[] buffer, int offset, int count) {
return _output_stream.Read(buffer, offset, count);
}
#endregion
public override void Write (byte[] buffer, int offset, int count) {
string strBuffer = UTF8Encoding.UTF8.GetString(buffer, offset, count);
// check for the closing HTML tag
Regex eof = new Regex("</html>", RegexOptions.IgnoreCase);
if ( !eof.IsMatch(strBuffer) ) {
_output_buffer.Append(strBuffer);
} else {
_output_buffer.Append(strBuffer);
string finalHtml = _output_buffer.ToString();
// original code from http://www.hanselman.com/blog/MovingViewStateToTheBottomOfThePage.aspx
int StartPoint = finalHtml.IndexOf("<input type="hidden" name="__VIEWSTATE");
if ( StartPoint >= 0 ) {
int EndPoint = finalHtml.IndexOf("/>", StartPoint) + 2;
string viewstateInput = finalHtml.Substring(StartPoint, EndPoint - StartPoint);
finalHtml = finalHtml.Remove(StartPoint, EndPoint - StartPoint);
int FormEndStart = finalHtml.IndexOf("</form>") - 1;
if ( FormEndStart >= 0 ) {
finalHtml = finalHtml.Insert(FormEndStart, viewstateInput);
}
}
byte[] data = UTF8Encoding.UTF8.GetBytes(finalHtml);
// write the page countents out to the user
_output_stream.Write(data, 0, data.Length);
}
}
}
}As ever, the code is provided as is, with no kind of waranty so please test thoroughly before you place in a production environment. You use this code at your own risk.
Subscribe to:
Posts (Atom)