Using .NET Assembly (DLL) in ASP page


1. Create a Assembly file using following:
        File >> New >> Project >> Class Library >> Name = MyLibCSharp
 
2. Add a function HelloWorld. Code will look as follows:

using System;

using System.Collections.Generic;

using System.Text;

using System.Runtime.InteropServices;

namespace MyLibCsharp

{

[Guid(“FE1EB79E-3513-487e-ADFF-2B61C6CB4730”)]

[ComVisible(true)]

public class Class1

{

public String HelloWorld(String name)

{

return (“Hellow World; Welcome “ + name);

}

}

}

3. Sign the Assembly (To enable it to be used by multiple Applications):

Go to Project >> MyLibCSharp Properties >> Signing >> Sign the Assembly >> New >> Key.snk

4. Enable for COM Interop:

Go to Project >> MyLibCSharp Properties >> Build >> Output >> Check the “Register for COM interop.

5. Build the Assembly.

6. Add to GAC using “Visual Studio Command Prompt” the assembly is located in DEBUG/RELEASE folder.

gacutil -I MyLibCSharp.dll

7. Execute the following:

Regasm /tlb /codebase MyLibCSharp.dll

8. ASP code:

<%

Dim foo

set foo = Server.CreateObject(“MyLibCSharp.Class1”)

Response.Write (foo.HelloWorld(“test”))

%>

9. To unregister the assembly

Regasm /unregister MyLibCSharp.dll

10. And to remove the same from GAC (Global assembly cache)

Go to

C:\WINDOWS\assembly

find the assembly you want to remove

select it , right click it and select uninstall

Bye

 

Unable to start debugging. The Machine Debug Manager is disabled


Occasionally I used to receive this error

“Unable to start debugging. The Machine Debug Manager is disabled” when I try to run the solution from visual studio in debug mode.

The reason for this was Machine Debug Manager was in disabled state or not started.

So the solution for this is

 

1) Go to control panel.

2) Then Administrative Tools

3) Then services.

4) In services find the service named Machine debug manager.

 

Enable the service and start it if disabled or stopped.

 

Bye

Reflector -Nice tool for .NET developer


Reflector is a nice tool developed by Lutz Roeder.

It is somewhat similar to .Net ILDASM (Intermediate Language Dissembler).

The best thing about it is that we can even view the source code that also in different languages

C#, VB.NET, Delphi even the IL code itself.

 

This is the link

http://www.aisto.com/roeder/dotnet/

 

There are other good tools as well.

 

Do check it.

Searching for an email id in Active Directory using C#


These are the steps i followed
1) Created a new windows application.
2) Added reference to System.DirectoryServices dll
3) Added a textbox(where the email id will be entered) and a button in the form.
4) On btnClick this is the code i wrote

we use the DirectorySearcher class to query the directory and read the attributes of the objects found
DirectorySearcher Dsearch = new DirectorySearcher();
EmailID = txtEmailID.Text;

The filter in an LDAP query restricts the objects that the search will return. It is the equivalent of the WHERE clause


Dsearch.Filter = “(&(objectCategory=person)(sAMAccountName=*)(mail=”+EmailID+”))”;
objectCategory=This attribute is meant to be used to group common types of objects together so that we can search across all of them. Both user and contact classes share the same objectCategory value of person.
sAMAccountName =To separate users from contacts efficiently we can make user of sAMAccountName attribute
mail =Finally the mail attribute is the attribute which we looking for. Setting it to the value entered in the textbox by the user

SearchResult sResult = Dsearch.FindOne();


A SearchResult represents a single item from a result set.The FindOne method returns a single SearchResult, representing the first result in the underlying result set. Internally, this method is calling the FindAll method and returning the first SearchResult from the SearchResultCollection

if (sResult != null)
{
txtInfo.Content = “This email id already existing”;
}
else
{
txtInfo.Content = “This email id is not found”;
}

That’s it.

%d bloggers like this: