Chris Worfolk's Blog


ASP.net url rewriting

July 16th, 2004 | Life

Perhaps the thing about Robert Hess and involving pictures and stuff is a pipe stream. I plan to do it tommorow but seen as tommorow is like 12 minutes away as I write I mean tommorow tommorow not just tommorow literally. Still, I may just be telling myself that I will do it tommorow and never actually get round to hit. Who can say what the future will bring?

I have spent most of the night trying to get an ASP.net url rewriting thing to work. Why oh why it couldn’t be simple like Apache’s mod_rewrite I will never know although I couldn’t get that working and resorted to using forcetype instead at the end so not much of a starter really. I tried to use the demos out of the box as it were though too with no success.

Anyway for those crazy enough to follow in my footsteps here are some useful web links:

http://www.codeproject.com/aspnet/URLRewriter.asp?select=867132&df=100&forumid=4228&exp=0
http://www.15seconds.com/issue/030522.htm
http://www.15seconds.com/issue/020417.htm
http://msdn.microsoft.com/asp.net/community/authors/scottmitchell/default.aspx?pull=/library/en-us/dnaspp/html/urlrewriting.asp

Hope you have more sucess than I did, if so, email me your code! 😉

My exact double

July 13th, 2004 | Life

I was just watching the episode of the Simpsons where Homer gets chucked out of Moe’s and Marge is scared of flying. I managed to get a quality photo of Homer’s exact double :). That will provide some nice entertainment when I am next flicking through what is contained on my compact flash card. Out of interest they are bringing out a 2GB one soon!

I did have point for this post previously but I can’t rememer now – it was a few days ago that I had the idea and I wanted to space it out between the Antitrust. Ah well, how about writing about writing about how Craig disappeared – there is a topic for you rawpulse. Anyway I like these posts to have a point that can be found on a search engine lol so today’s problem is when we were trying to log in on the Chain of Addiction forum we got page cannot be displayed error.

The solution? Yeah I knew you would come clicking. Anyway the problem was in the configuration of the board. To solve it, go into the admin panel and click on configuration and check the domain and folder path. Hope it works!

A point about Antitrust

July 12th, 2004 | Life

Antitrust maybe many things, the one I am refering to is the movie. For those of us in the UK it was on Channel 5 last Thursday. It was quite a good movie too. The basic plot was Milo is brought into NERV, a huge computer software company that everybody hates and is getting hit with antitrust lawsuits. Anyway the point is, to complete Synapse their latest project which will link every device in the world together they need really good code.

Milo is brought into the company to  help although the only real way they can do it is to kill the worlds best coders, make it look like a themed attack such as racial, etc and then steal the developers code. It is working pretty well until Milo stumbles onto the plan and makes the source code publically available.

The point is though that this movie came out in 2001 and was likely to have been writen in 2000. And what have Microsoft done between then and now. Unveiled, the Dot Net initiative, an XML platform which allows every device to communicate with each other. Seeing the connection?

Tis a new day

July 12th, 2004 | Life

Well who would have thought we could sustain interest for more than 24 hours? Ah well we have like an hour to spill out in ICT although we could do to get some law revision done. Anyway I have loads to post but have stuff to do now. Back later.

MySQL Timestamp

July 11th, 2004 | Life

Although officially I hate PHP, date() is pretty cool. The thing is that PHP uses a different timestamp format to the standard MySQL timestamp. Therefore the majority of timestamps stored in MySQL are actually stored as intergers. Or at least this is how phpBB do it. And that is how my latest site does it. But enough about quick plugs. What’s happening here?

Ah right, the thing about MySQL timestamp is that it updates to the current time everytime you update the column. Therefore when I had to make a change to the database to set a post to a different user, it updated the timestamp and moved the post to the top. Hmm, I posted this, maybe it evens it out or at least dislodges it from the top.

So, Malcolm in the Middle has just ended. Ok, here I am just trying to fill out space. Here’s a picture of Fonze again:

Remind you of anyone? Ayyyyy!

Resource album added to the site

July 11th, 2004 | Life

Hu, I lasted about 20 minutes. Not unexpected though really. I am still exploring the features of the site. On the left of the main page you can see a link called albums at the bottom, below the about link. This offers you the chance to see all our albums (well currently 1) and all the photos within these albums (again, 1). Enjoy!

I can add resources to posts apparently too, so if you go on the full link or permalink or whatever it’s called you should be able to see the full resource.

Or, if you are already on this page, you should be able to see it below ;):

Remind you of anyone? Ayyyyy!

Domain propogation time

July 11th, 2004 | Life

It would be cool if domains propogated faster – like instantly :). There is nothing worse than waiting around for them especially considering that they take anywhere from 12 to 48 hours. It will be good once Nerd Federation is officially back at the point we can start spreading the URL around again. Ah well, the time should come soon.

Time for today is publishing on and I really should start law revision but I am finally making visible process on my new site. It has an intergrated forum and I am moving towards finishing the posting and editing section then I only have the move topics section and the forum code guide and editor. Oh, its going to be a long night / a long week.

Remember exit() after location

July 11th, 2004 | Life

Well best get started with the random tips and information. One thing I am not happy about is this editor tells me I am using Verdana 8px, but when it comes out in the page it is Times New Roman! The blow is slightly cushioned for myself however as my browser, Beonex, uses Arial as the default font. A nice bit of scripting in the editor though means it is not compatable with Beonex – neither is vBulletin!

So before the moans side tracked me, I was getting into my story. Having started doing some stuff in PHP to make sure of forcetype and stats on subdomains (just wait until I get an ASP.net rewrite engin!) I found a few helpful bits of information that spent much time annoying me and ended up really simple. Most notably, not remember == for comparissions.

One other thing I noticed is that although you can redirect a user using the header location tag, it doesn’t actually stop the PHP script running. So the user may have been sent elsewhere but the thing they were not allowed to do and you had throught been stopped doing it because of the header location code you added, is still actually being done. It’s easy to fix though, all you need is:

Header ("Location: whateverpage.php");
Exit ();

Hmm, yet another over complication of PHP if you ask me. Still I’m kind of on a high right now as this editor is pretty cool. It has some quite extensive image adding features and plenty of HTML options. I give it my offical stamp of "neeto!" Well, I will probably be able to keep myself away for like an hour at tops, see you then.

Nerd Federation is back!

July 11th, 2004 | Life

After a long talk with everyone else involved in Nerd Federation (well, less of a talk, more of I am going to tell them later), Nerd Federation has been brought back online but these time as somewhat of a blog portal. That said none of you lower scum will be posting ;). It’s pretty much just myself, Ceon and Rawpulse that get to post entries, though the rest of you can post comments.

Random subjects are always cool and that’s the best thing about a blog. You can just come on and make a post pretty much about anything and yet you still don’t end up with the pointless comments and discussions that you often find on forums, indeed that you used to find on the Nerd Federation forum. If you can find your way past the entry portal page that is!

So prepare to be overwhelmed by fun as we post random comments that just make no sense…

Accessing MySQL with ASP

December 30th, 2003 | Programming, Tech

Being an active server page coder by nature, all my sites are in ASP. So eventually I hit a problem – two sites want to use the same Access database but they are on different hosts. Therefore I decided it would be best to use a MySQL database that they could share by making remote connections.

Why use MySQL?

The main advantage is as I have already mentioned, having a central MySQL database allows you to connect all your sites directly to it and access the information. There are ways to do this in Microsoft Access but they are patchy at best. The other option would be to use MS SQL server although this doesn’t come cheap from any host.

Changing the code

Let’s say for example I have a MySQL database on a linux hosting account at www.examplelinux.com. And I have a website at www.examplewindows.com that I want to connect with. Luckily connecting to MySQL is similar to any other connection except we just need to make a few changes.

The first is obvious; the connection script needs to be changed as we are accessing MySQL rather than an Access database. The second are certain changes in the scripts to make sure we don’t end up with any MySQL errors.

A typical DNS less connection would be something like:

Driver={Microsoft Access Driver (*.mdb)}; DBQ=" + Server.MapPath("/Conndb/springer1.mdb")

Whereas a connection to MySQL would look more like:

Driver={MySQL ODBC 3.51 Driver}; Server=examplelinux.com; Database=dbname; UID=username; PASS=password

To do this your server needs to have the MySQL driver on it. You can download it from http://www.mysql.com/downloads/index.html. You can also use a DNS connection if you have one which makes things considerably simpler:

DSN=linuxexampledns

All you need to do is replace the connection line you currently use with the new one modifying the username, password and name of the database you are going to use on your target server.

Further modifications

To make the ASP code work with MySQL there are a few other modifications you need to make with your code. The problem arises from the use of the ‘ character. Where Access is ok with it, MySQL will bring up a nice big error message.

Luckily a bit of PHP style code can come to the rescue. If you are familiar with PHP, you will know you can remove the significance of a character using \ before it. Therefore a quick replace function does the trick

Replace(string, "'", "\'")

So for instance a select command would go from:

SELECT * FROM hobbies WHERE firstname = '" + (users.Fields.Item("firstname").Value) + "' ORDER BY name ASC

And changed to:

SELECT * FROM hobbies WHERE firstname = '" + Replace((users.Fields.Item("firstname").Value) ,"'","\'") + "' ORDER BY name ASC

Setting up the server

Once the modifications to the code have been made you can get on with setting up the server to accept the requests. First of all you need to allow the scripts to access the database.

In CPanel goto MySQL Database and scroll down to access hosts: then add in the IP address of www.windowsexample.com. If you can’t find it out, simply run the scripts and it will bring you up an access denied message containing the IP address you are trying to access the database from.

In Direct Admin goto MySQL Databases, click on the database and then you can enter the IP address in to the access hosts form near the bottom. If you can access the privileges section in phpMyAdmin directly you can also do it from there as you can set for each user what access host the user can use.

The only other problem is getting the contents of your Access database to your MySQL server. The easiest way I found to do this way to set up a DNS connection to the MySQL server on my local machine, though you may be able to do this directly to the server providing you grant yourself access, and then going into Access and Exporting it.

File > Export then open the drop down menu at the bottom and and scroll to the bottom of the list until you see ODBC Databases (). This will close the export window and prompt you to enter the name of what you want to call it when you export it. Most likely it will be best to leave the default here.

Then it will come up with a box asking you to select a data source. Select the machine data source tab and find your DNS connection on the list then click ok and your done.

Conclusion

Switching your database from Access to MySQL is a hassle – you need a Linux server, code changes and connection scripts. However if your sites need to share a database its a far cheaper option that using MS SQL.