Tonight I wrote my first custom control. I was at a point with this project I am reworking a little bit, where I didn't want to have to create the same set of controls four times. I have no idea why I haven't done it before. I guess I was just to stuck in the old ways of doing things. I can't tell you how hard it rocks. I wrote the control, imported the control into VS, and used it. It worked first time! (now that never happens when you are trying something for the first time). I simple followed along with a great article at 15seconds.com. The article "Building ASP.NET User and Server Controls, Part 2 By Solomon Shaffer" is a great start. I followed along with the article and had my custom control built in about a half an hour. Mr. Shaffer's article is very easy to follow and he does an excellent job of getting to the real code and methods behind building a custom control. Everything I had read on Custom Controls before was so high level, that it didn't really do me much good. However this article makes it easy.
Wednesday, May 26, 2004
Interesting Blog
This evening I was reading an article about pixar. The article mentioned Steve Jobs and Disney discussing the contract. Of course this ended with Pixar going out on its own. But it got me thinkin' does Steve Jobs have a blog?
Guess what? He does JustOneMoreThing.com - Mac'N'Stuff - Steve Jobs' weblog ;-)
Tuesday, May 25, 2004
Searching Indexing Services with ASP.NET and C# Part III
I pretty much thought I had this whole Searching Indexing Services with ASP.NET all wrapped up, till my Boss' Boss' kept getting an "Access Denied Error". However it was extremely intermittent. It would work great three of four times and then show up. These kind of intermittent problems are so frustrating. How can you fix something that you can't reproduce everytime? Or even every other time? So after about an hour of doing google searchs, I found an article on support.microost.com. FIX: "Access Is Denied" Error Message When You Try to Access Indexing Service from ASP.NET with Impersonation Enabled.
Being that I am using impersonation in my application, I felt at least this could get me on the right track. The first thing that it mentioned was if you are on Windows 2000 serve rupgrade to service pack 4. We have been a little leary of service pack 4, but I crossed my fingers, toes, eyes and installed the services pack. To my surpise it installed cleanly, but didn't fix the issue. So re-reading the article it talked about adding something to the web.config. My web config was already pretty customized, but I through caution to the wind (after making a complete back up) and added the code. It worked! This is what I added. Make sure it is outside of your current <system.web> node.
<location path="filename.aspx">
<system.web>
<identity impersonate="false" />
</system.web>
</location>
It' basically turns off impersonation just for the file. And as I gave ASP.NET full access to my catalog. It runs beautiful.
Monday, May 24, 2004
Words, Words, Words
So the Little Boy's speech is getting better and better everyday. The funny thing about that is now he will go through his whole dictionary of words stringing them together for his own entertainment. (note: when the Little Boy calls out your name and strings it together with a vehicle, a color, a food, a smell and adjective, don't take it personally, however if your Wife does, that is a different matter completely) This is a dangerous time, but not for him, for us. He is at the parroting stage. However it isn't right after you said it. It's two hours to four days later. So you really have to watch what you say. You tell the dog 'you stink, bad dog', and two days later, the Little Boy is telling the some random kid at the park the same thing. Fortunately we can blame the school systems, being that he is in pre-school.
There are a lot of words he knows, and by knows I mean he understand what they mean. Usually there are driving instructions that are yelled out from the back seat when I am driving. Like 'turn here' or even worse 'turn here NOW!', when we pass the toy store on the way to walmart.(I don't go that way any more, It takes ten minutes more to go the long way, but I feel it is worth it.) And the 'No No, No, turn here please' when I keep on driving. Of course if you are really driving poorly (which apparently I do quite often. I use to think I was such a good driver.) you hear "Stop the Car, Please!".
A new phrase that has entered the Little Boy's repertoire is "No NEVER!". He picked up this little gem from the movie "Peter Pan". However he doesn't quite get how to use it. For example:
Me: "Would you like a glass of milk?"
Little Boy: "No NEVER!"
Me: *hand Little Boy glass of milk*
Little Boy: *Drinks it in two gulps*
Me: "Was that good?"
Little Boy: "No NEVER!, more please?"
So it makes me wonder what other phrases are going to be like that. I wonder what will be the next thing he says that will be my mental "quote of the week". He is growing so fast, and really starting to get use to using this strange language we call english. He has come so far, but still has more work to come. My Beautiful Wife and I were talking about this while doing some grocery shopping tonight. It must of been a sight to see two adults going down the isles saying "No NEVER!"
Sunday, May 23, 2004
Finally we get a real action figure
There is finally a real action figure. This one doesn't have freakishly large biceps. It doesn't sling webs, but it's good on the web. He doesn't have x-ray vision or lasers that shoot out of his eyes. Infact he needs glasses to see his computer screen. He is the everyday hero. He can fix DNS problems with a single command. Able to parse large log files in a single view, he's faster then an over clocked pentium 4, he is the super-alpha-uber-geek, GeekMan! Unlike other action figures you'll find in the stores, Geekman comes with full documentation, yeah, I know, pretty exciting, huh?
Friday, May 21, 2004
Skype and Two C# Guys
Skype
Today, I finally broke down and walked across the street to Frys and picked up a head set so that I could use Skype. So what is Skype? I am so glad you asked, It is a really cool piece of software that allows you to make "calls" over the internet. It uses the "IP" (Internet Protocol) transfer your voice across the ether of the internet to the person receiving the call. Now there is a couple of things, the other person has to be on Skype as well, and there isn't a version for Macs or Linux yet. Ed and I played with it this afternoon, and it is amazing it sounds just as good as the regular landline phone. You don't need anything special except for a headset. If you have a microphone and speakers that will work too. My headset is just a $10 labtech unit and it sounds great. I think this is going to a great tool, and something we will use when working from home.
Two C# Guys
Ed and I have started something we hope is helpful. Not only for each other but for everyone. We've started a blog that we are co-authors on called Two C# Guys. We are going to put code snippet and post about some of the C# issues and projects we run into. It's about sharing the knowledge.
Trying something New
Thursday, May 20, 2004
The Eyes have it
Today my Beautiful Wife and I had an appointment with our Optometrist. It has been about three years since I've gotten my eyes checked. So I was a little nervous. I know that they have gotten a little worse. Of course sitting in front of a computer all day, typing away doesn't help them much. It went as well as can be expected. The Optometrist seemed like a nice man, and wasn't in a rush to get you out the door. The little boy of course went with us.
Now that was a new experience for me. Last time I picked out glasses I was by myself and could take as long as I wanted. However after the Little Boy had patiently sat through both My Beautiful Wife's and my eye exam he was ready to go. But I still needed to pick out some frames. With some good advice from my Beautiful Wife I got some frames that will look nice two years from now. (When the insurance allows us to get new glasses) She on the other hand is going to go pick out hers when the little Boy is in school. (A very wise decision.) So Hightlights from the Optometrist visit.
- The Little Boy pretending to have a conversation with my Brother on a my cell phone which was turned off. It is great to see him using his imagination.
- One of the office stafff asked The Little Boy if he wanted to sit down and wait, and he informed her that he was going to be with one of us and he didn't care which, but under no circumstances was he going to sit down for her.(my heart swells with pride on this one)
- My Beautiful Wife looking at me in my new glasses, and giving me a look of 'you are the handsomest man on earth, after Johnny Dep'.
- On the way home we stopped at A&W and everyone had a Root Beer Float.
Wednesday, May 19, 2004
Be Careful About what you promise
Today at work, I was in an informal meeting with my boss and my boss' boss. We were talking about how one of the project that we hoped to have finished a month ago still isn't finished. Its due in part to people who should care and want it done, just not giving the project the time it deserves. Anyhow we were talking about new functions of the site that were tied to this project. One of them, I thought for sure we had done. It had been assigned to a person a couple of months back, and surely they had it done. So I told my boss' boss that we would generate the code that throw that page up on the site this afternoon. No problem right? As it turns out not so much. This one piece required some research and some terribly repeative copy and pasting (I hate that kind of work). So about a quarter of the research had been done and almost none of the coding. It was one of those things that just fell through that cracks like things sometimes do. Now of course, I had assumed it had all been done and was waiting and my boss's boss had been told it would be done today. Well I am happy to report that it was done today, with just about an hour to spare. I ended up just tearing into it, created an xml document for the data, an xsl to transform the data and used my handy dandy little html generator to create the html. Still even with the little utilities to help make it faster it was a lot more work than I initially thought it would be. However next time, I will check to make sure I have all the facts before I promise something like that.
I know I promised way back when that I would post my little html generator. I still haven't gone through and documented the code yet, but here it is anyway.
(Little disclamier: That the Software comes "as is", with no warranties. None whatsoever.
This means no express, implied or statutory warranty, including without
limitation, warranties of merchantability or fitness for a particular
purpose or any warranty of title or non-infringement. Also, you must pass
this disclaimer on whenever you distribute the Software or derivative
works.)
Monday, May 17, 2004
Renfaire Wedding
This weekend My Beautiful Wife and I went to a Wedding that was being held at the Renaissance Pleasure Faire. This was the first Renaissance wedding we have attended, and I have to admit it was a lot of fun. Not many weddings have musicians in Elizabethan costumes, or MooNie the Magnificent. The food was reall good and the weather was very nice. The wedding was lovely, and it really fit the couple well. One of the more interesting events was the toast. They did a 1530s style toast. How this goes, is a little different then the normal best man toast. The Best man stands up, and then the Bride and Groom do as well, each putting their right hand on the left shoulder of the person in from of them. Then they walk around the dinning tables and each person is to follow suite, until everyone at the wedding is following behind. It sort of looks like the Elizabethan version of a congo line. Once everyone is on the party train the best man circles the group around and around till they are in a tight circle around the couple. Then the toasts start. It was very nice and makes everyone feel like a part of the wedding instead of just a spectator.
Sunday, May 16, 2004
6 Months Old
Solution to the directory version application security problem
What do you do when you need to secure the directory in IIS, but you need security at the application level as well? Since IIS doesn't give your application all of the username and password information, you can't use directory security. However you have files that need to be secured at a directory level. Of course if you use application security, your application can't communicate with IIS to give it the username and password information. So it's kind of a catch22 isn't it? So when presented with a choose, choice both. My application give access to office files if your Active Directory account is in the correct groups. So that is application level. But with application level security if anyone knows, or can guess the url of the documents, they can view them right in their web browse. Now what is the use of setting up Active Directory groups and using the System.DirectoryServices namespace, if in the end anybody can browse to it.
The solution that I can up with was to lock down the my content directories in IIS. No rights to anyone. Then I created a page to be the proxy between the web and the NTFS level. So now you can only browse to the files if you have the correct authorization from the you Active Directory group, and if you don't it takes you to a login screen. What's really interesting about this solution is it envolves a lot lets code then you may think. The article I based my code on is in the Microsoft knowledge base, Article -306654.
private
voidPage_Load(object sender, System.EventArgs e){
FileInfo MyFileInfo;
long StartPos = 0, FileSize;
string filepath = "";
try
{
//Check to see if there is anything in the QueryString.
if (Request.QueryString["doc"].ToString() != "")
{
//Set filepath to Querystring.
filepath = Request.QueryString["doc"].ToString();
}
}
catch
{
//If the Querystring is empty send the user back to Default.aspx.
Response.Redirect("Default.aspx");
}
try
{
//Set the appropriate document type
Response.ContentType = "Application/pdf";
//Response.ContentType = "Application/pdf";
//get the physical file path
stringstrFilePath = utilities.getPath(filepath);
//instantiate the FileInfo class
MyFileInfo = newFileInfo(strFilePath);
//Get the size of the file.
FileSize = MyFileInfo.Length;
//Write the file directly to http content output stream
Response.WriteFile(strFilePath, StartPos, FileSize);
Response.End();
}
catch(Exception err)
{
//Write to custom error logging function
logging.writeError(err.Message.ToString());
}
}
So Pretty straight forward. You locate the document give the Response.WriteFile function the files path and a few properties and your aspx page opens up as if it were that document. Of course the one thing you have to be mindful of is the Content Type. That must be set to the correct MIME type for the type of file you are opening. Wher are some of the types.
I have ran in to a couple of issues worth mentioning. First in some cases with users that are running Internet Explorer, the page will appear to be completely blank. The issue seems to be that IE is second guessing the content type and doesn't display anything. The fix is simple, but on the client side, in their pdf reader they need to disable view pdf in browser. Here is an article that covers all of the variations of Acrobat and Internet Explorer settings to do that
Second, is speed, with files that are larger than 2MB it takes a little longer. Not a lot, but it is noticable. This is because our ASPX page is reading the file in binary and rewriting it in binary to the browser. I haven't figured out how to speed that up just yet. If I do I will post it. However a document being 10 times more secure, is worth it being a little slower.
Friday, May 14, 2004
Bloggin Apps
Lately, I have been using BlogJet for my posts. It works pretty good and they just came out with their first version out of beta. For the most part it does what it does pretty well. However there are something that I want that it does seem to have. I like the simplcity of the interface, but I want it to support my stylesheet. On my blog site I have a pretty extensive stylesheet that controls the fonts, colors, sizes and a couple of other things. Well when I post I have to add a bunch of <span> tags and, I have to look at my styleshee to see which style I want. usually that isn't too big of a deal when it is just paragraphs or links. But when I put code examples up, it gets to be a workout. I end up spending as much time making it look right as I do writing the content.
I've looked around and other stuff out there that does use the stylesheet is more complicated. And believe it or not the whole reason for this blog is to get away from complicated web programming. I just want to type in my post, click a few buttons and publish it. So of course this got me thinking. I am just going to have to build my own blog utility. I've already written a WYSIWYG editor that works in Internet Explorer. It's actually in xsl. So all I need is to figure out how to get the post to the server right? Well Blogger has adopted the Atom API. Which means I can make my application connect through Web Services to the Server. This will let me add new post , update or delete older post. What really impressed me is how well they have documented the API. There is even a C# example of coding to the API. So I will work at writing a utlity to add to the mryiad of others out there.
I'll let you know how it goes. If it's any good I'll post it.
Wednesday, May 12, 2004
How do you get Milk from a bean?
Searching Indexing Services with ASP.NET and C# Part II
Last friday I blogged about using Ixsso and ASP.NET to use as a site search. Well,I had to go and play with it a little more. The one thing I didn't like about the example that was given on friday was that it used a datagrid. Now don't get me wrong, I love datagrids in ASP.NET. However I just don't think of search results as tabular data. It's much more in a paragraph form. Look at google, you'll see a header/title, an abstract or paragraph and the URL. That is what people are use to seeing went they do site searches. Seeing the ranking is cool for us geeks but for most users, they want the search to be smart enough that, it is displayed in the order it was ranked in. So yesterday I had the idea that I should just serialize the results that I got from Indexing Services and use XSL to display the data. This is a great way to change the look of the results very quickly. However there was a side benefit that I didn't think of, it's fast. Now true I'm not searching an index of 6 billion pages like google, but I was amazed how quick it was. So how about some code now. This piece of code starts right before we were binding the results to the datagrid in friday's example.
da.Fill(ds, Q.CreateRecordset("nonsequential"), "IndexServerResults");XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(ds.GetXml());
XslTransform xslDoc = new XslTransform();
xslDoc.Load(utilities.getPath("xsl/search.xsl"));
xslDoc.Transform(xmlDoc, null, sw, null);
xmltest = sw.ToString();
So what we did was serialize the dataset by calling ds.GetXml(). From there we converted the string that ds.GetXml() generates by creating an new XmlDocument and loading the xml string into it by calling xmlDoc.LoadXml(ds.GetXml()). After that we created an instance of XslTransform, loaded the xsl file in to memory, and transform the xml to html, and returned it as string to be used in our aspx code. Pretty cool, huh?
What the brochure doesn't tell you.
Remember being in Jr. High and thinking that when you are an adult you can do anything you want?
I remember all of the things that I was going to be able to do and see when I was an adult. It was almost like a brochure. The brochure for adulthood. It showed parties, and cars to drive, and high paying jobs, and the ultimate apartment. I would get to spend my money however I wanted on whatever I wanted. I best of all I could go to bed whenever I wanted. Everyones brochure was what their ideal adulthood was going to be like. I remember my brother and I would go through the JC Whitney catalog picking out the accessories that would make our ultimate van for driving across country. We had big plans we were going to drive coast to coast and back again.
So now am an adult. Legally for 12 years, actually for 8. So first and foremost, the brochure lied! I don't get to spend my money however I want. It goes to bills and necessities. The time I go to bed is dictated by the three year old and the morning commute. I haven't been to a party in ages and wouldn't have the energy to go to one. But these are the little things and really easy to get over. The brochure doesn't mention that when the Little boy falls and gets hurt that you fell like crying too. It neglected to mention the complete heartbreak you feel when he crashes his tricycle and gets road rash and a goose egg on his little head. Or how much you would rather, you were the one that was hurt instead of him. It didn't talk about how much you would do for him, and how completely in love with him you would be. It forgot to mention that I would like story time just as much if not more than he does.
The Little Boy's wounds will heal. I've had my share of road rash. I was an adventurous lad myself once. I know what it's like to be a rough tumble boy. Some of the scars go away and the rest you wear with pride. I know that he will be okay, and survive the next crash and the next one after that. They will be some of his war stories from his childhood. What I don't know is if I'll survive his next crash.
The brochure lied, things are much better than it said.
Monday, May 10, 2004
The Weekend
So, an interesting thing happened this weekend. I didn't work. I mean, I did but not really. Monitor a server doesn't really feel like work work. I got to spend time with my Beautiful Wife and the Little. My Dad and I helped a friend move. (You can always tell if someone is really your friend if they help you move) Sunday morning I was exhausted from helping our friend move. (Dad and I didn't get home till after 2:45am saturday night/sunday morning). So I couldn't do much sunday morning but sit around the house and rest up a bit.
I got to feelin' a little better in the afternoon so my Beautiful Wife, the Little Boy and I headed down to the happiest place on earth. It wasn't too crowded. The crowds weren't as light as when we went last weekend with Mom and Dad but it was good. Anyhow we did all of the little boys favorites, pirates, pooh, autopia, his new favorite star tours and honey I shrank the audience. That last one was a little too intense for him. I don't think we'll do that one for a while.
My favorite quote from the day is from the Little Boy (most of my favorite quotes here lately are from him). So let me set the scene, we are on Autopia. He steers the car, I work the gas pedal. It works good for us since he reach the pedal yet. Anyhow, the Little Boy works very hard at, driving it well, keeping it between the lines. He hates when the car bumps the inner rail because it jerks the steering wheel out of his hands. That being said, he didn't quite get the car straightened out in time, and the rail got him, and moved the steering wheel, with the attitude of someone that's been driving LA traffic, everyday for the last 10 years, he balls up his little fist, and yell "Stupid Car" and hits section of the steering wheel where the horn would be. Now this has to be all him. I don't drive during the week. (I metrolink it to work) So my driving has calmed down tremendously. My Beautiful Wife doesn't drive like that either. She is a very calm driver and doesn't get rattled by traffic. So it has to be his little personality. It's amazing to see it coming out.
Friday, May 07, 2004
Searching Indexing Services with ASP.NET and C#
So I have a project that requires we have a mini site search. And being that I have written the whole site in ASP.NET/C#/XML/XSL I didn't want to have to go back to classic ASP for search. I did some searching online and found a really good post on using ASP.NET with Indexing Services. The article/post "Query the Indexing Service with Ixsso and ASP.NET" covered the issue really well. However it was written in VB. So of course I needed a C# version of it, so I just translated the VB stuff to C# and voila!.
private void searchIndexing(string strValue){
try{
CissoQueryClass Q = new CissoQueryClass();CissoUtilClass util =
new CissoUtilClass();OleDbDataAdapter da =
new OleDbDataAdapter();DataSet ds =
new DataSet("IndexServerResults");Q.Query = strValue;
Q.SortBy = "rank[d]";
Q.Columns = "vpath, filename, rank, characterization";
Q.Catalog = "query://contentserver/catalogname";
Q.MaxRecords = 1000;
util.AddScopeToQuery(Q,"\\","deep");
Q.LocaleID = util.ISOToLocaleID("EN-US");
da.Fill(ds, Q.CreateRecordset("nonsequential"), "IndexServerResults");
DataGrid1.DataSource = ds;
DataGrid1.DataBind();
}
catch(Exception f){
lblError.Text = f.Message.ToString();
}
}
Just make sure you add a reference to the IXSSO COM Object in your project and away it goes!
Thursday, May 06, 2004
Things I've learned about ASPNET (the local user account for ASP.NET)
Well, I have been trying to trackdown an incredibly irritating issue with my ASP.NET v1.1 code not running on one of our w2k (windows 2000) servers. I think the root cause of it all has to deal with the fact that this box runs OWA (Outlook Web Access) and OWA doesn't play well will other. So here is the run down. In the machine.config , node processmodel where use name says "machine" it is using the ASPNET local user. For the most part this user has access to everything it needs because it is in the Group user. (I know a user in the user group... a little redundant). However there are some instances, depending on patches and services packs where this user doesn't get the correct NT users permissions. This table from Microsoft really helped.
Table 1. Required NTFS permissions
| Folder | Required Permission | Account | Comments |
|---|---|---|---|
| C:\WINNT\Microsoft.NET\ Framework\<version>\ Temporary ASP.NET Files | Full Control | Process and fixed impersonation accounts | This is the ASP.NET dynamic compilation location. Application code is generated in a discrete directory for each application beneath this folder. The tempdir attribute on the <compilation> element can be used to change this default location. |
| C:\WINNT\temp | Read/Write/Delete | Process | Location used by Web services to generate serialization proxies. Note that the Delete permission is set using the Advanced button on the Security page of the Windows Explorer folder properties dialog box. |
| Application folder | Read | Process | The location of your Web application files (that is, your application's virtual root directory: for example, c:\inetpub\wwwroot\webapp1). By default, the Users group has the appropriate access rights. |
| %installroot% hierarchy (C:\WINNT\Microsoft.Net\Framework\v1.0.3705) | Read | Process and fixed impersonation accounts | ASP.NET must be able to access .NET Framework assemblies. By default, the Users group has the appropriate access rights. |
| C:\WINNT\assembly | Read | Process and fixed impersonation accounts | This is the global assembly cache. You cannot directly use Windows Explorer to edit ACLs for this folder. Instead, use a command Windows and run the following command: cacls %windir%\assembly /e /t /p domain\useraccount:R Alternatively, prior to using Windows explorer, unregister shfusion.dll with the following command: regsvr32–u shfusion.dll After setting permissions with Windows explorer, re-register shfusion.dll with the following command: regsvr32 shfusion.dll |
| Web site root: C:\inetpub\ wwwroot or the path that the default Web site points to | Read | Process | ASP.NET reads configuration files and monitors for file changes in this folder. |
| C:\WINNT\system32 | Read | Process | For system DLLs loaded by the Framework. |
| Parent directories of context | List Folder/ Read | Process | For file change notifications and the C# compiler. |