Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

File path problem
pkatsoulas
#1 Posted : Tuesday, September 20, 2011 4:04:07 PM(UTC)
Groups: Member
Joined: 8/1/2011(UTC)
Posts: 33

The following problem does not happen when running my application within VS 2010 using either a Debug or Release build. It also does not happen running my application on a server under IIS. It does however happen running my application under UltiDev Pro.

My application runs a process that requires a file. If I pass it a file path such as C:\\Program Files\\MyFolder\\MyFile.txt, the process produces an exception saying that file "C:\\Program" does not exist. Obviously the space between Program and Files is causing a problem.

Also, if I use a file path such as C:\\MyFolder\\MyFile.txt which has no spaces, I get an exception saying "Permission denied."

As stated above, none of this happens in my other environments. UltiDev Pro (2.0.9) is the only difference. Any thoughts on this?
Ultidev Team
#2 Posted : Tuesday, September 20, 2011 4:20:07 PM(UTC)
Ultidev Team

Groups: Administration
Joined: 11/3/2005(UTC)
Posts: 2,253

Thanks: 28 times
Was thanked: 60 time(s) in 59 post(s)
Hi there!

Re: space in a file path: it's not quite clear to us where do you pass the path from and to, and where exactly you see the error generated. Could you please include full stack trace and maybe attach a screenshot to your response?

Re: permissions denied: Does this happen when you run the application under UWS Interactive Host? The reason we ask is that an application registered with UWS is usually running under Network Service user account, which is often the same for IIS, but it really depends on what user identity is used for IIS AppPool or worker process. When you run your application under Visual Studio development server, or with UWS Interactive Host, your application is running inside an process that has access rights of your Windows login user. All these situations can be slightly different, so depending on what user account is selected for UWS host process and IIS AppPool, you may see different results. Both UWS Explorer and UWS Interactive Host show user context of corresponding hosts.

As a rule, web applications run in a secure, restricted user context on the server, because Internet-facing applications are subject to constant hacking attempts. If your application or our server is hacked, then attacker gets control under the security context of the hacked process user. If user is powerful - hacker can go on and compromise your entire machine or even a network. If user is restricted, the hacker is likely never to be able to do much damage outside of the application. If you need higher privileges for a part of your business logic, consider placing it in a ServicedComponent of server type. If your application runs in a very safe, low-threat environment, then you may consider running your application in UWS under Local System user, which is almost as powerful as Administrator and has access to most files and other resources on the server.

Please let us know if this information was helpful.

Best regards,
UltiDev Team.
Please donate at http://www.ultidev.com/products/Donate.aspx to help us improve our products.
pkatsoulas
#3 Posted : Wednesday, September 21, 2011 9:58:10 AM(UTC)
Groups: Member
Joined: 8/1/2011(UTC)
Posts: 33

The exception is thrown by my application. There is no stack trace but simply the message generated by the Windows process that is being used. The following C# method eventually gets called after the user clicks a submit button from an event handler.

private string ExecuteRScript(string a_identifier, EquationScriptData a_arguments)
{
System.IO.StreamReader scriptOutput = null;
string scriptString = null;
System.Diagnostics.ProcessStartInfo processInfo = null;
System.IO.StreamReader scriptErrorOutput = null;
string scriptErrorString = null;
System.Diagnostics.Process process = null;

if (m_advancedFitting)
{ // Advanced fitting approach
if (a_identifier.Equals(IDENTIFIER_RESOURCE_UNITS))
{ // Resource units or resource work.
processInfo =
new System.Diagnostics.ProcessStartInfo(m_rLanguageExecutable,
m_rScriptFileName +
" --slave --nron --no-save --no-restore --no-environ --args filename " +
m_tempFileName + " simlen 1000 mub0 30 mub1 40 mub2 50" +
" sigmab0 5 sigmab1 5 sigmab2 5" +
" jumpsigmab0 5 jumpsigmab1 5 jumpsigmab2 5");
}
else // Deliverable, PRate, AScope, Defect Removal, Potential Defects
{
processInfo = new System.Diagnostics.ProcessStartInfo(m_rLanguageExecutable,
m_rScriptFileName +
" --slave --nron --no-save --no-restore --no-environ --args filename " +
m_tempFileName + " simlen " + a_arguments.NumberOfIterations +
" mub0 " + a_arguments.StartCoefficient3 +
" mub1 " + a_arguments.StartCoefficient1 +
" mub2 " + a_arguments.StartCoefficient2 +
" sigmab0 " + a_arguments.SearchWidth3 +
" sigmab1 " + a_arguments.SearchWidth1 +
" sigmab2 " + a_arguments.SearchWidth2 +
" jumpsigmab0 " + a_arguments.JumpWidth3 +
" jumpsigmab1 " + a_arguments.JumpWidth1 +
" jumpsigmab2 " + a_arguments.JumpWidth2);
}
}
else // Simple fitting approach. ***** Not Used at This Time *****
{
processInfo =
new System.Diagnostics.ProcessStartInfo(m_rLanguageExecutable,
m_rScriptFileName +
" --slave --no-save --no-restore --no-environ --args filename " +
m_tempFileName);
}

processInfo.UseShellExecute = false;
processInfo.ErrorDialog = false;
processInfo.CreateNoWindow = true;
processInfo.RedirectStandardOutput = true;
processInfo.RedirectStandardError = true;
try
{
process = System.Diagnostics.Process.Start(processInfo);
scriptOutput = process.StandardOutput;
scriptString = scriptOutput.ReadToEnd();
scriptErrorOutput = process.StandardError;
scriptErrorString = scriptErrorOutput.ReadToEnd();
if (!process.HasExited)
{
if (!process.WaitForExit(120000)) // 2 minutes
{ // Process never exited.
throw (new GeneralException("Process did not complete in a timely fashion."));
}
}
// Process has exited.
process.Refresh();
if (process.ExitCode != 0)
{ // Process produced error.
throw (new GeneralException("Error code = " + process.ExitCode + " Error message = " + scriptErrorString));
}

if (scriptString == null)
{
throw (new GeneralException("R Script null string"));
}
}
catch (Exception e)
{
throw (new GeneralException("Equation Creation: " + e.Message));
}
finally
{
scriptOutput.Close();
scriptErrorOutput.Close();
process.Close();
process.Dispose();
}

return scriptString;
}


The process.ExitCode value is not zero so the exception is created and thrown. It is:

Equation Creation: Error code = 2 Error message = Fatal error: cannot open file 'C:\Program': No such file or directory

As stated in my first message, the file path has "Program Files" in it and the space is causing the problem. The file path value is in variable m_rScriptFileName.

This file path is initially generated in the submit button event handler method using the following code:

string rScriptFileName = Server.MapPath("~") + THE_ADVANCED_FITTING_APPROACH;

In VS 2010 and under IIS, there are double \ (\\) between folders. Under UltiDev Pro, I get single \ (\). However, even when I hardwire variable rScriptFileName to have double \, I get the same exception.

I hope this helps with the first issue.

Moving on to the second issue, I am running the application under UWS Explorer. The Default Shared Host Process contains ASP.NET 4 and NetworkService. Note that I am only using UWS on client machines. We are presently using IIS on servers.

I did not have this problem when I was using Cassini. I guess I don't understand why I would have to resort to using the ServicedComponent approach or setting up as a Local System user? If I am forced to running under Local System user, how do I do it? Can I do it in my setup just as I do the UWS registration?

Thanks

Ultidev Team
#4 Posted : Wednesday, September 21, 2011 6:42:35 PM(UTC)
Ultidev Team

Groups: Administration
Joined: 11/3/2005(UTC)
Posts: 2,253

Thanks: 28 times
Was thanked: 60 time(s) in 59 post(s)
Hi there!

Yes, you definitely want to try to run your application under "Local System". If you ran your application under legacy UltiDev Cassini, then it should work, because old Cassini ran under Local System.

Using UWS Explorer you can select your application and click "Move to another process" and create a new host if necessary. If that works, then you will need either to change your application installer to register the application with Local System host, or if your are hosting the application on the Internet, move the logic that is currently in that external EXE, to the ServicedComponent. It would look much better and would be way more convenient to call a function instead of passing lots of command line parameters to an external program.

We are surprised to learn that IIS allowed you to start external process. What AppPool identity is your application is running under? In general, if your application can't start an external process under UWS, then IIS settings should be also quite different from defaults, to allow external exe to be launched.

Please let us know what you have found.

Best regards,
UltiDev Team.
Please donate at http://www.ultidev.com/products/Donate.aspx to help us improve our products.
pkatsoulas
#7 Posted : Thursday, September 22, 2011 8:39:30 AM(UTC)
Groups: Member
Joined: 8/1/2011(UTC)
Posts: 33

With regards to IIS, our application is running in the Default Web Site whose identity is NetworkService. This seems to run counter to your thinking. All the other IIS settings are the defaults.

I selected my application in the UWS Explorer but when I clicked "Move to Another Host Process" it did nothing. I then selected the parent node which is "Default Shared Host Process" which has entries for "Host Process User", "Host Process Command Line", "Host Name", and "Host ID". This does not seem like a good place to make changes since other applications could be children of this node.

So, you are saying that IIS should not work when using NetworkService but it does. On the other hand, UWS does not. If you feel that I must use Local System, please explain what I must do in the UWS Explorer to change it. If this works, I will make the changes in my setup.

Thanks.
Ultidev Team
#9 Posted : Thursday, September 22, 2011 12:09:09 PM(UTC)
Ultidev Team

Groups: Administration
Joined: 11/3/2005(UTC)
Posts: 2,253

Thanks: 28 times
Was thanked: 60 time(s) in 59 post(s)
Hi there!

It's strange indeed. There is a change in the upcoming build that may fix this problem, but for now, to test whether this is access rights problem, please run the application in Local System host. Attached screen shot shows how to do that (please let us know if you still have a problem doing that). You can also simply create a new application pointing to the same physical location, and put this application into Local System host.

Please let us know what you have found.

Best regards,
UltiDev Team.
Ultidev Team attached the following image(s):
Ultidev Team attached the following image(s): MovingAppToNewHost.png
Please donate at http://www.ultidev.com/products/Donate.aspx to help us improve our products.
pkatsoulas
#10 Posted : Thursday, September 22, 2011 3:50:57 PM(UTC)
Groups: Member
Joined: 8/1/2011(UTC)
Posts: 33

Having moved the file in question to a path with no spaces in it, using a Local System host solved the "permission denied" problem. However, the "space in a folder name" problem still exists. I think that I might be able to go back to a Network Service host once the space problem is solved because the file in question will be back in the target folder which is under folder Program Files. I will also include your new build to see if it solves the problem.

So, do you have any thoughts on why a space in a folder name is causing a problem when the exact same code runs fine under VS 2010 and IIS?
Ultidev Team
#11 Posted : Thursday, September 22, 2011 4:22:05 PM(UTC)
Ultidev Team

Groups: Administration
Joined: 11/3/2005(UTC)
Posts: 2,253

Thanks: 28 times
Was thanked: 60 time(s) in 59 post(s)
Hi!

We have just noticed that if m_rScriptFileName = "c:\program files\etc", then
Code:
m_rScriptFileName + " --slave --nron..."
=
"c:\program files\etc --slave --nron..."

As you can see, to your program it will look like you have following list of parameters: "c:\program", "files\etc", "--slave", "--nron", etc.

To avoid this, you should do something like
Code:
new System.Diagnostics.ProcessStartInfo(m_rLanguageExecutable, "\"" + m_rScriptFileName + "\" --slave --nron...")

We still don't understand how this can work under other web servers, because spaces in m_rScriptFileName value clearly create a problem for the command line.

Please let us know if this information was helpful.

Best regards,
UltiDev Team.
Please donate at http://www.ultidev.com/products/Donate.aspx to help us improve our products.
pkatsoulas
#12 Posted : Thursday, September 22, 2011 5:27:41 PM(UTC)
Groups: Member
Joined: 8/1/2011(UTC)
Posts: 33

Your suggestion pointed me to the solution. The following did it:

m_rLanguageExecutable,"\"" + m_rScriptFileName + "\"" + " --slave --nron --no-save --no-restore --no-environ "

This also allowed me to return to a NetworkService host again since m_rScriptFileName can now be read in the target folder (where it is normally installed) which was under Program Files. Obviously, the user can pick a target folder somewhere where permission will be denied but to bad, they shoudn't be doing that.

Obviously, the folder space issue was my problem. The fact that the problem didn't show up in IIS through me off. Regardless, thanks for the help.
Ultidev Team
#13 Posted : Thursday, September 22, 2011 7:12:34 PM(UTC)
Ultidev Team

Groups: Administration
Joined: 11/3/2005(UTC)
Posts: 2,253

Thanks: 28 times
Was thanked: 60 time(s) in 59 post(s)
Great! We are glad the issue is resolved.

Thank you for using UltiDev products,
UltiDev Team.
Please donate at http://www.ultidev.com/products/Donate.aspx to help us improve our products.
Guest
#8 Posted : Wednesday, March 21, 2012 9:10:16 AM(UTC)
Groups:

Message was deleted by a Moderator.
Rss Feed  Atom Feed
Users browsing this topic
Guest (3)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You can vote in polls in this forum.