|
 |
aspx thread: Re: - Trouble using CDO from ASP.NET
Message #1 by "sydney frederick-osborne" <sydney@i...> on Wed, 9 Jan 2002 20:52:25
|
|
I'm having the exact same problem using CDO from a class called from an
ASP.Net (using C#). I do know that if the profileInfo is left as an empty
string, then I get a different error (MAPI_E_LOGON_FAILED).
Any clues would be greately appreciated.
Sydney
> Hi All,
> I have a problem when using CDO from a ASP.Net web
> form. My Mailer component is
> a VB.Net dll
>
> It goes like this
>
> Dim objSession As Object '
> MAPI.Session
> Dim typSystem As Type
>
> typSystem
> Type.GetTypeFromProgID("MAPI.Session")
> objSession
> Activator.CreateInstance(typSystem)
>
> 'Initialisations
> oArgs(gc_iZero) = Missing.Value
> 'ProfileName
> oArgs(gc_iOne) = Missing.Value
> 'ProfilePassword
> oArgs(gc_iTwo) = False 'ShowDialog
> oArgs(gc_iThree) = True 'NewSession
> oArgs(gc_iFour) = -1 'ParentWindow
> oArgs(gc_iFive) = Missing.Value 'NoMail
> oArgs(gc_iSix) = "Bg1Mail" & chr(10) & "sasj"
> 'ProfileInfo
>
> typSystem.InvokeMember("Logon" ,
> BindingFlags.InvokeMethod, Nothing, _
> objSession, oArgs)
>
> In my ASP.Net web application's config file i have set
>
> <identity>
> <impersonation enable="true" user="SSL_PDC\sasj"
> password="mypassword"/>
> </identity>
> inside my security tag. I have set authentication mode
> to windows.
> I have disabled anonymous access from IIS and enabled
> Windows NT Challenge response.
>
> The code for calling the Mailer goes like
>
> Dim wi As System.Security.Principal.WindowsIdentity
> wi
> CType(System.Threading.Thread.CurrentPrincipal.Identity,
> System.Security.Principal.WindowsIdentity)
> wi
> System.Security.Principal.WindowsIdentity.GetCurrent()
> wi.Impersonate()
> oMailer.SendMail(sMsg)
>
> I get an error like
> Collaboration Data Objects -
> [UNKNOWN_ERROR(80010106)]]
> which is actually
> //
> // MessageId: RPC_E_CHANGED_MODE
> //
> // MessageText:
> //
> // Cannot change thread mode after it is set.
> //
> #define RPC_E_CHANGED_MODE
> _HRESULT_TYPEDEF_(0x80010106L)
> from the WinError.h file
> can someone throw me some light on it.
>
> PS: I am using CDO from the MAPI subsytem that is
> installed with W2K.
>
> Thanks in advance.
> Regards,
> Ramanathan N.K.
>
Message #2 by "sydney frederick-osborne" <sydney@i...> on Wed, 9 Jan 2002 21:19:23
|
|
Thanks to your error translation, I think I've figured it out - you need
to initialized the session and logon in a separate thread. Here's the
code that seems to work for me - then I just have to check fLoggedOn
before using the session object.
private Boolean fLoggedOn = false;
public COutlook()
{
//Class initialization - this code could go anywhere
ThreadStart start = new ThreadStart(InitSession);
Thread t = new Thread(start);
t.Start();
}
public void InitSession()
{
if (oSession==null)
{
try
{
String sProfile = "myServer" + System.Environment.NewLine + "myAccount";
Thread.CurrentThread.ApartmentState = ApartmentState.STA;
oSession = (MAPI.Session)Activator.CreateInstance(Type.GetTypeFromProgID
("MAPI.Session"));
oSession.Logon("myUserName","",true,false,-1,true,sProfile);
fLoggedOn = true;
}
catch (System.Exception e)
{
throw new System.Exception("Error initializing Outlook\n"
+ e.Message + "\n" + e.StackTrace);
}
}
}
Sydney
> Hi All,
> I have a problem when using CDO from a ASP.Net web
> form. My Mailer component is
> a VB.Net dll
>
> It goes like this
>
> Dim objSession As Object '
> MAPI.Session
> Dim typSystem As Type
>
> typSystem
> Type.GetTypeFromProgID("MAPI.Session")
> objSession
> Activator.CreateInstance(typSystem)
>
> 'Initialisations
> oArgs(gc_iZero) = Missing.Value
> 'ProfileName
> oArgs(gc_iOne) = Missing.Value
> 'ProfilePassword
> oArgs(gc_iTwo) = False 'ShowDialog
> oArgs(gc_iThree) = True 'NewSession
> oArgs(gc_iFour) = -1 'ParentWindow
> oArgs(gc_iFive) = Missing.Value 'NoMail
> oArgs(gc_iSix) = "Bg1Mail" & chr(10) & "sasj"
> 'ProfileInfo
>
> typSystem.InvokeMember("Logon" ,
> BindingFlags.InvokeMethod, Nothing, _
> objSession, oArgs)
>
> In my ASP.Net web application's config file i have set
>
> <identity>
> <impersonation enable="true" user="SSL_PDC\sasj"
> password="mypassword"/>
> </identity>
> inside my security tag. I have set authentication mode
> to windows.
> I have disabled anonymous access from IIS and enabled
> Windows NT Challenge response.
>
> The code for calling the Mailer goes like
>
> Dim wi As System.Security.Principal.WindowsIdentity
> wi
> CType(System.Threading.Thread.CurrentPrincipal.Identity,
> System.Security.Principal.WindowsIdentity)
> wi
> System.Security.Principal.WindowsIdentity.GetCurrent()
> wi.Impersonate()
> oMailer.SendMail(sMsg)
>
> I get an error like
> Collaboration Data Objects -
> [UNKNOWN_ERROR(80010106)]]
> which is actually
> //
> // MessageId: RPC_E_CHANGED_MODE
> //
> // MessageText:
> //
> // Cannot change thread mode after it is set.
> //
> #define RPC_E_CHANGED_MODE
> _HRESULT_TYPEDEF_(0x80010106L)
> from the WinError.h file
> can someone throw me some light on it.
>
> PS: I am using CDO from the MAPI subsytem that is
> installed with W2K.
>
> Thanks in advance.
> Regards,
> Ramanathan N.K.
>
Message #3 by "sydney frederick-osborne" <sydney@i...> on Tue, 15 Jan 2002 14:33:15
|
|
Oops, spoke too soon. Despite the fact that the session object has class
scope, I only seem to be able to use it in the thread that initializes it,
so this still doesn't seem a viable solution.
Sydney
> Thanks to your error translation, I think I've figured it out - you need
> to initialized the session and logon in a separate thread. Here's the
> code that seems to work for me - then I just have to check fLoggedOn
> before using the session object.
>
> private Boolean fLoggedOn = false;
>
> public COutlook()
> {
> //Class initialization - this code could go anywhere
> ThreadStart start = new ThreadStart(InitSession);
> Thread t = new Thread(start);
> t.Start();
> }
>
>
> public void InitSession()
> {
> if (oSession==null)
> {
> try
> {
> String sProfile = "myServer" + System.Environment.NewLine + "myAccount";
> Thread.CurrentThread.ApartmentState = ApartmentState.STA;
> oSession = (MAPI.Session)Activator.CreateInstance(Type.GetTypeFromProgID
> ("MAPI.Session"));
> oSession.Logon("myUserName","",true,false,-1,true,sProfile);
> fLoggedOn = true;
> }
> catch (System.Exception e)
> {
> throw new System.Exception("Error initializing Outlook\n"
> + e.Message + "\n" + e.StackTrace);
> }
> }
> }
>
> Sydney
>
> > Hi All,
> > I have a problem when using CDO from a ASP.Net web
> > form. My Mailer component is
> > a VB.Net dll
> >
> > It goes like this
> >
> > Dim objSession As Object '
> > MAPI.Session
> > Dim typSystem As Type
> >
> > typSystem
> > Type.GetTypeFromProgID("MAPI.Session")
> > objSession
> > Activator.CreateInstance(typSystem)
> >
> > 'Initialisations
> > oArgs(gc_iZero) = Missing.Value
> > 'ProfileName
> > oArgs(gc_iOne) = Missing.Value
> > 'ProfilePassword
> > oArgs(gc_iTwo) = False 'ShowDialog
> > oArgs(gc_iThree) = True 'NewSession
> > oArgs(gc_iFour) = -1 'ParentWindow
> > oArgs(gc_iFive) = Missing.Value 'NoMail
> > oArgs(gc_iSix) = "Bg1Mail" & chr(10) & "sasj"
> > 'ProfileInfo
> >
> > typSystem.InvokeMember("Logon" ,
> > BindingFlags.InvokeMethod, Nothing, _
> > objSession, oArgs)
> >
> > In my ASP.Net web application's config file i have set
> >
> > <identity>
> > <impersonation enable="true" user="SSL_PDC\sasj"
> > password="mypassword"/>
> > </identity>
> > inside my security tag. I have set authentication mode
> > to windows.
> > I have disabled anonymous access from IIS and enabled
> > Windows NT Challenge response.
> >
> > The code for calling the Mailer goes like
> >
> > Dim wi As System.Security.Principal.WindowsIdentity
> > wi
> > CType(System.Threading.Thread.CurrentPrincipal.Identity,
> > System.Security.Principal.WindowsIdentity)
> > wi
> > System.Security.Principal.WindowsIdentity.GetCurrent()
> > wi.Impersonate()
> > oMailer.SendMail(sMsg)
> >
> > I get an error like
> > Collaboration Data Objects -
> > [UNKNOWN_ERROR(80010106)]]
> > which is actually
> > //
> > // MessageId: RPC_E_CHANGED_MODE
> > //
> > // MessageText:
> > //
> > // Cannot change thread mode after it is set.
> > //
> > #define RPC_E_CHANGED_MODE
> > _HRESULT_TYPEDEF_(0x80010106L)
> > from the WinError.h file
> > can someone throw me some light on it.
> >
> > PS: I am using CDO from the MAPI subsytem that is
> > installed with W2K.
> >
> > Thanks in advance.
> > Regards,
> > Ramanathan N.K.
> >
|
|
 |