We have an application (C#) that up till today has worked fine.
It communicates with a laravel website to manage the sites data.
So there are some validation points that occur, the application does checks with out SSO provider for authentication. Then it passes some of the user's information over to the site so the site can create a user / send back user id for further entry points.
I have literally not touched this in months - and its been working without a problem.
Today I get a message its not working and so I start digging.
Can somebody explain THIS one?
C# Code For Validating User - Notice the response from the site.
The Laravel API Routes File on the route in question.
public function validation(Request $request) {
//Check if user exists if they do then just return. If they dont we need to create them in the system.
$user = User::where('email', $request['Email'])->first();
if($user == null) {
$nuser = new User();
$nuser->first_name = $request['FName'];
$nuser->last_name = $request['LName'];
$nuser->email = $request['Email'];
$nuser->token = $request['Token'];
switch($request['Role']) {
case 1:
$nuser->user_level = 1;
break;
case 2:
$nuser->user_level = 2;
break;
case 3:
$nuser->user_level = 3;
break;
case 4:
$nuser->user_level = 4;
break;
default:
$nuser->user_level = 4;
break;
}
try {
$nuser->save();
return json_encode($nuser);
}catch(\Exception $e) {
Log::error($e->getMessage());
}
}else{
switch($request['Role']) {
case 1:
$user->user_level = 1;
break;
case 2:
$user->user_level = 2;
break;
case 3:
$user->user_level = 3;
break;
case 4:
$user->user_level = 4;
break;
default:
$user->user_level = 4;
break;
}
try {
$user->save();
return json_encode($user);
}catch(\Exception $e) {
Log::error($e->getMessage());
}
}
}
So the end user of the C# application decided to overwrite the ini file with the website in it (for quick swaps between dev and production for the development team)....I noticed new entries in the development server's database from yesterday....end user then tries to put it back to the production server. But left off the s in https - and like any good website - it auto redirects to its https counterpart.
Cue RestClient trying to follow the redirect with a GET.
Updated the INI fixing the typo, tell user to close the application and reopen it to reload the INI data. Have our network team lock down the network folder containing the INI to read only unless its a member of the development team. And we're back rolling.
Related
Im working on the Vsto excel add-in and I'm getting the window rect through CreateWindowRect().
I'm running the application with ISO Office2016 Excel and Office365 excel.
The problem is I'm getting a different window rectangle while running the ISO office2016 excel and I have to get the correct window rect while running the application with office365excel.
So I'm planning to adjust the window rectangle while running application with ISO office2016 excel. To check the condition I'm in need to get whether the excel is standalone or office365 excel.
Is there any way to find whether Excel application is Click-to-Run (Online Office 365 installer) or Windows Installer (ISO file or DVD) using c#?
A computer can have multiples versions of Office.
But, you can discover if the machine has the Office 365 installed doing something like that:
using Microsoft.Win32;
...
private bool Has365Office()
{
RegistryView registryView = RegistryView.Registry32;
string registryKey = "Software\Microsoft\Office\16.0\Common\Licensing\LicensingNext";
using (RegistryKey key = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, registryView).OpenSubKey(registryKey))
{
foreach (string subkeyName in key.GetValueNames())
{
if (subkeyName.Contains("o365"))
return true;
}
}
return false;
}
...
To know what version is running, or at least will run when the user opens it, you can do something like that:
using Microsoft.Office.Interop;
...
public string GetOfficeVersion()
{
string sVersion = string.Empty;
Microsoft.Office.Interop.Word.Application appVersion = new Microsoft.Office.Interop.Word.Application();
appVersion.Visible = false;
switch (appVersion.Version.ToString())
{
case "7.0":
sVersion = "95";
break;
case "8.0":
sVersion = "97";
break;
case "9.0":
sVersion = "2000";
break;
case "10.0":
sVersion = "2002";
break;
case "11.0":
sVersion = "2003";
break;
case "12.0":
sVersion = "2007";
break;
case "14.0":
sVersion = "2010";
break;
case "16.0":
sVersion = "2016 or 2019 or 365";
break;
default:
sVersion = "Too Old!";
break;
}
return sVersion;
}
You can combine the code above to get what you need. I hope it helps!
both codes were made from this answer: link
I am uploading / creating file on Google Drive using .NET SDK for google drive api. Everything works fine and I can give permission to user as per my business logic like writer,reader,commenter or owner. But I want to hide the Share button from everybody except Owner as my business logic should decide which file should be shared with whom and when.
Here is the code for sharing the document:
try
{
Google.Apis.Drive.v2.Data.Permission permission = new Google.Apis.Drive.v2.Data.Permission();
switch (role)
{
case GoogleRoles.WRITER:
case GoogleRoles.READER:
case GoogleRoles.OWNER:
{
permission.Role = role;
permission.Value = userEmail;
permission.Type = "user";
break;
}
case GoogleRoles.COMMENTER:
{
permission.Role = GoogleRoles.READER; //Need to assign role before we assign the additional role of commenter.
List<String> additionalRoles = new List<string>();
additionalRoles.Add(GoogleRoles.COMMENTER);
permission.AdditionalRoles = additionalRoles;
permission.Type = "user";
permission.Value = userEmail;
break;
}
}
PermissionsResource.InsertRequest insertRequest = DriveService.Permissions.Insert(permission, fileId);
insertRequest.SendNotificationEmails = true;
insertRequest.Execute();
Where DriveService is an instance of service account. Any pointer would be a great help.
Unfortunately the Drive API doesn't yet support the feature of disabling sharing or disabling downloading. Please file a feature request here: https://code.google.com/a/google.com/p/apps-api-issues/issues/entry?template=Feature%20request&labels=Type-Enhancement,API-Drive
I had raised this as an enhancement, and got the response too. So in Google drive API its not part of permission but these are properties of file itself, so we need to set he properties instead of permissions like:
File.LabelsData labels = new File.LabelsData();
labels.Restricted = true;
File body = new File();
body.Labels = labels;
body.WritersCanShare = false;
It has solved the issue of Share but download issue is not solved it by above changes. More details about this can be found at https://developers.google.com/drive/v2/reference/files
I have one custom application which install or other system & I want to call that from this system using WMI C# without any batch file.
Moreover that application has command arguments to run. So, can anyone guide me what I suppose to code ?
I already tried few things which I am pasting here (code snippet) for your reference which works fine in case of Notepad.exe or Calc.exe to run.
In fact, It also works for me in my custom application without arguments but not with arguments. When I passed with arguments it start & kill after 2 seconds. Which means it doesn't pass arguments in well/ proper format.
private static uint CreateProcess(ManagementScope connectionScope, string exeWithPathAndArguments)
{
try
{
var objectGetOptions = new ObjectGetOptions();
ManagementPath processPath = new ManagementPath("Win32_Process");
using (var processTask = new ManagementClass(connectionScope, processPath, objectGetOptions))
{
using (var methodInParams = processTask.GetMethodParameters("Create"))
{
methodInParams["CommandLine"] = exeWithPathAndArguments;
using (var methodOutParams = processTask.InvokeMethod("Create", methodInParams, null))
{
var err = (uint)methodOutParams["returnValue"];
if (err != 0)
{
var info = "see http://msdn.microsoft.com/en-us/library/windows/desktop/aa389388(v=vs.85).aspx";
switch (err)
{
case 2: info = "Access Denied"; break;
case 3: info = "Insufficient Privilege"; break;
case 8: info = "Unknown failure"; break;
case 9: info = "Path Not Found"; break;
case 21: info = "Invalid Parameter"; break;
default: info = "Unknown(Code)"; break;
}
var msg = "Failed to Start the Process, error = " + methodOutParams["returnValue"] + " (" + info + ")";
throw new Exception(msg);
}
return (uint)methodOutParams["processId"];
}
}
}
}
catch (Exception ex)
{
throw ex;
}
}
I already aware with PSExec but I don't want to use that. Same time I don't want to use Batch File to run my command. Just want to use direct command passing way to run the application.
My Application location is not in PATH Directory. so, obviously I need to supply a full path like...
CreateProcess(connectionScope, exeWithPathAndArguments.Trim());
where exeWithPathAndArguments would be "/"C:\Program files (x86)\Company\Application Folder\app.exe/" -argsName argvalue"
Add methodInParams["CurrentDirectory"] = wheretostartapp; and delete -argsName
So your exeWithPathAndArguments will be:
\"C:\\\\Program files (x86)\\\\Company\\\\Application Folder\\\\app.exe\" argvalue
I had a Winforms App with a propertyGrid to let the user edit his settings.
How to achieve the same goal whithin a Console Application?
ANSWER
Thanks to those who answered.
Here is a synthetic code based on a few answers :
Console.WriteLine("Choose user settings to setup");
Console.WriteLine("User setting1: press 1");
Console.WriteLine("User setting2: press 2");
string line = Console.ReadLine();
int code = int.Parse(line);
swicth(code)
{
case 1:
Settings.Default.MyProperty = line ;
Settings.Default.Save();
break;
case 2:
...
}
Settings.Default.MyProperty1 = "some value";
Settings.Default.MyProperty2 = 2;
Settings.Default.Save();
You should prompt the user about user settings. Something like this:
Console.WriteLine("Choose user settings to setup");
Console.WriteLine("User setting1: press 1");
Console.WriteLine("User setting2: press 2");
....
...
string line = Console.ReadLine();
int code = int.Parse(line);
swicth(code)
{
case 1:
....
.....
case 2:
}
After save changes in XML file.
If it's not you're asking for, please clarify.
Console applications does not have an User Interface, by definition (though you can force display of Windows Forms). You need to rethink your solution. Maybe you want to use app.config (XYZ.exe.config) or a separate configuration file. BTW, you can edit application settings file from code.
How can I check the status of an IIS6 application pool with C# ?
For example, I want to know if it is running or not !
Thank's in advance for your help !
http://msdn.microsoft.com/en-us/library/ms524962.aspx
You can do this checking the AppPoolState Property:
protected void status()
{
string appPoolName = "dev.somesite.com";
string appPoolPath = #"IIS://" + System.Environment.MachineName + "/W3SVC/AppPools/" + appPoolName;
int intStatus = 0;
try
{
DirectoryEntry w3svc = new DirectoryEntry(appPoolPath);
intStatus = (int)w3svc.InvokeGet("AppPoolState");
switch (intStatus)
{
case 2:
lblStatus.Text = "Running";
break;
case 4:
lblStatus.Text = "Stopped";
break;
default:
lblStatus.Text = "Unknown";
break;
}
}
I think you need the services of WMI (
Windows Management Instrumentation)
There are several articles around on how to manage IIS using WMI via vbscript, e.g.
http://learn.iis.net/page.aspx/163/managing-applications-and-application-pools-on-iis-70-with-wmi/
If you take one of those articles you should be able to adapt it to C# easily enough.