aspnet_wp.exe and COM+

M

MP

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
 
W

Willy Denoyette [MVP]

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.
 
M

MP

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
 
W

Willy Denoyette [MVP]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top