2008年6月16日

[IIS] How to install ASP.Net 3.5 onto IIS 6 ?

You don't need to.

ASP.Net 3.5 is basically an extension of ASP.Net 2.0, so just register ASP.Net 2.0 to IIS 6 and you are ready to run your ASP.Net 3.5 application on IIS 6.

But there do have some configuration settings you might need to know if you are running you applicaion on web server without VS2008 installed.

If you create your site with VS2008. then these settings are created by VS, but you may need to add the following section to your web.config to make your site compiled with ASP.Net 3.5 if you are modifying an existing site.

<system.codedom> 
<compilers><compiler language="c#;cs;csharp" extension=".cs" compilerOptions="/warnaserror-" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<providerOption name="CompilerVersion" value="v3.5"/></compiler>
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" compilerOptions="/optioninfer+" type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"><providerOption name="CompilerVersion" value="v3.5"/>
</compiler></compilers>
</system.codedom>



Also, your assembly settings should be changed.



<compilation debug="true">
<assemblies>
<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
</assemblies>
</compilation>

2008年6月13日

[SQL Express]How to change LogonMode and sa password

  1. 1. Open Regedit.
  2. 2. Check if [HKLM\Software\Microsoft\Microsoft SQL Server\MSSQL.1\MSSQLServer\LoginMode] is set to 1(Windows Mode) or 2(Mix Mode)
  3. 3. Modify the registry key to 2.
  4. 4. Open command prompt, change to C:\Program Files\Microsoft SQL Server\90\Tools\Binn
  5. 5. Execute osql -S [ServerName]\[InstanceName] -E
  6. 6. Under OSQL prompt, type each of the following statement and press Enter.
    sp_password @old = null, @new = 'complexpwd', @loginame ='sa'


    go




  7. 7. Restart SQL Service




reference:http://support.microsoft.com/kb/322336


2008年6月6日

[.Net][Remoting]Impersonate client user on Remoting server

Sometimes you need to simulate client user on server operations, with .Net Remoting, this can be done in simple steps.

On the server side, we have to enable security communication and to set impersonate level, this can be done by adding configuration settings in application config file:

<channel ref="tcp" port="8888" secure="true" impersonate="true" authenticationMode="ImpersonateCallers"/>

  • impersonate="true" to enable impersonation on threads
  • authenticationMode="ImpersonateCallers" to impersonate the caller, which impersonate client user before calling remoted object's methods
  • secure="true" to enable security options

On the client sider, application should comply server's rules

<channel ref="tcp"
secure="true"
tokenImpersonationLevel="impersonation">
<clientProviders>
  • secure="true" to enable client security options
  • tokenImpersonationLevel="impersonation" to enable client side impersonation, this property is same with server's impersonate property

When you server starts, do enable security option in your code:

System.Runtime.Remoting.RemotingConfiguration.Configure(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile,true);

On client side application, also configure remoting service via config file with secure enabled like the above code sample.

The above sample illustrate NTLM scenario, with Kerberos, you'll have to add a property spn="Service/Domain" in your client configuration file.

reference:

  1. http://www.leastprivilege.com/
  2. How to add CIA to .Net Remoting
  3. Remoting config file format

2008年6月5日

[.Net] SelectNodes case insensitively with .Net Xml DOM

The Microsoft .Net Framework provides interfaces that you can use them to implement your own extended functions to work in XPath expressions, and here are what you ought to know when you want to perform a case-insensitive search.

First is to write your own XslContext class, to do  this, create a class inherits from System.Xml.Xsl.XslContext class, and implement its abstract methods.

public class XmlExtendedContext:XsltContext
{
public override IXsltContextFunction ResolveFunction
(string prefix,
string name,
XPathResultType[] ArgTypes)
{
IXsltContextFunction resolvedFunction = null;
if (this.LookupNamespace(prefix) == EqualsFunction.Namespace &&
name == EqualsFunction.FunctionName)
resolvedFunction = new EqualsFunction();
return resolvedFunction;
}
}


The ResolveFunction() method resolves custom functions in XPath. So we have to write another class EqualsFunction to actually perform the function.





public class EqualsFunction{
public const string Namespace =
"http://myextensions.xml";
public const string FunctionName
= "equals";

private XPathResultType[] m_argTypes =
new XPathResultType[] {
XPathResultType.Any,
XPathResultType.Any };

#region IXsltContextFunction Members
public XPathResultType[] ArgTypes
{get{return m_argTypes;}}
private string GetArgs(object arg)
{
string stringValue;
if (arg is string)
stringValue = (string)(arg);
else if (arg is XPathNodeIterator)
{
XPathNodeIterator i =
(XPathNodeIterator)arg;
if (i.MoveNext() == true)
{
XPathNavigator navigator = i.Current;
stringValue = navigator.ToString();
}
else
throw new ArgumentNullException();
}
else
throw new ArgumentNullException();
return stringValue;
}
public object Invoke(
XsltContext xsltContext,
object[] args,
XPathNavigator docContext)
{
if (args.Length != 2)
throw new ArgumentNullException();
string argument1 = GetArgs(args[0]);
string argument2 = GetArgs(args[1]);
bool result = string.Equals( argument1, argument2, StringComparison.CurrentCultureIgnoreCase);
return result;
}
#endregion
}



And to use newly created function in your code:



//Create custom Context
XmlExtendedContext ctx = new XmlExtendedContext(doc.NameTable);

//Prepare namespace manager
ctx.AddNamespace("s", XmlExtendedContext.EqualsFunction.Namespace);

//perform the search
return doc.SelectSingleNode"//*/child[s:equals(@Name,\"TEST\")]",ctx);













Blog Archive

About Me