.Net, ASP.Net, C#, VB.net, SQL Server, Xml, CSS, Design Patterns related tips, tricks, code snippets, articles, links, thoughts, etc. from Binu & Subi Thayamkery.

Binu Thayamkery is a seasoned software architect with more than 13 years of experience in developing enterprise grade connected systems using Microsoft Technologies. In his current position as a lead consultant-solution architect with Prudential Financial, he is working on architecture of next generation investment reporting framework using .net 3.5/WCF/AJAX, etc. He holds a Masters Degree in Computer Science from Colorado State University. Subi Thayamkery is an experienced software developer with more than 8 years of developing various application software systems ranging from workflow automation systems to compliance management tools. She currently works as a technology consultant for Prudential Financial where she helps develop a new system for corportate governance department. She holds an Electrical Engineering degree from New Jersey Institute of Technology.

Tuesday, January 31, 2006

HTTP 500 - Internal server error

This is no fun message ! When you get this message, a simple restart of W3 services might fix your issues. When you are dealing with ASP.net, some time you end up installing asp.net on your server again ( aspnet_regiis -i from your current framework version sub directory ), in my case, it showed up for no "apparent" reason ( server: Win 2k, .NET 1.1 ). Server Event log showed this message,
Source: DCOM
Error: DCOM got error "Logon Failure: unknown username or bad password" Unable to logon .\IWAM_SERVERNAME in order to run the server.



Source: W3SVC
Error: "The server failed to load application '/LM/W3SVC/1/Root/op.' The error was 'The server process could not be started because the configured identity is incorrect. Check the username and password.


I did some basic test pages ( both aspx and asp ) and found out that both the pages were not serving from the server. (html pages were ok).

After some research (read Googling:) this is what I found out,
"Configured Identity Is Incorrect for IWAM Account!!"
and what you need to resolve this issue is to sync up IUSR and IWAM accounts in IIS metabase. I followed the steps in this MS KB article and the issue was resolved.

http://support.microsoft.com/default.aspx?scid=kb;%5BLN%5D;Q297989

Tuesday, January 24, 2006

"Server Application Unavailable"

All of a sudden, this big scary message showed up ! Application Event Log showed more details like,


"aspnet_wp.exe could not be launched because the username and/or password supplied in the processModel section of the config file are invalid.
aspnet_wp.exe could not be started. HRESULT for the failure: 80004005
"...


If you get this error, this link might shed some light on the issue,
http://support.microsoft.com/default.aspx?scid=kb;en-us;315158

In my case, it was much simpler issue, my ASPNET account (Win 2K Server) was locked out ! (dont have a clue how that happened !!)

Thursday, January 19, 2006

Server.Transfer and Page to Page data exchange

When you are using Server.Transfer to transfer control from one page to another page within the same HttpContext, you can use Context property of Current (http context) to get a handle of the parent page. Once you have that you can access properties (public) of that page. Key thing to remember is that all ASP.Net pages are classes! (derived from mama Page Class )

Here is a simple illustration:

Your first page:

public class FirstPage: System.Web.UI.Page
{

public int MyInt
{
get
{
return (1);
}
}

}

Your second page:

public class SecondPage: System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
if (!Page.IsPostBack)
{
int myParentInt;
FirstPage myParentPage;
myParentPage = (FirstPage)Current.Handler;
myParentInt = myParentPage.MyInt;



}
}

Friday, January 06, 2006

More File and Directory Stuff !

Level: Beginner

In general, when you want to do anything related to Files and Directories, the namespace
of interest is System.IO. And most of the file and directory operations can be done using
one or combination of DirectoryInfo, Directory, FileInfo, or File class. Here is some common
tasks and one of many ways to do those...

1) Check if file exits :

FileInfo file = new FileInfo("filename.txt");
if (file.Exists)
{//file exists}


2) Check if directory exists:
Similar to the one before,
DirectoryInfo dir = new DirectoryInfo(path);
if (dir.Exists)
{ // dir exists }

3) Create a Directory
DirectoryInfo dir = new DirectoryInfo(path);
if (!dir.Exists)
{ dir.Create(); }

Using the same class, you can get the attributes, number of files present (dir.GetFiles().Length.ToString())
and more...
4) If you want to change the attribute of a File, you can do so like this...

FileInfo file = new FileInfo("my.txt");
// This adds just the read-only attribute.
file.Attributes = file.Attributes FileAttributes.ReadOnly;

// This removes just the read-only attribute.
file.Attributes = file.Attributes & ~FileAttributes.ReadOnly;


5) To read or write a text file, use a StreamReader and a StreamWrite classes
To create a new file,
FileStream fs = new FileStream("my.txt", FileMode.Create);
6) Find files with of a certain type:
FileInfo[] files = dir.GetFiles("*.xml");
GetFiles() method takes an argument where you can specify the type.


Can you think of more uses, samples...post on comments...Thanx :)

VS.net project, accessing from Network Share !

Level: Intermediate

If you place your VS.Net projects (Windows App) in a network share and try to work off that share, you might end up with an error message like this "The project location is not fully trusted by the .NET runtime". This message pops up when you try to open the project file. If you say Ok, to that "long" message and continue working you might end up with some security permissions issue when you try to debug. (In my case, I was trying to open a file using StremReader and it threw an Security Exception !)

In order to successfully run the projects, you will need to play around a bit with .Net configuration tool. Launch mscorcfg.msc (you should be able to find this under your current version of .Net Framework dir)

Under My Computer > Runtime Security Policy, you can either add a new code group and give "Full Trust" permission for the URL(File/Http) or you can use the adjust the security policy link, give Full Trust to Local Intranet.

Try one or the other and see what works for you !