Gitlab commands not working through IIS web application - c#

I have a requirement to clone gitlab project and get commit details through c# application. I am able to execute all gitlab commands such as clone, pull, fetch, show etc in my machine through command line and mvc application. Same commands are not working when application in deployed on IIS server. clone and pull commands are not working, they are simply hanged and no output is produced. Can someone tell me what settings are required to be done to make gitlab commands work through web application. I have spent 4 days on this issue and still not able to resolve.My c# code is below
compiler.StartInfo.FileName = #"C:\Windows\System32\cmd.exe";
compiler.StartInfo.Arguments = "git pull";
compiler.StartInfo.UseShellExecute = false;
compiler.StartInfo.WorkingDirectory = local_repository;
compiler.StartInfo.RedirectStandardOutput = true;
compiler.StartInfo.RedirectStandardError = true;
compiler.StartInfo.RedirectStandardInput = true;
compiler.StartInfo.CreateNoWindow = true;
compiler.StartInfo.Verb = "runas";
compiler.StartInfo.ErrorDialog = false;
compiler.Start();
try
{
compiler.WaitForExit();
exitcode = compiler.ExitCode;
}
git clone "my_gitlab_url"
git pull

Related

Unable to execute command ng build in iis hosted asp.net web app using cmd.exe

I want to execute ng build using c# code to build my angular project. I have hosted by c# application on IIS. When I am executing code I am getting error:
ng' is not recognized as an internal or external command,\r\noperable program or batch file.\r\n
I have created another application that I have not hosted on IIS and I am executing that with locally using visual studio. In that same code is working property. I am unable to figure out issue with iis. My code is as below.
private void buildAngular()
{
try
{
Process p = new Process();
p.EnableRaisingEvents = true;
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.WorkingDirectory = #"D:\AngularToBuild\AngularProject";
p.StartInfo.UseShellExecute = false;
//p.StartInfo.Arguments = #"/c echo off > fff1.txt";
p.StartInfo.Arguments = #"/c ng build";
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.Start();
p.Exited += new EventHandler(myProcess_Exited);
var err = p.StandardError.ReadToEnd();
var msg = p.StandardOutput.ReadToEnd();
Console.WriteLine("error", msg, err);
}
catch (Exception ex)
{
Console.WriteLine("error");
}
}
private void myProcess_Exited(object sender, System.EventArgs e)
{
Console.WriteLine("Exit time: {0}\r\n" +
"Exit code: {1}\r\nElapsed time: {2}");
}
ng.cmd is located in C:\Users\<user name>\AppData\Roaming\npm but the default application pool identity has no permissions to access that folder.
Grant NTFS read permissions to application pool identity and make sure that folder is included in the PATH environment system variable.
The default app pool identity for DefaultAppPool is IIS APPPOOL\DefaultAppPool.. You need to grant permissions to this account.
Open Windows Explorer
Go to C:\Users\<user name>\AppData\Roaming
Right click on npm
Select Properties.
Select Security tab
Click on edit button
Click on addbutton
Enter IIS APPPOOL\DefaultAppPool on the text box
Click Ok button
Ensure Read and Execute, List Folder and Content and Read Permissions are checked.
Click Ok
Click Ok

How to edit Firewall rules in code successfully on a Worker Role Instance?

I'm trying some code that works locally but it doesn't work on my cloud instance. I assume it may be permissions related, but I'm unable to fix it yet. Here is what I have which works when I debug my worker role locally, but nothing happens when it is published (on staging right now).
string strCmdText = string.Format("advfirewall firewall add rule name=\"BlockU\" protocol=any dir=in action=block remoteip={0}", ip);
ProcessStartInfo psi = new ProcessStartInfo("netsh.exe", strCmdText);
psi.RedirectStandardOutput = true;
psi.UseShellExecute = false;
psi.CreateNoWindow = true;
try
{
Process.Start(psi);
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
I have also tried using the
psi.Verb = "runas";
but that did not help either.
Finally I tried the firewall api like so. This also worked locally, but threw an access denied error on the last line.
INetFwRule2 inboundRule = (INetFwRule2)Activator.CreateInstance(Type.GetTypeFromProgID("HNetCfg.FWRule"));
inboundRule.Enabled = true;
inboundRule.RemoteAddresses = ip;
inboundRule.InterfaceTypes = "All";
inboundRule.Protocol = (int)NetFwTypeLib.NET_FW_IP_PROTOCOL_.NET_FW_IP_PROTOCOL_ANY;
inboundRule.Name = "BlockU Part 2";
//inboundRule.Profiles = currentProfiles;
inboundRule.Action = NET_FW_ACTION_.NET_FW_ACTION_BLOCK;
// Now add the rule
INetFwPolicy2 firewallPolicy = (INetFwPolicy2)Activator.CreateInstance(Type.GetTypeFromProgID("HNetCfg.FwPolicy2"));
firewallPolicy.Rules.Add(inboundRule);
I found over on the azure forums that I need to enable my Worker Role to run with elevated privileges. This can be done in the ServiceDefinition.csdef file by adding the following attribute to the WorkerRole element
<WorkerRole name="CloudService.Worker" vmsize="ExtraSmall"
enableNativeCodeExecution="true">
and also by adding a
<Runtime executionContext="elevated" />
element inside the WorkerRole element.
Both sets of code ran successfully with the configuration changes.
I've found an interesting post in msdn blogs that uses a library which simplify the configuration of firewall rule, may be it will resolve your issue,
http://blogs.msdn.com/b/securitytools/archive/2009/08/21/automating-windows-firewall-settings-with-c.aspx
on a

Unable to read the full output redirected from Console application - SVN Update automation

I am trying to automate the update procedure for the svn update using the console application. I use the following code below.
ProcessStartInfo svnUpdate = new ProcessStartInfo();
svnUpdate.Arguments = string.Format("update \"{0}\" -r {1}", destination, revisionNo);
svnUpdate.FileName = "svn.exe";
svnUpdate.CreateNoWindow = true;
svnUpdate.UseShellExecute = false;
svnUpdate.WindowStyle = ProcessWindowStyle.Hidden;
svnUpdate.RedirectStandardOutput = true;
svnUpdate.RedirectStandardError = true;
Process p = new Process();
p.StartInfo = svnUpdate;
p.EnableRaisingEvents = true;
p.Start();
svnOutPut = p.StandardOutput.ReadToEnd();
p.WaitForExit();
if (p.HasExited)
{
Console.WriteLine("Received Output Test : " + svnOutPut);
}
p.Close();
p.Dispose();
The above code works fine if there are no errors returned with update command. If there are some errors I am able to get only the First line of the outpput returned but when I set the code below the console gives me the full error text.
svnUpdate.RedirectStandardOutput = false;
svnUpdate.RedirectStandardError = false;
Sample outpput when I have the Redirection to false.
Updating 'C:\TestSvnRepo':
svn: E175002: Unable to connect to a repository at URL 'http://svnrepositoryAdd/svn/TestSvnRepo'
svn: E175002: Unexpected HTTP status 500 'Internal Server Error' on '/svn/TestSvnRepo'
svn: E720003: Additional errors:
svn: E720003: Could not open the requested SVN filesystem
Sample output received in string when I have the redirection to True.
Updating: 'C:\TestSvnRepo':
I believe the output that you're missing is sent through STDERR, not STDOUT. In your code, you're only looking at STDOUT (svnOutPut = p.StandardOutput.ReadToEnd();)
You need to read STDERR as well - p.StandardError.ReadToEnd();
As an aside, I would recommend that rather than automating svn.exe and adding both the application and environment dependency (IOW, your app requires that svn.exe be present on the system and be in either %PATH% or a known absolute path that you specify), you use SharpSVN which provides a .NET implementation of the SVN API itself.

invoking a third party app through asp.net/C# code- UI gets "stuck"

Iam trying to write a webpage where iam invoking a third part app (.exe) from the code
using
System.Diagnostics.Process.Start("app.exe")
The app fires and it starts to open up the GUI but gets "stuck" after about 3-4 seconds and just sits there.. Its not an app issue as it runs fine when I run it through the local admin account on the web-server. I also tried invoking this app through the admin account using
Start(
string fileName,
string userName,
SecureString password,
string domain)
but that didnt help. Any help is appreciated.
Its better to set some initialization before you run it, and not run it with the default settings that are not for the web, so try this code:
Process compiler = new Process();
// Make sure that the application.exe can be found
compiler.StartInfo.FileName = "c:\\app.exe";
compiler.StartInfo.StandardOutputEncoding = System.Text.Encoding.UTF8;
compiler.StartInfo.UseShellExecute = false;
compiler.StartInfo.CreateNoWindow = false;
compiler.StartInfo.RedirectStandardError = true;
compiler.StartInfo.RedirectStandardOutput = true;
compiler.StartInfo.RedirectStandardInput = true;
// here I run it
compiler.Start();
compiler.StandardInput.Flush();
compiler.StandardInput.Close();
// here I get the output
string cReadOutput = compiler.StandardOutput.ReadToEnd();
compiler.WaitForExit();
compiler.Close();

Call SVN console client from C#

any ideas how to create a branch from a trunk url in a c# console app.
im trying to create a branching tool, that will create all new branches. for the life of me i have tried almost everything. Sharpsvn has given me no luck.
string command = "cp https://svn:8443/svn/blah/trunk \\ https://svn:8443/svn/blah/branches/newBranch \\";
Process svnBranchProcess = new Process();
svnBranchProcess.StartInfo.FileName = "Svn.exe";
svnBranchProcess.StartInfo.Arguments = command;
svnBranchProcess.StartInfo.UseShellExecute = false;
svnBranchProcess.StartInfo.RedirectStandardOutput = true;
svnBranchProcess.Start();
string output = svnBranchProcess.StandardOutput.ReadToEnd();
svnBranchProcess.WaitForExit();
Console.WriteLine("Output:");
Console.WriteLine(output);
This is the error that i get
svn : Cannot mix repository and working copy sources
Basically i want to be able to create a branch off trunk and then update some externals. why is this such a mission?
thanks for any help :)

Categories

Resources