I already done this using full javascript but how can i do this in C#/asp.net website (not winform). thanks..
-
Can't you use some of your JavaScript code in this ASP.NET page? It's html after all... – decyclone Dec 10 '10 at 13:22
-
I mean yes it can, but I just want it server side so that the code cant be viewed when you viewsource the html =) – CSharpNoob Dec 10 '10 at 13:24
-
There's a similar question in stack over flow already..chek it out--http://stackoverflow.com/questions/469798/konami-code-in-c – Andrew Collins Dec 10 '10 at 14:36
4 Answers
So you mean the user should not find out about your ultra secret konami code when viewing the source?
It's not possible to do it entirely server-side, unless you want a postback on every keystroke, which is awkward.
You could compress and obfuscate the javascript, but I guess a user with a strong determination still can figure it out.
You could use Silverlight, but again, a user with a strong determination can unpack the XAP from the browser cache and view your DLLs in reflector.
What you could do is sending every keystroke to the server using AJAX (or maybe collect them client-side and send them in a batch), which is actually not that painfully slow. On the server you'd have to analyse the keystrokes. This code will not be visible to the user. You'd then have to simulate some push mechanism to trigger your desired reaction on the client side.

- 11,101
- 2
- 41
- 51
It doesn't make sense to do it in C#. Such code would have to be executed on the client side anyway, so it has to be Javascript (unless you want to send each client keystroke to the server, which would be painfully slow)
Anyway, here's a C# implementation. It's for WPF, but it wouldn't be hard to adapt it to another technology.
private static readonly Key[] _konamiCode = new[] { Key.Up, Key.Up, Key.Down, Key.Down, Key.Left, Key.Right, Key.Left, Key.Right, Key.B, Key.A };
int _konamiCurrentIndex = 0;
protected override void OnPreviewKeyDown(KeyEventArgs e)
{
base.OnPreviewKeyDown(e);
if (e.Key == _konamiCode[_konamiCurrentIndex])
{
_konamiCurrentIndex++;
if (_konamiCurrentIndex == _konamiCode.Length)
{
_konamiCurrentIndex = 0;
KonamiEasterEgg();
}
}
else
{
_konamiCurrentIndex = 0;
}
}
void KonamiEasterEgg()
{
// whatever you want to do when the Konami code is entered...
}

- 286,951
- 70
- 623
- 758
-
1i wonder whats the equivalent of KeyEventArgs in system.web namespace ^^ – CSharpNoob Dec 10 '10 at 13:36
as others already said, it doesn't make much sense to implement it fully in C#. But i could imagine some kind of combination of both JavaScript + AJAX with C#... Just some ideas :)
Possible Workflow: Scan user Input (last 10 keys) with JavaScript and push the inputs into an array (ascii code or something) and send a request via AJAX which will return the whole secret target page as a html result instead of just checking, as this would be easy to crack. Actually, this would be more like a password comparison. But you could optimize your JavaScript and clear the array on few seconds without input (idle time) like 2 seconds (so that the input must be fluent) and send the ajax request after 1 second without input so that you don't flood your own server.
JQuery will help you a lot!
Happy coding : )
- best regards
Thomas

- 5,729
- 3
- 39
- 67
See herzmeister der welten
What you could do is sending every keystroke to the server using AJAX (or maybe collect them client-side and send them in a batch), which is actually not that painfully slow. On the server you'd have to analyse the keystrokes. This code will not be visible to the user. You'd then have to simulate some push mechanism to trigger your desired reaction on the client side.
The Trigger could be the last keystroke you need as part of the combination, the user would only then be able to decipher the last keystroke, and this would offer the fewest postbacks without some client side validation.
(Would have just made a comment but lack rep)

- 1,886
- 1
- 12
- 5