I have created a Web API for installing the latest version of exe using Web API and hosted via IIS Server.
The process is Downloading -> Closing -> Installing Exe via CLI.
The downloading process is working fine.
While closing the running exe exception caught "Access is denied."
Following is the code block I am using to close the running exe.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using WebGrease;
namespace API.Controllers
{
public class TestController : ApiController
{
public string Get()
{
foreach (Process p in Process.GetProcessesByName("APPLICATION NAME"))
{
try
{
p.Kill();
p.WaitForExit();
}
catch (Exception ex)
{
return ex.Message.ToString();
}
}
return "Aborted";
}
}
}
While debugging the same this code block is working fine but when testing on another computer it says "Access is Denied".I guess this issue is related to Windows Authentication.
Debugging the above code will take the current logged window account as the credential to run the WebAPI. However, some other built-in system account will be used when the project is hosted in the IIS. This is commonly determined by the IIS application pool identity.
Although granting the administrative permission to IIS is risky for website security, at least this could solve your problem.
Feel free to let me know if the problem still exists.
Related
I know this error maybe very popular and there are many people asking about it. I have read through other threads but can not seem to find a solution applicable to my scenario.
I am new to ASP.NET programming, am using vs 2013 ultimate, IIS express on my laptop with Windows 8.1.
I have created a new website using WebForms and I was testing the upload function to my local machine running IIS express that came with VS2013.
My code behind is as simple as
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class MyWebForm : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
string name = TextBox1.Text;
string type = DropDownList1.SelectedValue;
string filename = FileUpload1.FileName;
FileUpload1.SaveAs(Server.MapPath("~/Content"));
}
}
}
Ran it and got this error:
{"Access to the path 'C:\\Users\\xxx\\Documents\\Visual Studio 2013\\WebSites\\WebFormDemo\\Content' is denied."}
I understand that it is an unauthorized access due to lack of privilege, but my question is how do I give access to my application? I have admin right on my machine, run it locally so the firewall should not be an issue. Some threads suggested to go to IIS manager and adjust the right to DefaultPool but I do not think I have InetMgr on my Windows 8.1,
How do I solve the unauthorized access for my case?
I was always able to launch chromedriver server locally but then I tried to do this remotely and since then I am unable to launch it. I reinstalled chrome as well the chrome driver but nothing seems to fix this. Even when I give the path of my driver it won't launch.
using OpenQA.Selenium;
using OpenQA.Selenium.Support;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.IE;
using OpenQA.Selenium.Chrome;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenQA.Selenium.Safari;
using OpenQA.Selenium.Interactions;
namespace TestWebDriver
{
class Program
{
static void Main(string[] args)
{
var driver = new ChromeDriver(#"C:\Users\laurens.putseys\Documents\Visual Studio 2015\Projects\TestWebDriver\packages\Selenium.WebDriver.ChromeDriver.2.21.0.0\driver\");
driver.Url = "http://google.be";
Console.ReadLine();
driver.Quit();
}
}
}
The error I get is the following:
An unhandled exception of type 'System.InvalidOperationException' occurred in WebDriver.dll
Additional information: unknown error: chrome failed to start
(Driver info: chromedriver=2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4),platform=Windows NT 6.1 SP1 x86_64)
It started after I tried this:
System.Environment.SetEnvironmentVariable("webdriver.chrome.driver",#"/path/to/where/you/ve/put/chromedriver.exe"
Now I cannot launch the local either. Launching IE and Firefox local work without any problems. Any ideas? Thanks in advance!
try downloading the driver and give its path to contractor - LINK
driver = new ChromeDriver(DRIVER_PATH);
By the version number (2.21.371459) you can tell that the ChromeDriver executable has been launched by your remote Selenium server. But the ChromeDriver was obviously unable to launch the Chrome browser. Is it installed on the server? Can you launch is manually? Can you watch the remote server on a screen and see what happens? Are there any error message boxes displayed by Chrome?
Maybe uninstalling and re-installing Chrome could help!
I had the same problem. I had the browser set to always run under the administrator.
So I started Visual Studio as an administrator and the problem was solved.
The following code breaks in a .NET 3.5 class library project, but not in .net 4. I'm stumped and would appreciate any ideas:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using NUnit.Framework;
namespace test2
{
[TestFixture]
public class TestClass
{
[Test]
public void Test()
{
var request =
WebRequest.Create("http://www.google.com");
Specific Exception:
System.Security.SecurityException : Request for the permission of type 'System.Net.WebPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
at System.Security.CodeAccessSecurityEngine.Check(Object demand, ref StackCrawlMark stackMark, Boolean isPermSet)
at System.Security.CodeAccessPermission.Demand()
at System.Net.HttpWebRequest..ctor(Uri uri, ServicePoint servicePoint)
at System.Net.HttpRequestCreator.Create(Uri Uri)
at System.Net.WebRequest.Create(Uri requestUri, Boolean useUriBase)
at System.Net.WebRequest.Create(String requestUriString)
at test2.LaunchRequestInitializeIdsTestFixture.Test()
The answer, as the exception says, is Code Access Security (CAS). I am building my code from a network drive (hosted VM). In .NET 3.5 and below, the network drive has lower privileges. This restriction was turned off for .NET 3.5 SP1 and above. The following link put me on the right track:
http://blogs.msdn.com/b/vancem/archive/2008/08/13/net-framework-3-5-sp1-allows-managed-code-to-be-launched-from-a-network-share.aspx
The following, run from caspol in the .NET 2 install dir got my code working:
caspol.exe -m -pp off -ag 1 -url "file:///Z:/*" FullTrust
I got the above command line from this helpful post:
https://julianscorner.com/wiki/programming/caspol_network_share
FYI:
to restore to defaults, just run "caspol -restore"
Description Of Environment
I have an SSIS task which executes from asp.net, the package gets data from excel files over UNC path and puts the data into a sql server databaase . I have deployed the SSIS to file system, it has windows authentication database connections and the IIS user has database access. I can log in as the AppPoolUser I have used to host the web application and open/modify the files in question so those basic permissions are there. Web App is compiled in x86.
When it works:
When run from Visual Studio (ctrl + shift + W) it works fine and every thing is done succefuly.
When it doesn't work:
When run from client browser. it upload the file but fail in the package.
My Question
What is different about the client and server and how do I make it work? I was under the impression that when running the web app all connections go through the AppPool User so it should behave the same on any machine server included? i need to do so without the need of CMD.
c# Code running SSIS Package
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.SqlServer.Dts.Runtime;
public partial class Pages_Quality : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Upload_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
string fileExt =
System.IO.Path.GetExtension(FileUpload1.FileName);
if (FileUpload1.FileName == "Breached.xlsx")
{
try
{
FileUpload1.SaveAs("*:\\***\\***\\" +
FileUpload1.FileName);
Label1.Text = "Upload Done";
Application app = new Application();
Package package = app.LoadPackage(#"*:\**\**\Quality.dtsx", null);
DTSExecResult result = package.Execute();
Label2.Text = (result.ToString());
}
catch (Exception ex)
{
Label1.Text = "ERROR: " + ex.Message.ToString();
}
}
else
{
Label1.Text = "Only Breached.xls is allowed!";
}
}
else
{
Label1.Text = "You have not specified a file.";
}
}
}
Do you have SSIS service or SSIS Component (Client Tools) installed in the machine (web server in your case) where you are deploying and running your application from?
You may have bids in the same development PC where you have Visual Studio to develop and debug your application application. Usually the SSIS component is installed along with BIDs so you do not need SSIS service to run the package. This might be the case where your package execution is fine in you development PC. However it will never work in your web server because you do not have these components installed in your web server.
Hope this will help you.
Regards,
Sandip
If you are using Excel source connection, most probably the error happened because the excel driver work under 32 bit mode only, while when you try to call it from web, it's execute under 64 bit.
Check that.
Regards
I have a Windows service which I can install on my local machine using installutil no problem.
Now, this service has to be installed on a server. I copy all files to the server and run the same command, set the service to log on as a local user account and when the service starts I get an error saying "logon failed" - okay so perhaps the user account is the issue.
So I change the service log on as to local system account. I start the service and I am told "The service did not respond to the start or control request in a timely fashion".
So I googled and tried various solutions but to no avail. So I got to thinking maybe it was something in the OnStart method which broke (even though I have logging calls which never logged). So I removed all code from the OnStart event and still the service would not start, I got the "timely fashion" error.
So where am I at? I believe it could be due to the references I have defined in the project. To test this I created a new Windows service template from VS2012 with no references (other than the default ones) and I can start the service. No issues.
So my question is what could be causing this? In my project the references point to locations which do not exist on the server, however the directory where the service resides has all the referenced DLLs.
Edit:
Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;
namespace RetrieveAndProcessSecurityLogs
{
static class Program
{
static void Main()
{
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new LogService()
};
ServiceBase.Run(ServicesToRun);
}
}
}
LogService.cs
public partial class LogService : ServiceBase
{
public LogService()
{
InitializeComponent();
this.ServiceName = "Retrieve and Process Security Logs";
this.CanPauseAndContinue = true;
this.CanStop = true;
}
protected override void OnStart(string[] args)
{
//...
}
protected override void OnStop()
{
//...
}
Edit: The installed .NET version on the server is v4.0, however in the app config file for the project there is this line:
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
Could the 4.5 part be the issue?
Edit2: Bottom line: if I reference a DLL, I get the timely fashion error. If I have no extra DLL reference defined the service starts.
Sorry for the story.
Andrew
For future reference to anyone who encounters this issue, the issue was one of the references was built against .NET FW 4.5 and on the server where the service was being installed had .NET FW 4. My machine had 4.5.