0 comments Tuesday, January 23, 2007

Hi All,
The below function will authenticate user using Active Directory.


public bool IsAuthenticated(string domain, string username, string pwd)

{

string _path;

string _filterAttribute;

string servername = "ServerName"; // Give the server Name

string domainAndUsername = domain + "\\" + username;

DirectoryEntry entry = new DirectoryEntry("LDAP://" + servername, domainAndUsername, pwd);

try

{

object obj = entry.NativeObject;

DirectorySearcher search = new DirectorySearcher(entry);

search.Filter = "(SAMAccountName=" + username + ")";

search.PropertiesToLoad.Add("cn");

SearchResult result = search.FindOne();

if (result == null)

{

return false;

}

_path = result.Path;

_filterAttribute = ((string)(result.Properties["cn"][0]));

}

catch (Exception ex)

{

return false;

}

return true;

}



Hope this will help all

Regards
Pankaj

0 comments

Hi,
Download XML notepad from here

http://www.microsoft.com/downloads/details.aspx?FamilyID=72d6aa49-787d-4118-ba5f-4f30fe913628&DisplayLang=en

Regards
Pankaj

0 comments

Hi All

To quickly add assemblies to the GAC - a registry key can be created
which allows you to right click the DLL and 'GAC it' in one click.

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\dllfile\shell\gacutil\command]
@="c:\\windows\\Microsoft.NET\\Framework\\v1.1.4322\\gacutil.exe /i
\"%1\""

Reference link
http://markharrison.co.uk/blog/2005/12/easier-way-to-add-dll-to-gac.htm

Thanks & Regards
Pankaj

0 comments

Encrypting Web.Config Values in ASP.NET 2.0

One of the cool new features in the configuration system with ASP.NET 2.0 is the ability to encrypt any of the values stored within them (note: this works with any configuration section -- including ones you build yourself). This is obviously important when storing sensitive information like connection strings -- and now enables you to avoid having to roll your own solution.
Here are a few other good articles I found on the web that discuss it more as well:
http://msdn2.microsoft.com/en-us/library/zhhddkxy.aspx http://blogs.msdn.com/federaldev/archive/2005/11/08/490319.aspx http://msdn2.microsoft.com/en-us/library/dtkwfdky.aspx http://aspdot.net/articles/encryptedconnstring/ http://davidhayden.com/blog/dave/archive/2005/11/17/2572.aspx http://weblogs.asp.net/owscott/archive/2005/07/29/421063.aspx Look at the following simple example to encrypt a section in web.config
The ASP.NET IIS Registration Tool (Aspnet_regiis.exe) can encrypt and decrypt sections of web.config. There is no special code required in an application, as ASP.NET 2.0 will magically decrypt sections at runtime.
The tool and runtime can also work together to encrypt and decrypt custom configuration sections. So if I have the following in web.config:
name="sampleSection" type="System.Configuration.SingleTagSectionHandler" />
FavoriteMusic="Disco" FavoriteLanguage="COBOL" DreamJob="Dancing in the opening ceremonies of the Olympics" />
All I need to do from the command line, is:
aspnet_regiis -pef MySecrets .


Hope this helps,

Pankaj

0 comments

HI Guys,

This is a very good stored procedure which compares 2 databases and gives excellent comparison
http://www.sql-server-performance.com/vg_database_comparison_sp_code.asp

Hope you find this useful

Regards
Pankaj

0 comments


Namespace


C# namespace allow us to organize our class.unlike a file and component namespace provide us a flexibility to group our class and other types
For eg
Namespace MyCustomNameSpace
{
using System;
public int show()
{
return 0;
}
}
Using keyword in C#
C# allows us to abbreviate a class full name for doing this we have to list the class namespace at the top of the file with the “Using” key word
Eg
Using MyNameSpace.CsharpExample
Class MyClass
{
public static int Main()
{
SomeOtherNameSpace.SomeOtherClass loMyObj = new SomeOtherNameSpace.SomeOtherClass loMyObj();
Return 0;
}
}
Namespace Aliases
The another use of the namespace in c# is creating aliases.this is use ful when we have a long namespace for eg
Using myAliases = MyNameSpace.CsharpExample;

Regards
Pankaj