Posts

Showing posts from December, 2010

C# | Get My REAL External Public IP Address (not 127 or 192 stuff)

Yes, there is a way. No 127.0.0.1 or 192.168.0.1 stuff. Contact whatsmyip.com and they'll tell you! public static IPAddress GetExternalIp() { string whatIsMyIp = "http://automation.whatismyip.com/n09230945.asp"; WebClient wc = new WebClient(); UTF8Encoding utf8 = new UTF8Encoding(); string requestHtml = ""; try { requestHtml = utf8.GetString(wc.DownloadData(whatIsMyIp)); } catch (WebException we) { // do something with exception Console.Write(we.ToString()); } IPAddress externalIp = IPAddress.Parse(requestHtml); return externalIp; } Thanks to this guys at dreamincode.net http://www.dreamincode.net/forums/topic/24692-showing-the-external-ip-address-in-c%23/ Update: The function appears to return the server IP address. How to get both CLIENT and SERVER public IP Addresses? string serverIP = GetExternalIp().ToStr...

JavaScript | Static Current Date Format

<script type="text/javascript"> var today = new Date(); var d = today.getDate(); var m = today.getMonth(); var y = today.getFullYear(); var months = new Array("January", "February", "March", "April", "May", "June", "Jully", "August", "September", "October", "November", "December"); datestr = months[m] + " " + d + ", " + y; document.write(datestr); </script> This displays always "Month Day, Year", regardless of user browser language, or system regional settings. The code can be added in-line, where it is needed within the html.

PowerShell | Change Application Pool State

$appPool = get-wmiobject -namespace "root\MicrosoftIISv2" -class "IIsApplicationPool" | where-object {$_.Name -eq "W3SVC/AppPools/MY_APP_POOL"} $appPool.Stop()

DNN | Non-dynamic control ID names

We can avoid those "Placeholder_MYID" ID generation in DNN. <asp:Content ID="MainContent" runat="server" ContentPlaceHolderID="MainContent" ClientIDMode="Static"> http://www.highoncoding.com/Articles/703_Understanding_ClientIDMode_Mode_Feature_in_ASP_net_4_0.aspx

Outlook 2007 | Too slow changing between folders

After a MS update, Outlook starting acting crazy. Common effects are non-responsive behavior and slow loading between folders. Solution: Remove Hotmail add-in! Tools Trust Center Add-ins "Go" "COM Addin for Microsoft Outlook Hotmail Connector" http://labnol.blogspot.com/2007/03/microsoft-outlook-2007-running-slow-fix.html

MYSQL starters for dummies

reset password c:\Program Files\MySQL\MySQL Server 5.1\bin\mysqld.exe --init-file=C:\\mysql-init --console file here Source: MySQL.com http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html MySQL commands: show databases; create database [db_name]; drop database [db_name]; Problem: Unable to connect to the database:Could not connect to MySQL Fix: Change hostname to from "localhost" to "127.0.0.1"

Orchard first steps

Machine Key Error ViewState MAC add to web config's system.web <machineKey validationKey="84EF7A1ABD0B0AE06E348C0700126710730D72A52041CDF03C9143BB30C0F9E3D5D497418281F5433A219A2BF9C3C7D63464DDF54D2064DE6FD8EB06606DB5FB" decryptionKey="9271D3B59272D556F028B7B7C3761751733DCB2C2BD71E88479761A4B9089665" validation="SHA1" decryption="AES" /> restart iis and browser! for code generation: start cmd.exe \orchard\bin\orchard.exe feature enable Orchard.CodeGeneration codegen theme MyTheme /BasedOn:TheThemeMachine http://www.orchardproject.net/docs/Default.aspx?Page=Customizing-the-default-theme&NS=&AspxAutoDetectCookieSupport=1 online machine key generator http://aspnetresources.com/tools/machineKey orchard activate search on 0.8 http://www.orchardproject.net/docs/Search-and-indexing.ashx update: orchard starting 0.9.253 search activation process: - In Gallery, Modules, install: Indexing, Search and Lucene - Then go to Configuration, Feat...

Run Process from ASPNET and capture output

ProcessStartInfo myProcessInfo = new ProcessStartInfo(); myProcessInfo.WorkingDirectory = workingDir; //variable with folder to be on myProcessInfo.FileName = file; //file to run myProcessInfo.Arguments = args; //arguments: string, spaces between args Process myProcess = new Process(); myProcess .StartInfo = myProcessInfo; gerador.Start(); myProcess.PriorityClass = ProcessPriorityClass.RealTime; //must be after starting! gerador.WaitForExit(600000); //max waiting for 10 minutes if (!gerador.HasExited) { gerador.Kill(); } TimeSpan durationInSeconds = (DateTime.Now - gerador.StartTime).Seconds.ToString(); textDuration.Text = "Duration: " + durationInSeconds + " seconds!"; optionally set on exit action //myProcess .Exited += delegate { Response.Write("Finished in "+(DateTime.Now - gerador.StartTime).Seconds.ToString() + " seconds"); }; or on exit event myProcess .EnableRaisingEvents = true; myProcess .Exited += new EventHandler(procExit); void procE...

ASPNET | Increase File Upload Size and Waiting Time

<httpRuntime maxRequestLength="4000" enable = "true" requestLengthDiskThreshold="512" useFullyQualifiedRedirectUrl="true" executionTimeout="200" /> http://msdn.microsoft.com/en-us/library/e1f13641.aspx

Email being used for spam

Some people I know are "sending" me spam email, wether they're using hotmail, gmail or others. This also making some of them sending artificial communication in Windows Live Messenger while they're actually offline. Commonly, there are links that say one thing, and actually redirect to something else. This is why I've decided to post some info on this. What to do to prevent 1) Do not respond to those "messenger bots" talking to you in WLM (usually the contact is set as offline) 2) Block "people" you don't know and is asking to join your friends, network or whatever (do give yourself the trouble of blocking them) 3) Install an anti-virus (some free: Avast! , AVG ) 4) Keep firewall and system updated and active, running regular spyware and virus checking (I recomend SpyBot Search & Destroy for Spyware removal) 5) Do NOT click on those links in awkward emails (mainly english and brazilian). These emails have usually no formatting, special...