How to poll anonymously? [closed] - c#

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 9 years ago.
Improve this question
I'm looking for an idea to develop a little poll system that voters be able to vote anonymously. No registration, no e-mail ..., Of course, everyone must vote only ONE time.
I do not want to use cookies, because I think it's possible that a few users vote from one machine, or one user votes with several browsers on a machine. Also I think working with IP addresses is not a good idea too, because it is possible users use proxy. So, do you have any idea for this?
(I use ASP.NET 4 with C# & SQL Server 2008)
Thanks.

There is absolutely no way to guarantee that each person will only vote once, without registration. Even if you get the IP, you will fail to prevent this person from voting a second time from another location and you will prevent multiple persons from voting using the same connection.

Without registration your best bet is to use IP adress to identify votes. Store polls in a database and refuse to update if the voter is trying to vote more than once.
A way to get IP address:
public static string getIPAddress(HttpRequestBase request)
{
string szRemoteAddr = request.UserHostAddress;
string szXForwardedFor = request.ServerVariables["X_FORWARDED_FOR"];
string szIP = "";
if (szXForwardedFor == null)
{
szIP = szRemoteAddr;
}
else
{
szIP = szXForwardedFor;
if (szIP.IndexOf(",") > 0)
{
string [] arIPs = szIP.Split(',');
foreach (string item in arIPs)
{
if (!isPrivateIP(item))
{
return item;
}
}
}
}
return szIP;
}

Related

How do I store the result as cache in C# [closed]

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 last year.
Improve this question
So I have below code running, where I am calling an Api, which gives me result a Json Array which I am later querying in my code. The response, I get from the api is mostly constant and since it has SOME data, it takes few seconds to get the complete result. I would like to know, if I can store the result coming from api in some way in cache in order to make the whole processing part faster?
EDIT: below code is inside a Foreach loop
foreach (var did in myDeserializedClass)
{
if (did.id == matchedid)
{
url = "https://.../api/information/test";
var response = await Request(Stream.Null, url, "GET");
string message = await response.Content.ReadAsStringAsync();
var allcodes = JsonConvert.DeserializeObject<List<CoCode>>(message);
foreach(var cc in allcodes )
{....// rest of my code
You can absolutely use a memory cache, even Microsoft provide one which if possible also can be place in the api side for quicker lookups
https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.caching.memory.memorycache?view=dotnet-plat-ext-6.0

How do I use libphonenumber to find phone numbers? [closed]

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 3 years ago.
Improve this question
I am trying to use the libphonenumber-csharp library and the FindNumbers feature. But I am unable to implement it properly. What am I doing wrong?
PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
var a = phoneUtil.findNumbers("this is my phone number: (805) 527-9975", null);
Console.WriteLine(a);
Console.Write(phoneUtil.findNumbers("8055279975", "US"));
public Iterable<PhoneNumberMatch> findNumbers(CharSequence text, String defaultRegion);
I tried the code and I am getting this as the output:
java.lang.Iterable1[com.google.i18n.phonenumbers.PhoneNumberMatch]
java.lang.Iterable1[com.google.i18n.phonenumbers.PhoneNumberMatch]
Are you getting the same result? looking into the issue now and I'll let you know if I figure it out.
EDIT
I was able to figure it out!
The correct way to do it is like this:
string testString = "testing the ability to grab here: 345-365-567";
{
PhoneNumberUtil phoneUtil = PhoneNumberUtil.GetInstance();
PhoneNumber phoneNumber = phoneUtil.Parse(testString, "US");
//now from here you can do ahead and retrieve the number by calling upon phoneNumber.
Console.WriteLine(phoneNumber.NationalNumber);
}

Requesting code recommendations for building a multi-layered, conversation bot [closed]

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 3 years ago.
Improve this question
My company wants an Azure bot to respond to a series of “yes” and “no” answers along a conversational path with three layers. I'm using Visual Studio Community 2019 to edit code and Bot Framework Emulator (V4) to test the bot.
Here's a link to an image of the questions and answers and how the conversational flow should look:
https://cdn1.imggmi.com/uploads/2019/5/21/738797c22a7756a01fdf6786f26eb39b-full.png.
I'm not sure know how to link multiple layers of dialogue together. I've only been able to construct a bot with one layer of dialogue as shown at the URL below:
https://cdn1.imggmi.com/uploads/2019/5/21/99019e8e881d62f56ce449397ca9f191-full.png
I tried using the "SuggestedActionsBot" template, but it seems to need a major rework to make our deliverable possible.
https://github.com/microsoft/BotBuilder-Samples/tree/master/samples/csharp_dotnetcore/08.suggested-actions
Just for reference, here's an example of how the code for the first layer of dialogue looks:
private static string ProcessInput(string text)
{
const string FirstSequenceResponseYes = "Sure, can you explain the issue? " +
"Do you see error message such as 'Power BI Access Tokens Not Allocated?'";
const string FirstSequenceResponseNo = "Thanks, user. " +
"It's good to interact with you. Have a great day!";
switch (text)
{
case "yes":
{
return $"{FirstSequenceResponseYes}";
}
case "no":
{
return $"{FirstSequenceResponseNo}";
}
default:
{
return "Please select one of the suggested action choices.";
}
}
}
What is the best way to go about writing the code to make this deliverable possible? Are there URLs and resources someone could provide that are directly pertinent to what we're trying to achieve?
I'm not sure I understood your question exactly, as the comment say.
But for navigating layers in the bot, I would encourage you to read this documentation.
With the bot-community solution, you can create a complex dialog with several levels.
Finally, in order to create a dialog that receives only yes and no answers, I would suggest using ConfirmPrompt.

Choosing users for A/B testing [closed]

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 7 years ago.
Improve this question
I have a table with userid's (int increment) about 4M records.
I would like to show a new feature to only 25% of the users.
What would be the best way to choose those 25% users?
you could use some sort of Fisher Yates shuffle algorithm to randomly choose the 'first' 25% of user ids.
ie, pick a random number between 1 and 4M. that's your first user, add it to a collection somewhere. repeat until you have 1M (25%) users in your collection.
Once you have all the users, mark them somehow in your table.
Another idea is that you could set a browser cookie which was 'myAwesomeFeature=A' or 'myAwesomeFeature=B'. If the cookie isn't set yet, set it to 'B' if a random number between 0-100 is 25 or less. 'A' otherwise. If the cookie is already set, just use it.
Has the added benefit of being easily testable since you can easily force yourself to be in whichever group you want. And it'll work for multiple features since you just need to change the cookie name. And the same user will get the same group as long as the cookie doesn't expire.
How about this?
if (user.Id <= (maxId * 0.25))
{
// Show a new feature
}

What's the best way to store variables in code behind? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
i'm using asp.net and c#.
I have some variable like CurrentCulture, SignedinUserEmail, MenuItemID for for each page that are used in different method and events, which way is the best for holding their values?
private string _CurrentCulture;
private string CurrentCulture
{
get
{
return _CurrentCulture;
}
set
{
_CurrentCulture = value;
}
}
or
private string CurrentCulture
{
get
{
if (ViewState["CurrentCulture"] == null)
{
return "en-UK";
}
else
{
return ((string)ViewState["CurrentCulture"]);
}
}
set
{
ViewState["CurrentCulture"] = value;
}
}
their values might assign by query string or another local variable.
We can best use each one as:
Save it to viewstate if you need to have it after the post back. If you do not make post back there is no reason to save it there.
Save it to a variable if you like to get it from the page it self, or to send it to other custom controls on the page.
Save it to the session if you like to use it on other pages - for example if some user select a language that prefer, then save that selection on session and use it on the next pages.
Use the url parameters if you won the user to be able to save the url, and together keep that parameters.
The CurrentCulture, SignedinUserEmail is better to saved on session because you want to use it on every call, on every page view, with and with out post back.

Categories

Resources