Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
i want to connect my site(mvc5) to payeer payment proccessor .i read payeers document but all script of document is in php .please help me to convert this script to c#.
<?php if (!in_array($_SER VER['REMOTE_AD DR'], array('185.71.65.92', '185.71.65.189','149.202.17.210'))) return; if isset($_POST['m_operation_id']) && isset($_POST['m_sign'])){ $m_key = 'Your secret key';$arHash = array($_POST['m_operation_id'],$_POST['m_operation_ps'],$_POST['m_operation_date'],$_POST['m_operation_pay_date'],$_POST['m_shop'],$_POST['m_orderid'],$_POST['m_amount'],$_POST['m_curr'],$_POST['m_desc'],$_POST['m_status']);if isset($_POST['m_params'])){$arHash[] = $_POST['m_params'];}$arHash[] = $m_key;$sign_hash = strtoupper(hash('sha256', implode(':', $arHash)));if $_POST['m_sign'] == $sign_hash && $_POST['m_status'] == 'success'){exit($_POST['m_orderid'].'|success');}exit($_POST['m_orderid'].'|error');}?>
if (!in_array($_SERVER['REMOTE_AD DR'], array('185.71.65.92', '185.71.65.189','149.202.17.210'))) return;
in this line code checks if the client address is in white list, if it is not in white list so block request, you can do this in c# using this code:
string[] whiteListIps = new string[]{'185.71.65.92', '185.71.65.189','149.202.17.210'};
var clientIp = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if(!whiteListIps.Contains(clientIp))
return Redirect("/UnAuthorized");
in the next line you should check if m_operation_id and m_sign exists in Request.Body
the below is in php:
if isset($_POST['m_operation_id']) && isset($_POST['m_sign']))
in c#:
if(Request.Form["m_operation_id"] != null && Request.Form("m_sign") != null)
$m_key and $arHash just are variables that declared based on posted values and a key that will used in SHA256 algorithm to decode message to ensure if received message hash is equal with parameters value
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
The community is reviewing whether to reopen this question as of 2 years ago.
Improve this question
I have a below code to capture an objects values:
var key = fulfillment.GetType().GetProperties().FirstOrDefault(p => p.Name.ToLower().Contains("operator")).GetValue(fulfillment);
the code return:
the Operator property type is:
[JsonProperty(PropertyName = "operator")]
public object Operator { get; set; }
i want to get the name value of the index 1 -> OMS_OPERATOR_AUTOMATED and assign it to another string variable. How can i do this ?
Final answer after looking at code and data structure the answer was:
var foundOperator = (Dictionary<string, object>) fulfillment.Operator;
var teste = foundOperator["name"];
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
Console.WriteLine("Unlike my deceased predecessor, A.I./Ai, I do not mind not being human. I am content with what I have.");
Console.ReadKey();
bool AI = false;
if (AI = true)
I want the user to type "AI" and have it set the bool to true if they do.
After reading all the comments I think this is what you mean
Console.WriteLine("Unlike my deceased predecessor, A.I./Ai, I do not mind not being human. I am content with what I have.");
string answer = Console.ReadLine();
bool AI = (answer == "AI");
You want to use Console.ReadLine, not Console.ReadKey. You also should make the check case insensitive in case the user enters Ai or ai.
Console.WriteLine("Unlike my deceased predecessor, A.I./Ai, I do not mind not being human. I am content with what I have.");
string lineRead = Console.ReadLine();
bool AI = "ai".Equals(lineRead, StringComparison.OrdinalIgnoreCase);
if(AI)
{
// ai was selected
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
This code throws an exception if the key does not exist.
For example, if the key exists for a position in an array index the code is okay, even if the value is null. But, if the key does not exist the code throws an exception`. The code in the select token parenthesis is dynamic (a string variable).
r["Value"] = json.SelectToken($.Objectives[x].state).ToString() ?? "";
You can't call ToString() on a null value.
JToken value = json.SelectToken("$.Objectives[x].state");
r["Value"] = (value != null) ? value.ToString() : "";
You could use the tenary operator to return a default value if x doesn't exist
r["Value"] = $.Objectives[x] ?
json.SelectToken($.Objectives[x].state).ToString() ?? "
: '';
OR
r["Value"] = x >= $.Objectives.Length ?
json.SelectToken($.Objectives[x].state).ToString() ?? "
: '';
I'm not sure why you end the line with a double quote. Maybe a typo? But I didn't fix it, that code is what you started with.
In javascript, if a given variable has a value, it will return true to the following:
if(r["Value"]){
//this only runs if r["Value"] exists
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I wanted to minimize if block from below code.Please help me suitable extension method
var v = (from rec in _DataContext.tblCourierMasters
where rec.CourierReceievedDate == dtCourierReceivedDate
&& rec.RegionId == lRegionId
&& rec.PODNumber == strPODNo
select new { rec.TotalCafReceived, rec.ReceiptDoneCount }).FirstOrDefault();
lTPC = (long)v.TotalCafReceived;
if (v.ReceiptDoneCount== null) {
lRDC = -1;
}
else
lRDC = (long)v.ReceiptDoneCount;
You could use the null-coalescing operator:
lDRC = (long)(v.ReceiptDoneCount ?? -1);
So if v.ReceiptDoneCount is null, lDRC will be assigned the value of -1 instead.
Here's a demo.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have Json file in string (for example):
#{
"Url": "http://site.com/?q=windows8"
}
How can i take the information after ?q= on c# (windows 8). Sorry for my English.
You can use the querystring.
in Codebehind file
public String q
{
get
{
if (Request.QueryString["q"] == null)
return String.Empty;
return Convert.ToString(Request.QueryString["q"]);
}
}
then use the line below to get the value
var index = ('<%=q%>');
You can do simply this :
string s = "myURL/?q=windows8";
// Loop through all instances of ?q=
int i = 0;
while ((i = s.IndexOf("?q=", i)) != -1)
{
// Print out the substring. Here : windows8
Console.WriteLine(s.Substring(i));
// Increment the index.
i++;
}