PC Review


Reply
Thread Tools Rate Thread

aspnet_wp.exe and COM+

 
 
MP
Guest
Posts: n/a
 
      9th Jan 2007
Hi,

I have a library in which I use the COM+ services dynamically for
creating a Folder in the virtual directory of the Web Application on
the Web Server.


As ASPNET account does not have enough previlages I Impersonate a user
account at run time that has enough previlages to create a folder on
the web server.


Following is my code.


/// <summary>
/// Creates the event email folder.
/// </summary>
/// <param name="eventId">The event id.</param>
/// <returns></returns>
public static bool CreateEventEmailFolder(int eventId)
{


bool isFolderCreated = false;


Impersonate impersonate = new
Impersonate(LogonProvider.LOGON32_PROVIDER_WINNT50);


try {



impersonate.ImpersonateUser(EmailConfiguration.FolderManagerImpersonatedUse*r,

EmailConfiguration.FolderManagerImpersonatedDomain,
EmailConfiguration.FolderManagerImpersonatedPassword);


ServiceConfig config = new
ServiceConfig();


config.TrackingEnabled = true;


config.TrackingAppName =
"EmailFolderCreator Application";


config.TrackingComponentName =
"EmailFolderCreator";


config.Transaction =
TransactionOption.Required;


ServiceDomain.Enter(config);


//Check if the method is running in a
transaction


DirectoryInfo directoryInfo = new
DirectoryInfo(EmailConfiguration.EmailImagesFolderRootPath + "\\Event_"

+ eventId);
if(directoryInfo.Exists) {
directoryInfo.Delete(true);
directoryInfo.Create();
}
else {
directoryInfo.Create();
}


isFolderCreated = true;


}
catch(Exception ex) {
// so, we should abort the transaction
ContextUtil.SetAbort();
// we got an exception so process the
exception

ExceptionValidator.ProcessException(ex);
}
finally {
ServiceDomain.Leave();
impersonate.UndoImpersonation();
}


return isFolderCreated;


}


After the folder is created in the web server the folder is locked by
some process and I am no longer able to use the folder through the web
application for uploading or accessing files within this folder.


When I tried to investigate I found the the "EmailFolderCreator
Application" COM+ application is running contiously in Running services

node of the COM+ MMC under the aspnet_wp.exe client application. If I
kill the aspnet_wp.exe worker process I am able to access the folder. I

believe the aspnet_wp.exe worker process is locking the newly created
folder. Is there any way so that the aspnet_wp.exe worker process does

not lock the folder or releases the "EmailFolderCreator Application"
COM+ application from the running processes node immediately after I
leave the COM+ context.


Thanks in advance for any solutions.


Mahesh Mahangare

 
Reply With Quote
 
 
 
 
Willy Denoyette [MVP]
Guest
Posts: n/a
 
      9th Jan 2007
"MP" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
Hi,

I have a library in which I use the COM+ services dynamically for
creating a Folder in the virtual directory of the Web Application on
the Web Server.


As ASPNET account does not have enough previlages I Impersonate a user
account at run time that has enough previlages to create a folder on
the web server.


Following is my code.


/// <summary>
/// Creates the event email folder.
/// </summary>
/// <param name="eventId">The event id.</param>
/// <returns></returns>
public static bool CreateEventEmailFolder(int eventId)
{


bool isFolderCreated = false;


Impersonate impersonate = new
Impersonate(LogonProvider.LOGON32_PROVIDER_WINNT50);


try {



impersonate.ImpersonateUser(EmailConfiguration.FolderManagerImpersonatedUse*r,

EmailConfiguration.FolderManagerImpersonatedDomain,
EmailConfiguration.FolderManagerImpersonatedPassword);


ServiceConfig config = new
ServiceConfig();


config.TrackingEnabled = true;


config.TrackingAppName =
"EmailFolderCreator Application";


config.TrackingComponentName =
"EmailFolderCreator";


config.Transaction =
TransactionOption.Required;


ServiceDomain.Enter(config);


//Check if the method is running in a
transaction


DirectoryInfo directoryInfo = new
DirectoryInfo(EmailConfiguration.EmailImagesFolderRootPath + "\\Event_"

+ eventId);
if(directoryInfo.Exists) {
directoryInfo.Delete(true);
directoryInfo.Create();
}
else {
directoryInfo.Create();
}


isFolderCreated = true;


}
catch(Exception ex) {
// so, we should abort the transaction
ContextUtil.SetAbort();
// we got an exception so process the
exception

ExceptionValidator.ProcessException(ex);
}
finally {
ServiceDomain.Leave();
impersonate.UndoImpersonation();
}


return isFolderCreated;


}


After the folder is created in the web server the folder is locked by
some process and I am no longer able to use the folder through the web
application for uploading or accessing files within this folder.


When I tried to investigate I found the the "EmailFolderCreator
Application" COM+ application is running contiously in Running services

node of the COM+ MMC under the aspnet_wp.exe client application. If I
kill the aspnet_wp.exe worker process I am able to access the folder. I

believe the aspnet_wp.exe worker process is locking the newly created
folder. Is there any way so that the aspnet_wp.exe worker process does

not lock the folder or releases the "EmailFolderCreator Application"
COM+ application from the running processes node immediately after I
leave the COM+ context.


Thanks in advance for any solutions.


Mahesh Mahangare


This is only a part of the code, so it's hard to tell what's happening here, show us how you
call this method from asp.net and how you release the interface.
Also you have to tell us whether this is a COM+ "library" or a "server" application, if it's
a "server" style, then you should run this server in the context of an administrator and
remove the impersonation stuff. Another remark is that you don't need to set the Transaction
required attribute, there is no transactional resource manager involved here so why bother
the DTC with this?
If it's a library style, then you don't need the Transaction nor the TrackingEnabled
attribute.

Willy.

 
Reply With Quote
 
MP
Guest
Posts: n/a
 
      10th Jan 2007
Hi,

1) We call this method from Asp.net in the folowing manner.

This is the Save method inside our business object that calls the
previously posted code:

public void Save() {

using(TransactionScope scope = new TransactionScope()) {

using(SqlConnection cn = new
SqlConnection(DatabaseConnection.MyConnection)) {

cn.Open();

if(this.IsDeleted) {

//do db delete work

}

else {

if(this.IsNew) {

//do db insert work

}

else {

//do db update work

}



if(this.IsNew) {



mEventId =
(int)cm.Parameters["@eventId"].Value; //if this was an insert get the
id



bool isFolderCreated =
EmailFolderCreator.CreateEventEmailFolder(mEventId);



if(isFolderCreated == false) {

throw new
BusinessLayerException(ResourceStrings.GetResourceString("EmailFolderNotCreated"));

}

}

}

}

scope.Complete();

}

}

2) For releasing the interface i am not sure what you mean by, Can
please clear a bit more on this point. I believe right now we are not
releasing the interface.

3) I belive this is a server application. For more details you can
refer to following links http://www.15seconds.com/issue/030930.htm







Willy Denoyette [MVP] wrote:
> "MP" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> Hi,
>
> I have a library in which I use the COM+ services dynamically for
> creating a Folder in the virtual directory of the Web Application on
> the Web Server.
>
>
> As ASPNET account does not have enough previlages I Impersonate a user
> account at run time that has enough previlages to create a folder on
> the web server.
>
>
> Following is my code.
>
>
> /// <summary>
> /// Creates the event email folder.
> /// </summary>
> /// <param name="eventId">The event id.</param>
> /// <returns></returns>
> public static bool CreateEventEmailFolder(int eventId)
> {
>
>
> bool isFolderCreated = false;
>
>
> Impersonate impersonate = new
> Impersonate(LogonProvider.LOGON32_PROVIDER_WINNT50);
>
>
> try {
>
>
>
> impersonate.ImpersonateUser(EmailConfiguration.FolderManagerImpersonatedUse*r,
>
> EmailConfiguration.FolderManagerImpersonatedDomain,
> EmailConfiguration.FolderManagerImpersonatedPassword);
>
>
> ServiceConfig config = new
> ServiceConfig();
>
>
> config.TrackingEnabled = true;
>
>
> config.TrackingAppName =
> "EmailFolderCreator Application";
>
>
> config.TrackingComponentName =
> "EmailFolderCreator";
>
>
> config.Transaction =
> TransactionOption.Required;
>
>
> ServiceDomain.Enter(config);
>
>
> //Check if the method is running in a
> transaction
>
>
> DirectoryInfo directoryInfo = new
> DirectoryInfo(EmailConfiguration.EmailImagesFolderRootPath + "\\Event_"
>
> + eventId);
> if(directoryInfo.Exists) {
> directoryInfo.Delete(true);
> directoryInfo.Create();
> }
> else {
> directoryInfo.Create();
> }
>
>
> isFolderCreated = true;
>
>
> }
> catch(Exception ex) {
> // so, we should abort the transaction
> ContextUtil.SetAbort();
> // we got an exception so process the
> exception
>
> ExceptionValidator.ProcessException(ex);
> }
> finally {
> ServiceDomain.Leave();
> impersonate.UndoImpersonation();
> }
>
>
> return isFolderCreated;
>
>
> }
>
>
> After the folder is created in the web server the folder is locked by
> some process and I am no longer able to use the folder through the web
> application for uploading or accessing files within this folder.
>
>
> When I tried to investigate I found the the "EmailFolderCreator
> Application" COM+ application is running contiously in Running services
>
> node of the COM+ MMC under the aspnet_wp.exe client application. If I
> kill the aspnet_wp.exe worker process I am able to access the folder. I
>
> believe the aspnet_wp.exe worker process is locking the newly created
> folder. Is there any way so that the aspnet_wp.exe worker process does
>
> not lock the folder or releases the "EmailFolderCreator Application"
> COM+ application from the running processes node immediately after I
> leave the COM+ context.
>
>
> Thanks in advance for any solutions.
>
>
> Mahesh Mahangare
>
>
> This is only a part of the code, so it's hard to tell what's happening here, show us how you
> call this method from asp.net and how you release the interface.
> Also you have to tell us whether this is a COM+ "library" or a "server" application, if it's
> a "server" style, then you should run this server in the context of an administrator and
> remove the impersonation stuff. Another remark is that you don't need to set the Transaction
> required attribute, there is no transactional resource manager involved here so why bother
> the DTC with this?
> If it's a library style, then you don't need the Transaction nor the TrackingEnabled
> attribute.
>
> Willy.


 
Reply With Quote
 
Willy Denoyette [MVP]
Guest
Posts: n/a
 
      10th Jan 2007
"MP" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
Hi,

1) We call this method from Asp.net in the folowing manner.

This is the Save method inside our business object that calls the
previously posted code:

public void Save() {

using(TransactionScope scope = new TransactionScope()) {

using(SqlConnection cn = new
SqlConnection(DatabaseConnection.MyConnection)) {

cn.Open();

if(this.IsDeleted) {

//do db delete work

}

else {

if(this.IsNew) {

//do db insert work

}

else {

//do db update work

}



if(this.IsNew) {



mEventId =
(int)cm.Parameters["@eventId"].Value; //if this was an insert get the
id



bool isFolderCreated =
EmailFolderCreator.CreateEventEmailFolder(mEventId);



if(isFolderCreated == false) {

throw new
BusinessLayerException(ResourceStrings.GetResourceString("EmailFolderNotCreated"));

}

}

}

}

scope.Complete();

}

}

2) For releasing the interface i am not sure what you mean by, Can
please clear a bit more on this point. I believe right now we are not
releasing the interface.

3) I belive this is a server application. For more details you can
refer to following links http://www.15seconds.com/issue/030930.htm


Oh I see, you are using COM+ services without Components, a COM+ 1.5 feature which allows
you to get (some) COM+ services without deriving from ComponentServices. Such components do
run "in-process", that means they run in the security context of the caller, so here the
caller is allowed to call LogonUser() (which I suppose you do in your Impersonate method)
and the CreateEventEmailFolder Method doesn't need distributed transaction services either.
I suggest you to drop this ServiceDomain completely and make it a simple "regular" method
that only impersonates in order to create/delete a folder.

Willy.



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
aspnet_wp.exe MJ Microsoft ASP .NET 0 4th Nov 2003 04:44 PM
aspnet_wp Bill Burris Microsoft ASP .NET 2 29th Oct 2003 02:41 AM
aspnet_wp.exe skg Microsoft C# .NET 0 29th Aug 2003 01:44 PM
RE: aspnet_wp,exe Jim Cheshire Microsoft ASP .NET 0 29th Jul 2003 09:53 PM
Re: aspnet_wp,exe S. Justin Gengo Microsoft ASP .NET 0 29th Jul 2003 08:28 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:05 PM.