my.net

My Photo
Name:
Location: United States

Wednesday, February 06, 2008

Developer Tools (free)

7-zip

.net debugger

IE developer toolbar

viewstate decoder
http://www.pluralsight.com/tools.aspx

Application Verifier
http://www.microsoft.com/downloads/details.aspx?FamilyID=bd02c19c-1250-433c-8c1b-2619bd93b3a2&DisplayLang=en

Ethereal
http://www.ethereal.com/download.html

Wednesday, November 28, 2007

Underlying connection was closed

FIX: Intermittent "Underlying connection was closed" error message when you call a Web service from ASP.NET

Friday, October 12, 2007

InteropXML - .NET Xml


MSXML.tagDOMNodeType.NODE_ELEMENT - Xml.XmlNodeType.Element
MSXML.IXMLDOMNamedNodeMap - Xml.XmlNamedNodeMap
MSXML.IXMLDOMNode - Xml.XmlNode
MSXML.IXMLDOMAttribute - Xml.XmlAttribute


nodValue.text- sInnerText
nodeName - Name
ChildNodes.length - ChildNodes.Count
xml - OuterXml


---------------
mscorlib The type System.Xml.XmlDocument in Assembly System.Xml, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 is not marked as serializable.

Dim r_xmldoc As New Xml.XmlDocument, parzError As String
LoadnParseXML(r_XMLdoc, sr_XMLdoc, parzError)

sr_XMLdoc = r_xmldoc.InnerXml
---------------

---------------

Public Function LoadnParseXML(ByRef xmldoc As Xml.XmlDocument, ByVal xmlstr As String, _
ByRef parzError As String) As Boolean
On Error GoTo Err_LoadnParseXML
Dim bRet As Boolean

xmldoc.LoadXml(xmlstr)

bRet = True
Exit_LoadnParseXML:
Return bRet
Err_LoadnParseXML:
parzError = Err.Number & "-" & Err.Description
bRet = False
Resume Exit_LoadnParseXML
End Function

---------------


Thursday, October 11, 2007

WCF - when to use what binding

Monday, October 08, 2007

System.Xml.XmlDocument is not marked as serializable

XmlDocument is not marked as serializable, as you can send as a parameter to COM+ methods, the resolution is to send Xml as string

Dim r_oXMLdocString As String = r_oXMLdoc.InnerXml
call the server function here...


ServerFunction()
{
Dim r_xmldoc As New Xml.XmlDocument, parzError As String
LoadnParseXML(r_XMLdoc, sr_XMLdoc, parzError)

do processing...

sr_XMLdoc = r_xmldoc.InnerXml
}

Saturday, June 16, 2007

cms 101

cms 2002 installation complete with dev tools (on .NET 2003)

- setup cmsguest, cmssys, cmsadmin domain accounts
- create website cms101.com
- create virtual directory cms101.com
- create empty database
- use dca to create cms tables (specify admin account) (step#b)
- use sca to make the site as cms site (step#a)
- use sca to allow guest login as cmsguest
- create webctrl_client(folder) at the website root
- create cms virtual directory and point to ..\program files\cms\server\iis_cms\
- mcms and nr virtual directories are automatically created in step#a
- can use only one cms database for a cms site (switch to different database using dca)
- run site manager under admin (specified in step#b)

Monday, June 04, 2007

Forms Authentication thru AD


using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Runtime.InteropServices;
using System.Security.Principal;
using System.Security;
using System.Security.Permissions;

public partial class Client_Novelis_Login : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
Image image = new Image();
tdTopMiddle.Style.Add("background-image", image.ResolveClientUrl("~/Client/Novelis/Images/table_side_top.gif"));
tdSideLeft.Style.Add("background-image", image.ResolveClientUrl("~/Client/Novelis/Images/table_side_left.gif"));
tdSideRight.Style.Add("background-image", image.ResolveClientUrl("~/Client/Novelis/Images/table_side_right.gif"));
tdBottomMiddle.Style.Add("background-image", image.ResolveClientUrl("~/Client/Novelis/Images/table_side_bottom.gif"));
}
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{
string ADskipaccount = "admin";
string ADDomain = "mydomain";
string ASPNETDefPasswd = "mypass999";
Impersonator oImper = null;
e.Authenticated = false; //not authenticated.
try
{
Login oLogin = (Login)sender;
if (oLogin.UserName.ToLower().StartsWith(ADskipaccount))
//if valid skip account, auth thru ASPNET
e.Authenticated = Membership.ValidateUser(oLogin.UserName, oLogin.Password);
else
{
oImper = new Impersonator(oLogin.UserName, ADDomain, oLogin.Password);
oImper.Impersonate();
MembershipUserCollection oUserCol = Membership.FindUsersByName(oLogin.UserName);
MembershipUser oUser;
if (oUserCol.Count == 0) //if not found, create user with default password
{
oUser = Membership.CreateUser(oLogin.UserName, ASPNETDefPasswd);
if (oUser != null)
{
//Log "create user success"
}
else
{
//Log "create user failed"
}
}
else
{
oUser = oUserCol[oLogin.UserName];
}
if (Membership.ValidateUser(oLogin.UserName, ASPNETDefPasswd))
{
e.Authenticated = oUser.IsApproved;
}
}
}
catch(Exception ex)
{
//Log "AD Authentication failed"
e.Authenticated = false;
oImper.Undo();
}
}
protected void Login1_LoggedIn(object sender, EventArgs e)
{
string desiredUrl = Request.QueryString[QS.RETURN_URL];
if (desiredUrl != null)
{
Response.Redirect("~" + desiredUrl.Replace(Request.ApplicationPath, ""));
}

}

protected void UserName_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
TextBox tb = (TextBox)sender;
tb.Focus();
}
}
}
public class Impersonator
{
// private members for holding domain user account credentials
private string username = String.Empty;
private string password = String.Empty;
private string domain = String.Empty;
// this will hold the security context for reverting back to the client after impersonation operations are complete
private WindowsImpersonationContext impersonationContext = null;

// disable instantiation via default constructor
private Impersonator()
{ }

public Impersonator(string username, string domain, string password)
{
// set the properties used for domain user account
this.username = username;
this.domain = domain;
this.password = password;
}

private WindowsIdentity Logon()
{
IntPtr handle = new IntPtr(0);
handle = IntPtr.Zero;

const int LOGON32_LOGON_NETWORK = 3;
const int LOGON32_PROVIDER_DEFAULT = 0;

// attempt to authenticate domain user account
bool logonSucceeded = LogonUser(this.username, this.domain, this.password, LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT, ref handle);

if (!logonSucceeded)
{
// if the logon failed, get the error code and throw an exception
int errorCode = Marshal.GetLastWin32Error();
throw new Exception("User logon failed. Error Number: " + errorCode);
}

// if logon succeeds, create a WindowsIdentity instance
WindowsIdentity winIdentity = new WindowsIdentity(handle);

// close the open handle to the authenticated account
CloseHandle(handle);

return winIdentity;
}


public void Impersonate()
{
// authenticates the domain user account and begins impersonating it
this.impersonationContext = this.Logon().Impersonate();
}


public void Undo()
{
if (this.impersonationContext != null)
// rever back to original security context which was store in the WindowsImpersonationContext instance
this.impersonationContext.Undo();
}

[DllImport("advapi32.dll", SetLastError = true)]
private static extern bool LogonUser(string lpszUsername,
string lpszDomain,
string lpszPassword,
int dwLogonType,
int dwLogonProvider,
ref IntPtr phToken);

[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
private static extern bool CloseHandle(IntPtr handle);

}