16 December 2011

Validate Login User with AD/LDAP authentication(Login Page)

Validating users against Active Directory/ LDAP. Also many organisation have multiple domains and same application needs to validate accross all domain.

This code can be used in SharePoint custom Login form for user Validation for Claim based authentication or Form Based Authentication.




Reference Added :

using System.Runtime.InteropServices;

COMException : The exception that is thrown when an unrecognized HRESULT is returned from a COM method call for more simplified error response from LDAP Error: Unknown error (0x80005000).


using System.DirectoryServices;


Below is the code sniplet

using (DirectoryEntry entry = new DirectoryEntry())
{
entry.Username = "DOMAIN\\LOGINNAME";
entry.Password = "PASSWORD";
DirectorySearcher searcher = new DirectorySearcher(entry);
searcher.Filter = "(objectclass=user)";
try
{
searcher.FindOne();
{
//Add Your Code if user Found..
}
}
catch (COMException ex)
{
if (ex.ErrorCode == -2147023570)
{
ex.Message.ToString();
// Login or password is incorrect
}
}
}


ErrorCode : -2147023570 suggest the Username or password is not correctly entered.

post your questions, comments or suggestion.


10 December 2011

Hide the extension .aspx in the url of page ...

Now a days customers are more concerned with site URL and its relative path displayed on the browser address.
Many Suggest having interceptor/handler or use the existing global.asax (Application_Begin Request handler) for modifying the URL shown in the browser window, Web Routing is the concept (4.0 framework)

However you can get solution for .Net /sharepoint application there are following ways:
  1. MVC
  2. HttpModule rewrite URL
  3. ISAPIRewrite to enable Extension-less URL Rewriting for IIS5 and IIS6
  4. IIS level extension parsing
Step by step approaches refer below links:
URL Rewriting in ASP.NET
URL Rewriting in Asp.net
URL rewrite/Routing (4.0 framework concept) *
IIS Forum for Extension parsing

 Let me know your comments /feedback for the same

Rate Now: