I am trying to delete all cookies from the responder,
the function is inside a service project.
code:
int limit = HttpContext.Current.Request.Cookies.Count;
for (int i = 0; i < limit; i++)
{
cookieName = HttpContext.Current.Request.Cookies[i].Name;
aCookie = new HttpCookie(cookieName);
aCookie.Value = null;
aCookie.Expires = DateTime.Now.AddYears(-1);
HttpContext.Current.Response.Cookies.Add(aCookie)
}
but the response only adds more cookies with the same name. How do I fix this?
Try this:
string[] myCookies = Request.Cookies.AllKeys;
foreach (string cookie in myCookies)
{
Response.Cookies[cookie].Expires = DateTime.Now.AddDays(-1);
}
Edit: this suggestion is based on the guestimate that it has to do with you adding the cookie to the response instead of updating the one that's already present.
after a lot of head banging I finaly noticed that while creating the cookie as followed it did the trick
cookie = new HttpCookie(CookieName, CustId);
declaring the cookie in any other manner didn't work,
for example :
int limit = HttpContext.Current.Request.Cookies.Count;
for (int i = 0; i < limit; i++)
{
cookieName = HttpContext.Current.Request.Cookies[i].Name;
aCookie = new HttpCookie(cookieName);
aCookie.Value = null;
aCookie.Expires = DateTime.Now.AddYears(-1);
HttpContext.Current.Response.Cookies.Add(aCookie);
}
or
var cookie = HttpContext.Current.Response.Cookies[CookieName];
if(cookie == null)
{
cookie = new HttpCookie(CookieName, CustId);
}
else
{
cookie.Expires = DateTime.Now.AddDays(-100);
HttpContext.Current.Response.Cookies.Add(cookie);
//HttpContext.Current.Session.Clear();
}
Related
I created a Asmx Web service and host it in IIS, in MVC, I could call it from below code:
BasicWebService.WebService1 client = new BasicWebService.WebService1();
client.Credentials = new System.Net.NetworkCredential("user", "pwd","domain");
string result = client.HelloWorld();
But, I failed to mark it work under Asp.net Core.
Here is the code what I have tried.
ServiceReference1.WebService1SoapClient client = new ServiceReference1.WebService1SoapClient(ServiceReference1.WebService1SoapClient.EndpointConfiguration.WebService1Soap);
client.ClientCredentials.UserName.UserName = "xx";
client.ClientCredentials.UserName.Password = "xx";
//string USER = "xx";
//string PASSWORD = "xx";
//string Domain = "xx";
//NetworkCredential netCredential = new NetworkCredential(USER, PASSWORD,Domain);
////client.Credentials = new System.Net.NetworkCredential("xx", "xx", "xx");
//client.ClientCredentials.Windows.ClientCredential = netCredential;// netCredential.GetCredential(new Uri("http://localhost/WCFBasicSecurity/WebService1.asmx"), "Basic");
ServiceReference1.HelloWorldResponse result =client.HelloWorldAsync().Result;
Got solution from GitHub, thanks for the suggestion from hongdai. Modify the generated reference.cs with below:
public WebService1SoapClient(EndpointConfiguration endpointConfiguration) :
base(WebService1SoapClient.GetBindingForEndpoint(endpointConfiguration), WebService1SoapClient.GetEndpointAddress(endpointConfiguration))
{
this.Endpoint.Name = endpointConfiguration.ToString();
this.ChannelFactory.Credentials.UserName.UserName = "xx\xx";
this.ChannelFactory.Credentials.UserName.Password = "xxxx";
ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
}
private static System.ServiceModel.Channels.Binding GetBindingForEndpoint(EndpointConfiguration endpointConfiguration)
{
if ((endpointConfiguration == EndpointConfiguration.WebService1Soap))
{
//Transport Security
System.ServiceModel.BasicHttpBinding result = new System.ServiceModel.BasicHttpBinding(System.ServiceModel.BasicHttpSecurityMode.Transport);
result.Security.Transport.ClientCredentialType = System.ServiceModel.HttpClientCredentialType.Basic;
result.MaxBufferSize = int.MaxValue;
result.ReaderQuotas = System.Xml.XmlDictionaryReaderQuotas.Max;
result.MaxReceivedMessageSize = int.MaxValue;
result.AllowCookies = true;
return result;
}
if ((endpointConfiguration == EndpointConfiguration.WebService1Soap12))
{
System.ServiceModel.Channels.CustomBinding result = new System.ServiceModel.Channels.CustomBinding();
System.ServiceModel.Channels.TextMessageEncodingBindingElement textBindingElement = new System.ServiceModel.Channels.TextMessageEncodingBindingElement();
textBindingElement.MessageVersion = System.ServiceModel.Channels.MessageVersion.CreateVersion(System.ServiceModel.EnvelopeVersion.Soap12, System.ServiceModel.Channels.AddressingVersion.None);
result.Elements.Add(textBindingElement);
System.ServiceModel.Channels.HttpTransportBindingElement httpBindingElement = new System.ServiceModel.Channels.HttpTransportBindingElement();
httpBindingElement.AllowCookies = true;
httpBindingElement.MaxBufferSize = int.MaxValue;
httpBindingElement.MaxReceivedMessageSize = int.MaxValue;
result.Elements.Add(httpBindingElement);
return result;
}
throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration));
}
private static System.ServiceModel.EndpointAddress GetEndpointAddress(EndpointConfiguration endpointConfiguration)
{
if ((endpointConfiguration == EndpointConfiguration.WebService1Soap))
{
return new System.ServiceModel.EndpointAddress("https://localhost/WCFBasicSecurity/WebService1.asmx");
//return new System.ServiceModel.EndpointAddress("http://localhost/WCFBasicSecurity/WebService1.asmx");
}
if ((endpointConfiguration == EndpointConfiguration.WebService1Soap12))
{
return new System.ServiceModel.EndpointAddress("http://localhost/WCFBasicSecurity/WebService1.asmx");
}
throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration));
}
Reference:https://github.com/dotnet/wcf/issues/1812
I have the following code:
if (adSetting.Core_standard_application_role)
{
rc = new IntegrationRoleCompany();
rc.RoleCompany = firmSettings.FirmNo.ToString();
rc.RoleName = "Core standard application role";
rcList.Add(rc);
}
if (adSetting.Expense_Invoice_Application_Access)
{
rc = new IntegrationRoleCompany();
rc.RoleCompany = firmSettings.FirmNo.ToString();
rc.RoleName = "Expense Invoice Application Access";
rcList.Add(rc);
}
The problem is that I have 20 if-checks where I check addSetting.Property. Now to the question:
What is the best and most effective way to refactor this if-statements?
you could have a 20x2 array with the adSetting.STUFF_AS_STRING -> rc.RoleName mapping.
then loop over the array in a for loop
pseudo code:
for (var i=0; i<theArray.length; i++) {
adSettingStr, RoleName = theArray[i]
if (adSetting[adSettingStr]) {
rc = new IntegrationRoleCompany();
rc.RoleCompany = firmSettings.FirmNo.ToString();
rc.RoleName = RoleName;
rcList.Add(rc);
}
}
Any idea why the below code would return an error(Failure) for its status?
private SearchResult getTxns()
{
TransactionSearchAdvanced tsa = new TransactionSearchAdvanced();
tsa.columns = new TransactionSearchRow();
tsa.columns.basic = new TransactionSearchRowBasic();
tsa.columns.basic.tranId = new SearchColumnStringField[] { new SearchColumnStringField() };
tsa.criteria = new TransactionSearch();
tsa.criteria.basic = new TransactionSearchBasic();
tsa.criteria.basic.mainLine = new SearchBooleanField();
tsa.criteria.basic.mainLine.searchValue = true;
tsa.criteria.basic.mainLine.searchValueSpecified = true;
tsa.criteria.basic.type = new SearchEnumMultiSelectField();
tsa.criteria.basic.type.#operator = SearchEnumMultiSelectFieldOperator.anyOf;
tsa.criteria.basic.type.operatorSpecified = true;
tsa.criteria.basic.type.searchValue = new string[] { "_salesOrder" };
tsa.criteria.basic.otherRefNum = new SearchTextNumberField();
tsa.criteria.basic.otherRefNum.#operator = SearchTextNumberFieldOperator.equalTo;
tsa.criteria.basic.type.operatorSpecified = true;
tsa.criteria.basic.type.searchValue = new string[] { "BBnB 1001" };
SearchResult sr = _service.search(tsa);
return sr;
}
The following is the error that is returned in the results.
Status Code: INVALID_SEARCH_OPERATOR
Status Message: You need to provide a valid search field operator.
However, this operator appears in the NetSuite UI itself when I do a search. Also, I find it in the NetSuite documentation here.
I am using v2013_1_0 for the webservices version of the wsdl.
SOLUTION
Solution found to be in the last block of code. Was attempting to set otherRefNum and was referencing Type. Here is the corrected code.
private SearchResult getTxns()
{
TransactionSearchAdvanced tsa = new TransactionSearchAdvanced();
tsa.columns = new TransactionSearchRow();
tsa.columns.basic = new TransactionSearchRowBasic();
tsa.columns.basic.tranId = new SearchColumnStringField[] { new SearchColumnStringField() };
tsa.criteria = new TransactionSearch();
tsa.criteria.basic = new TransactionSearchBasic();
tsa.criteria.basic.mainLine = new SearchBooleanField();
tsa.criteria.basic.mainLine.searchValue = true;
tsa.criteria.basic.mainLine.searchValueSpecified = true;
tsa.criteria.basic.type = new SearchEnumMultiSelectField();
tsa.criteria.basic.type.#operator = SearchEnumMultiSelectFieldOperator.anyOf;
tsa.criteria.basic.type.operatorSpecified = true;
tsa.criteria.basic.type.searchValue = new string[] { "_salesOrder" };
tsa.criteria.basic.otherRefNum = new SearchTextNumberField();
tsa.criteria.basic.otherRefNum.#operator = SearchTextNumberFieldOperator.equalTo;
tsa.criteria.basic.otherRefNum.operatorSpecified = true;
tsa.criteria.basic.otherRefNum.searchValue = "BBnB 1001";
SearchResult sr = _service.search(tsa);
return sr;
}
The problem is with your SearchEnumMultiSelectField operator. equalto is not a valid operator for this filter; you will need to use anyOf instead.
-- EDIT - Adapated from original comment --
A SearchTextNumberField does not accept an array of Strings. Instead try tsa.criteria.basic.otherRefNum.searchValue = "BBnB 1001";
I have a drop down list that gets its data from a php web service method.This response is smthing like :
array('id'=>integer,'name'=>'lin')
When the page loads, I want to set the selected index to "lin" initially. How do I do this ?
you just need to set selectedIndex property of dropdownlist control.
ex.
dwl.selectedIndex = 1; // "Index of "lin"
you should do this.
var iIndex:int;
for(var i:int = 0; i < arrResponse.length; i++)
{
// if(Array(arrResponse[i])[1] == "lin")
if(Array(arrResponse[i]).name == "lin") {
iIndex = i;
}
}
dwl.selectedIndex = iIndex;
I would like to know how to retrieve the list of users that are logged onto a Remote machine. I can do it with qwinsta /server:xxxx, but would like to do it in C#.
check out wmi in .net under system.management.
something like:
ConnectionOptions conn = new ConnectionOptions();
conn.Authority = "ntdlmdomain:NAMEOFDOMAIN";
conn.Username = "";
conn.Password = "";
ManagementScope ms = new ManagementScope(#"\\remotecomputer\root\cimv2", conn);
ms.Connect();
ObjectQuery qry = new ObjectQuery("select * from Win32_ComputerSystem");
ManagementObjectSearcher search = new ManagementObjectSearcher(ms, qry);
ManagementObjectCollection return = search.Get();
foreach (ManagementObject rec in return)
{
Console.WriteLine("Logged in user: " + rec["UserName"].ToString());
}
You may not need the ConnectionOptions...
I ended up using the qwinsta /server:server1 command from C# -- it was much easier
thanks Ken
All this checks all 8 servers at the same time -- I put the result in sql server
but you can do what ever you want
query_citrix.bat script
cd C:.......\bin\citrix_boxes
qwinsta -server:servername or ip > servername.txt
string sAppCitrixPath = Application.StartupPath.ToString() + "\\citrix_boxes\\";
//Run Script for current citrix boxes
Process proc = new Process();
ProcessStartInfo si = new ProcessStartInfo();
si.FileName = sAppCitrixPath + "query_citrix.bat";
proc.StartInfo = si;
proc.Start();
proc.WaitForExit();
int exitCode = proc.ExitCode;
proc.Close();
if (exitCode == 0)
{
//Execute update who is on the Citrix_Boxes Currently
DirectoryInfo dic = new DirectoryInfo(sAppCitrixPath);
FileInfo[] fic = dic.GetFiles("*.txt");
for (int i = 0; i < fic.Length; i++)
{
ParseQWinStaServerFile(fic[i].FullName.ToString(), fic[i].Name.ToString().ToUpper().Replace(".TXT",""));
File.Delete(fic[i].FullName.ToString());
}
}
private void ParseQWinStaServerFile(string sLocation,string sServer)
{
using (StreamReader sr = File.OpenText(sLocation))
{
string sRecord = String.Empty;
char[] cSep = new char[] {' '};
bool bFirst = true;
while ((sRecord = sr.ReadLine()) != null)
{
if (bFirst == false)
{
string[] items = sRecord.Split(cSep, StringSplitOptions.RemoveEmptyEntries);
//Make sure all columns are present on the split for valid records
if (sRecord.Substring(19, 1) != " ") // check position of user id to see if it's their
{
//Send the user id and server name where you want to.
//here is your user
id = items[1].ToString().ToLower().Trim()
//here is your server
};
}
else
{
bFirst = false;
}
}
}
}