Joey Iodice http://joeyiodice.com Software Development & Technology Solutions Sat, 22 Aug 2015 23:51:00 +0000 en-US hourly 1 https://wordpress.org/?v=4.8.2 How to setup up a Google Voice number http://joeyiodice.com/how-to-setup-up-a-google-voice-number/ http://joeyiodice.com/how-to-setup-up-a-google-voice-number/#respond Sat, 22 Aug 2015 05:36:17 +0000 http://joeyiodice.com/?p=4555 ...read more →

The post How to setup up a Google Voice number appeared first on Joey Iodice.

]]>
This a quick guide on how to setup a free Google Voice phone number.
Before I dive right into the steps, here are a few good reasons for why I suggest people use Google Voice:

  • IT IS FREE! Many similar services charge $12+ dollars per month
  • You can add a business layer to your mobile phone by having a different voicemail and still keeping your normal voicemail for people who call your number directly.
  • You can add an extra layer of protection since Google Voice allows you to easily block phone numbers at a carrier level instead of relying on your device. If you have ever tried to block an annoying telemarketer on your cell phone, you know how annoying it is.  Even if you do have an app or a phone setting to block it, your phone still receives that call before it is blocked.
  • It gives you the ability to manage your phone calls, text messages, and voice mails on the computer.  Voicemail recordings can be automatically emailed to you and even transcribed into text.
  • You can ring multiple phone numbers with just your one Google Voice number.  So if you have a mobile phone & a home phone, you can set Google Voice to ring both at the same time.

Just to be clear, Google Voice does not provide the calling capabilities.
Google voice just acts as a middle man and routes your calls for free to devices that have phone service.

Ok, so the first step to setting up your Google Voice account is to make sure you have a Google account.
If you have a Gmail account, then you are good to go.
If you don’t have a Gmail or Google account, sign up for one here

Now go to the Google Voice Home Page

If you are not signed in, go ahead and sign in.

You should now see this screen if you have never setup a Google Voice number on your account:

GoogleVoiceStep1

 

Go ahead and accept the terms & privacy policy and continue on to the next step.
After that you will be asked whether you want a new number or if you want to user your mobile number (port your number to Google Voice).
You will want a new number, this is pretty much the point of Google Voice.

GoogleVoiceStep2

 

Now that you have selected that you want a new number, you will need to go ahead and setup your device that you want to route the calls to.
You can choose a Mobile phone, Home phone, or Work phone.
Make sure you enter in a phone number that you have access to right now since you will need to verify ownership by accepting a call and entering a unique code.

GoogleVoiceStep3

Now once you hit continue, you will be asked to verify that you own this phone number by accepting a call.
Go ahead and hit the “Call me now” button and enter in the verification code that it tells you to enter when you receive the call.

GoogleVoiceStep4 GoogleVoiceStep5

 

Once you verify your device, you will see the next screen which allows you to select your free Google Voice phone number.
Make sure you choose a number that you like because Google charges $10 if you want to change your number later.
You have the option searching by area code, zip code, or by city to determine the area code of your phone number.
You also have the ability to search for certain vanity word phrases or certain number combinations.
If you really want a certain area code and none are available, try waiting a few days and trying again since phone number inventories are always changing.
At the time of writing this, there were no 615 area code phone numbers but I am sure there will be some more soon.

GoogleVoiceStep6 GoogleVoiceStep7

Once you choose your number and select “Continue”, you will now have your new Google Voice phone number assigned to your account.

GoogleVoiceStep8

 

The post How to setup up a Google Voice number appeared first on Joey Iodice.

]]>
http://joeyiodice.com/how-to-setup-up-a-google-voice-number/feed/ 0
Download failed. Destination directory for file streaming does not exist or is not writable. http://joeyiodice.com/download-failed-destination-directory-for-file-streaming-does-not-exist-or-is-not-writable-wordpress-3-5/ http://joeyiodice.com/download-failed-destination-directory-for-file-streaming-does-not-exist-or-is-not-writable-wordpress-3-5/#comments Tue, 08 Jan 2013 20:42:46 +0000 http://joeyiodice.com/?p=4522 ...read more →

The post Download failed. Destination directory for file streaming does not exist or is not writable. appeared first on Joey Iodice.

]]>
Did you get this error: “Download failed. Destination directory for file streaming does not exist or is not writable.” after upgrading to WordPress 3.5? The error usually occurs when trying to install or update a plugin or theme. Here is a simple fix to the problem.

  • First you will need to gain access to your wordpress files. This will usually mean getting FTP access to your website directory.
  • Once you have obtained access to your WordPress directory, open up the wp-config.php file.
  • Add this line of text to the end of the file:
    define(‘WP_TEMP_DIR’, ABSPATH . ‘wp-content/’);
  • Save your wp-config.php file and you should no longer have problems updating/installing plugins or themes

This will fix a PHP problem that fails to write to a temporary folder and will use your wp-content folder as the temporary location when doing updates to plugins or themes.

For more information on the cause of this problem, visit: http://core.trac.wordpress.org/ticket/22900

The post Download failed. Destination directory for file streaming does not exist or is not writable. appeared first on Joey Iodice.

]]>
http://joeyiodice.com/download-failed-destination-directory-for-file-streaming-does-not-exist-or-is-not-writable-wordpress-3-5/feed/ 3
How To Make Adsense Ads Responsive http://joeyiodice.com/how-to-make-adsense-ads-responsive/ http://joeyiodice.com/how-to-make-adsense-ads-responsive/#comments Thu, 13 Dec 2012 00:12:07 +0000 http://joeyiodice.com/?p=4507 ...read more →

The post How To Make Adsense Ads Responsive appeared first on Joey Iodice.

]]>
So you have a responsive website design but you need to add some Google Adsense advertisements into your design?  Here is a simple code snippet that will allow you to serve Adsense ads based on screen size.  It  will also handle browser resizing (overflow problems).  Just insert your publisher ID and ad IDs and you are set.  The code can easily be adjusted for different ad sizes and target screen sizes.  Leave a comment below with any questions or suggestions.

<div style="overflow: hidden;">
            <script type="text/javascript">
                google_ad_client = "ca-pub-XXXXXXXXXXXXXXXX";
                if (window.innerWidth >= 800) {
                    /* Desktop Ad */
                    google_ad_slot = "XXXXXXXXXX";
                    google_ad_width = 728;
                    google_ad_height = 90;
                } else if (window.innerWidth < 400) {
                    /* Mobile Ad */
                    google_ad_slot = "XXXXXXXXXX";
                    google_ad_width = 300;
                    google_ad_height = 250;
                } else {
                    /* Tablet Ad */
                    google_ad_slot = "XXXXXXXXXX";
                    google_ad_width = 468;
                    google_ad_height = 60;
                }
            </script>
            <script type="text/javascript" 
             src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
            </script>
        </div>

The post How To Make Adsense Ads Responsive appeared first on Joey Iodice.

]]>
http://joeyiodice.com/how-to-make-adsense-ads-responsive/feed/ 2
Converting a TP-Link TL-WR1043ND to DD-WRT http://joeyiodice.com/converting-tp-link-tl-wr1043nd-to-dd-wrt/ http://joeyiodice.com/converting-tp-link-tl-wr1043nd-to-dd-wrt/#comments Thu, 08 Nov 2012 20:07:39 +0000 http://joeyiodice.com/?p=4488 ...read more →

The post Converting a TP-Link TL-WR1043ND to DD-WRT appeared first on Joey Iodice.

]]>
In this post, I will walk you through converting your TP-Link TL-WR1043ND from factory firmware to DD-WRT 3rd party firmware.  DD-WRT is generally more stable than the factory firmware and contains more advanced features.  This is a pretty easy firmware upgrade with one catch.  If your router’s Serial Number begins with 12, then you will need to perform an additional step before converting to DD-WRT. The extra step is to flash a special german firmware image before flashing to DD-WRT.  Newer versions of the TL-WR1043ND router turn off the WAN port during a firmware upgrade which never gets turned back on in DD-WRT.  This special german firmware image prevents the WAN from being turned off during the DD-WRT conversion.

**UPDATE** If you already have a non working DD-WRT install, you can use this file to revert your firmware back to stock TP-Link. Then you can install the german firmware file and then install DD-WRT.

  •  First, you will need to make a hardwired connection to the router (do not attempt this using a wireless connection).
  • Next you will need to obtain the DD-WRT firmware for this router.  The firmware can be found HERE. The link is to the DD-WRT ftp site.  Select the latest year, then select the most recent build (not a testing build), then select the tplink_tl-wr1043nd folder, and lastly click the factory-to-ddwrt.bin file.  I used build 19419 at the time of writing this.
  • If you have a router that has a serial number starting with 12, then you will need to download THIS german firmware file, otherwise you can skip this step.
  • Open up a browser and navigate to http://192.168.1.1 and the default user is admin, default password is admin.
  • Go to System Tools and then Firmware Upgrade.  You should see the following screen:
  • If your router serial number starts with 12, select browse and choose the german firmware file that you downloaded earlier.  Otherwise select browse and choose the  factory-to-ddwrt.bin file that you downloaded from DD-WRT.
  • You will then see the next two screens and your router will automatically reboot.
  • If you uploaded the german firmware file, then you will need to go back to System-Tools then Firmware-Upgrade to upload the factory-to-ddwrt.bin file.
  • Once you have uploaded the factory-to-ddwrt.bin file, the router will reboot and you will see the DD-WRT setup screen.  You just need to set your username and password and you are ready to start configuring your DD-WRT router.

If you have any questions or suggestions, leave a comment. Also, let me know what builds you have found to be stable on this router.

The post Converting a TP-Link TL-WR1043ND to DD-WRT appeared first on Joey Iodice.

]]>
http://joeyiodice.com/converting-tp-link-tl-wr1043nd-to-dd-wrt/feed/ 243
Converting a Linksys WRT160N V3 to DD-WRT http://joeyiodice.com/converting-a-linksys-wrt160n-v3-to-dd-wrt/ http://joeyiodice.com/converting-a-linksys-wrt160n-v3-to-dd-wrt/#comments Thu, 11 Oct 2012 21:55:01 +0000 http://joeyiodice.com/?p=4462 ...read more →

The post Converting a Linksys WRT160N V3 to DD-WRT appeared first on Joey Iodice.

]]>
So you are tired of your WRT160N dropping connections or maybe you want to turn it into a wireless bridge, DD-WRT is the solution. Also, if you are just looking for a cheap DD-WRT router, you can find a refurbished WRT160N on Amazon for usually less than 30 dollars.
WARNING: When flashing your router with custom firmware, there is always a small chance of bricking your router.

  • First, you will need to make a hardwired connection to the router (do not attempt this over a wireless connection).
  • Next, you will need to download the DD-WRT firmware for this router.  The firmware can be found HERE. Find the build folder with the newest date stamp.  Then in that folder, find the firmware file that has “WRT160Nv3” in the file name.  I used dd-wrt.v24-18946_NEWD-2_K2.6_mini_wrt160nv3.bin since it is the latest version at the time.  Some people recommended using build 16773 since the wifi drivers in newer builds may cause problems.
  • After obtaining the DD-WRT firmware, you will need to perform a 30/30/30 reset on your router. Some people have reported that the 30/30/30 reset is not working, if so try a Linksys factory reset
  • Next, you will need to open a browser and navigation to http://192.168.1.1/. You should see the following screen:
  • If your computer is not able to connect, you may have to assign an IP address to your network connection, such as the following:
  • Now you will click the browse button and select the DD-WRT firmware file that you downloaded earlier and then press the Upload button.  You should now see this screen:
  • Do not press anything, it may take a few minutes to complete.  Look at your router and once the lights are steadily lit up and not flashing, you may click the continue button.
  • You should now see the change password screen (do not bother setting this now):
  • You will now perform another 30/30/30 reset on your router. After that, navigate to 192.168.1.1 and hit the Reboot link on the page.  Your router is now ready to be configured.
If you have any questions, leave a comment below.

 

The post Converting a Linksys WRT160N V3 to DD-WRT appeared first on Joey Iodice.

]]>
http://joeyiodice.com/converting-a-linksys-wrt160n-v3-to-dd-wrt/feed/ 19
Configure Uverse Gateway (Static IPs) with pfsense router http://joeyiodice.com/configure-uverse-gateway-with-pfsense-router/ http://joeyiodice.com/configure-uverse-gateway-with-pfsense-router/#comments Tue, 28 Aug 2012 05:50:02 +0000 http://joeyiodice.com/?p=4409 ...read more →

The post Configure Uverse Gateway (Static IPs) with pfsense router appeared first on Joey Iodice.

]]>
In this blog, I will walk you through setting up your Uverse gateway to allow all traffic to properly pass through to your pfsense router or any other router.

While this blog is aimed at configuring a Uverse gateway with static IP addresses, most of the information is the same for configuring a Uverse gateway with a dynamic IP.  If you need to configure more than one static IP address into your pfsense router, then you will need to setup CARP virtual IP addresses which is beyond this tutorial.

First you must have a working Uverse gateway that has been installed by an ATT tech. Do not connect your pfsense router yet.  On the gateway, you will find a sticker that contains the information you need to connect to the device. The default IP is usually 192.168.1.254, so fire up a browser and head to that IP address.  If you are prompted for a password, it is the password on the side of your Uverse 2wire gateway.

Once you are logged in, go to the settings tab and then to the broadband tab.  If your ATT tech already configured your static IP addresses, then your router address and Subnet Mask will already be entered in.  If you have a block of 5 static IP addresses, then your subnet mask will be the same as below.  If your static IP addresses have not been configured, you will have to get the Router Address (Gateway IP) from ATT support.  Make sure the check box for Auto Open Firewall is checked.

Save the page if you made any changes (most likely).  Now it is time to configure your pfsense router.  Connect your computer to the LAN of your pfsense box.  Connect into the pfsense web administration (default IP: 192.168.1.1, default Username: admin, Default Password: pfsense).  Go to Settings -> Routing to access the list of gateways.  Click the add gateway button and you will then select your WAN interface, enter in a gateway name, and enter your gateway IP address (Router Address in the Uverse Link Configuration page).  You will also need to check the Default Gateway box.

Now that the gateway is configured, you will need to setup your WAN inteface.  Go to Interfaces -> WAN (or whatever your WAN is named such as UVERSE).  You will need to select Static from the Type dropdown.  Then enter in an IP address that is in your usable range and select the gateway that you configured in the previous step.  You will also have to select the subnet mask (/29 for a 5 static IP address block).

Now that your pfsense router is configured with your static IP address, plug the WAN port of your pfsense router into one of the network ports on the Uverse 2Wire gateway.  Connect your computer to one of the other ports on the Uverse gateway and log back into the Uverse gateway web page as we did in the first step. Go to the Settings tab, then the LAN tab and then the IP Address Allocation link.  If you configured your pfsense router correctly, it should have pushed the static IP into this page. You might also see your computer in this list, do not worry about it.  Make sure your pfsense router is listed on this page and that the settings look similar to the image below:

If your firewall on the device shows disabled like the image above, you can skip this next step.  If your device has the firewall enabled, you will need to go to the settings tab, then the firewall tab and then the Applications, Pinholes and DMZ link.  On this page you will select your pfsense router from the devices and then select the last option (Allow all applications) which will essentially turn off the firewall. Then hit the save button.

Your gateway should now be passing all incoming traffic to your pfsense router.  This last step is optional.  Go to the settings tab, then firewall tab, then Advance Configuration link.  This is my working configuration below, I let the gateway handle some basic firewall functions. If you would like to completely disabled the gateway firewall, you can uncheck Stealth Mode & Block Ping under Enhanced Security.  It is best to leave the timeouts alone.  You can also uncheck all of the items under Attack Detection since your pfsense router will be handling these.

 

Once you get your gateway working, try to avoid changing WAN ports.  The Uverse gateway associates that static IP address to your pfsense WAN MAC address.  I recently built a new pfsense box and ran into a few problems trying to get the Uverse gateway to let me use that same static IP with a new MAC address.  Leave any questions or comments below.

The post Configure Uverse Gateway (Static IPs) with pfsense router appeared first on Joey Iodice.

]]>
http://joeyiodice.com/configure-uverse-gateway-with-pfsense-router/feed/ 10
ATAPORT.SYS BSOD Virus Fix http://joeyiodice.com/ataport-sys-bsod-virus-fix/ http://joeyiodice.com/ataport-sys-bsod-virus-fix/#respond Tue, 28 Aug 2012 03:34:16 +0000 http://joeyiodice.com/?p=4403 ...read more →

The post ATAPORT.SYS BSOD Virus Fix appeared first on Joey Iodice.

]]>
If you see a BSOD like the one above (ATAPORT.SYS error), you may be the victim of a rootkit virus.
Most likely it comes from the malware family: Rootkit.Win32.TDSS

Kaspersky Anti Virus makes a free tool to remove this infection from your system.

The tool is called TDSSKiller.exe and can be downloaded here.

The tool has a simple GUI and can run on pretty much any system that has Windows Xp or newer operating system (64 bit or 32 bit).

You may have to boot into safe mode to run the tool. (To boot into safe mode: consecutively press F8 during boot until you are given a list of choices, one of them being to boot into safemode with networking.)

After running the tool and removing any infections, you must reboot your computer.  After that, run your antivirus to remove any remaining infections.

For more information on using the TDSSKiller.exe tool, visit Kaspersky’s support article:

http://support.kaspersky.com/faq/?qid=208280684

The post ATAPORT.SYS BSOD Virus Fix appeared first on Joey Iodice.

]]>
http://joeyiodice.com/ataport-sys-bsod-virus-fix/feed/ 0
Convert SQL Azure GetDate() UTC Time to Local Time http://joeyiodice.com/convert-sql-azure-getdate-utc-time-to-local-time/ http://joeyiodice.com/convert-sql-azure-getdate-utc-time-to-local-time/#comments Mon, 23 Jul 2012 05:05:24 +0000 http://joeyiodice.com/?p=4383 ...read more →

The post Convert SQL Azure GetDate() UTC Time to Local Time appeared first on Joey Iodice.

]]>
I have been using SQL Azure for almost a year now. I recently found out that SQL Azure stores date/times in UTC format when generated within the database using the GetDate() function and similar built in SQL date/time functions. Also, at this time there is no way to change the timezone for a SQL Azure instance.

I have done a few SQL Azure projects but I started from scratch on them and had my applications generating the date/time so it never was a problem. Recently I had to transfer an existing project from an on-premise MS SQL 2008 database to SQL Azure. The project stores all times in the Central Time Zone since the on-premise MS SQL server was configured to use that timezone when GetDate() was called. The project is about 2 years old and has a few hundred stored procedures.

The easiest solution for me was to replace all GetDate() calls in the stored procedures with a custom date/time calculation function to keep the data consistent. Ok, so lets get to it.

Case 1: Your local time zone does not observe daylight savings time and stays consistent year round.  This is easy to handle, you can simply replace GetDate() with a DateAdd() function.

DATEADD (hh, n, GETDATE())

You can use this by replacing n with the difference in hours between your time and UTC.

Case 2: Your local time zone observes daylight savings such as the Central Time Zone. This requires a custom set of functions for calculating when daylight savings starts and ends, then a function for determining if it is currently daylight savings time or not and returns the corrected date/time.

These are my functions for converting the SQL Azure UTC time into the Central Time Zone.

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:	Joey Iodice (JoeyIodice.com)
-- Credits:	Tim Cullen (MSSQLTips.com)
-- Create date: 07/20/2012
-- Description:	Calculates the second Sunday in
--		March at 8:00AM UTC (2:00AM CST)
-- =============================================
CREATE FUNCTION [dbo].[DaylightSavingsStart]
(@Year VARCHAR(4))
RETURNS SMALLDATETIME
AS
BEGIN
	DECLARE @StartWeek SMALLDATETIME

	SET @StartWeek = '03/01/' + CONVERT(VARCHAR,@Year)

	RETURN CASE DATEPART(dw,@StartWeek)
		WHEN 1 THEN 
			DATEADD(HOUR,176,@StartWeek)
		WHEN 2 THEN
			DATEADD(HOUR,320,@StartWeek)
		WHEN 3 THEN 
			DATEADD(HOUR,296,@StartWeek)
		WHEN 4 THEN 
			DATEADD(HOUR,272,@StartWeek)
		WHEN 5 THEN 
			DATEADD(HOUR,248,@StartWeek)
		WHEN 6 THEN 
			DATEADD(HOUR,224,@StartWeek)
		WHEN 7 THEN
			DATEADD(HOUR,200,@StartWeek)
	END
END

GO

This function calculates the beginning of Daylight Savings Time which is the second Sunday in March in my area. It uses 8:00 AM UTC for the  time because Central Time is 6 hours behind UTC time before daylight savings time.  This can easily be modified for other time zones such as Eastern Time by subtracting an hour from each DATEADD function.

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

-- =================================================
-- Author:	Joey Iodice (JoeyIodice.com)
-- Credits:	Tim Cullen (MSSQLTips.com)
-- Create date: 07/20/2012
-- Description:	Calculates the first Sunday in
--		November at 7:00AM UTC (2:00AM CDT)
-- =================================================
CREATE FUNCTION [dbo].[DaylightSavingsEnd]
(@Year VARCHAR(4))
RETURNS SMALLDATETIME
AS
BEGIN
	DECLARE @EndWeek SMALLDATETIME

	SET @EndWeek = '11/01/' + CONVERT(VARCHAR,@Year)

	RETURN CASE DATEPART(dw,DATEADD(WEEK,1,@EndWeek))
		WHEN 1 THEN
			DATEADD(HOUR,7,@EndWeek)
		WHEN 2 THEN
			DATEADD(HOUR,151,@EndWeek)
		WHEN 3 THEN
			DATEADD(HOUR,127,@EndWeek)
		WHEN 4 THEN
			DATEADD(HOUR,103,@EndWeek)
		WHEN 5 THEN 
			DATEADD(HOUR,79,@EndWeek)
		WHEN 6 THEN 
			DATEADD(HOUR,55,@EndWeek)
		WHEN 7 THEN 
			DATEADD(HOUR,31,@EndWeek)
	END
END

GO

This function is similar to the other one, it calculates the end of Daylight Savings Time which is the first Sunday in November for my area.  It uses 7:00AM UTC for the time because it is 2:00AM Central Daylight Savings Time.  This function can also easily be converted for other time zones by adding or subtracting hours from the DATEADD function.

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

-- =================================================
-- Author:		Joey Iodice
-- Create date: 07/20/2012
-- Description:	Converts UTC time into Central Time
-- =================================================
CREATE FUNCTION [dbo].[GetLocalDateTime] ()
RETURNS DATETIME
AS
BEGIN
	DECLARE @StartDate SMALLDATETIME, @EndDate SMALLDATETIME, 
	@Date DATETIME

	SET @Date = GETUTCDATE()
	SET @StartDate = dbo.DaylightSavingsStart(CONVERT(VARCHAR,DATEPART(YEAR,GETDATE())))
	SET @EndDate = dbo.DaylightSavingsEnd(CONVERT(VARCHAR,DATEPART(YEAR,GETDATE())))

	IF @Date between @StartDate and @EndDate
		BEGIN
			SET @Date = DATEADD (hh, -5, GETUTCDATE())
		END
	ELSE
		BEGIN
			SET @Date = DATEADD (hh, -6, GETUTCDATE())
		END
	RETURN @Date
END

GO

This last function determines whether or not the current UTC time falls in daylight savings and returns the correct time for the Central Time Zone.  I used GETUTCDATE() instead of GETDATE() so that it will work on any MS SQL database.

From here, I simply scripted all of the stored procedures and did a find/replace to easily replace every GetDate() call with my function: dbo.GetLocalDateTime() .

I based my functions on Tim Cullen’s blog post and I would like to thank him for his work.

The post Convert SQL Azure GetDate() UTC Time to Local Time appeared first on Joey Iodice.

]]>
http://joeyiodice.com/convert-sql-azure-getdate-utc-time-to-local-time/feed/ 3
Cascading DropDownLists Using MVC3 & Jquery http://joeyiodice.com/cascading-dropdownlists-using-mvc3-and-jquery/ http://joeyiodice.com/cascading-dropdownlists-using-mvc3-and-jquery/#respond Sun, 22 Jul 2012 03:04:53 +0000 http://joeyiodice.com/?p=4302 ...read more →

The post Cascading DropDownLists Using MVC3 & Jquery appeared first on Joey Iodice.

]]>
This is something I put together to show how easy it is to do cascading dropdownlists using MVC3 and Jquery.
My cascading dropdownlists demonstration is for choosing a vehicle’s year, make, and model.
First thing is the MVC3 model, I hardcoded in some data for demo purposes but it can very easily be hooked up to a database.

public class VehicleModel
    {
        [Required(ErrorMessage = "Year is required")]
        [Display(Name="Vehicle Year")]
        public int SelectedYear { get; set; }

        [Required(ErrorMessage = "Make is required")]
        [Display(Name = "Vehicle Make")]
        public string SelectedMake { get; set; }

        [Required(ErrorMessage = "Model is required")]
        [Display(Name = "Vehicle Model")]
        public string SelectedModel { get; set; }

        public IEnumerable Years { get; set; }
        public IEnumerable Makes { get; set; }
        public IEnumerable Models { get; set; }

    }

    public class Vehicle
    {
        public int Year { get; set; }
        public string Make { get; set; }
        public string Model { get; set; }

        public static List GetVehicles()
        {
            List vehicles = new List();

            vehicles.Add(new Vehicle { Year = 2011, Make = "Honda", Model = "Civic" });
            vehicles.Add(new Vehicle { Year = 2011, Make = "Honda", Model = "Accord" });
            vehicles.Add(new Vehicle { Year = 2011, Make = "Dodge", Model = "Durango" });
            vehicles.Add(new Vehicle { Year = 2011, Make = "Dodge", Model = "Charger" });
            vehicles.Add(new Vehicle { Year = 2010, Make = "Hummer", Model = "H2" });
            vehicles.Add(new Vehicle { Year = 2010, Make = "Honda", Model = "Accord" });
            vehicles.Add(new Vehicle { Year = 2010, Make = "Jeep", Model = "Compass" });
            vehicles.Add(new Vehicle { Year = 2010, Make = "Jeep", Model = "Grand Cherokee" });
            vehicles.Add(new Vehicle { Year = 2010, Make = "Jeep", Model = "Wrangler Rubicon Unlimited" });
            vehicles.Add(new Vehicle { Year = 2010, Make = "Jeep", Model = "Wrangler Unlimited" });
            vehicles.Add(new Vehicle { Year = 2010, Make = "Dodge", Model = "Durango" });
            vehicles.Add(new Vehicle { Year = 2010, Make = "Dodge", Model = "Charger" });
            vehicles.Add(new Vehicle { Year = 2010, Make = "BMW", Model = "325i" });
            vehicles.Add(new Vehicle { Year = 2010, Make = "BMW", Model = "M3" });
            vehicles.Add(new Vehicle { Year = 2009, Make = "Honda", Model = "Civic" });
            vehicles.Add(new Vehicle { Year = 2009, Make = "Honda", Model = "Accord" });
            vehicles.Add(new Vehicle { Year = 2009, Make = "Dodge", Model = "Durango" });
            vehicles.Add(new Vehicle { Year = 2009, Make = "Dodge", Model = "Charger" });
            vehicles.Add(new Vehicle { Year = 2009, Make = "BMW", Model = "530i" });
            vehicles.Add(new Vehicle { Year = 2009, Make = "BMW", Model = "730d" });

            return vehicles;
        }
    }

It consists of two classes, my view class and my data class. (Not the best model but will do).
Next up is the controller, pretty straightforward.

public class CascadingDropdownsController : Controller
    {
        //
        // GET: /CascadingDropdowns/
        public ActionResult Index()
        {
            //Vehicle model
            VehicleModel theModel = new VehicleModel();

            //Drop down list
            List years = Vehicle.GetVehicles().Select(x => x.Year).Distinct().ToList();
            List blankList = new List();
            theModel.Years = years.Select(x => new SelectListItem
            {
                Value = x.ToString(),
                Text = x.ToString()
            });

            theModel.Makes = blankList.Select(x => new SelectListItem
            {
                Value = x,
                Text = x
            });

            theModel.Models = blankList.Select(x => new SelectListItem
            {
                Value = x,
                Text = x
            });

            return View(theModel);
        }

        public JsonResult GetMakes(int year)
        {
            List makes = Vehicle.GetVehicles().Where(x => x.Year == year).Select(x => x.Make).Distinct().ToList();

            return Json(makes, JsonRequestBehavior.AllowGet);
        }

        public JsonResult GetModels(int year, string make)
        {
            List models = Vehicle.GetVehicles().Where(x => x.Year == year && x.Make == make).Select(x => x.Model).ToList();

            return Json(models, JsonRequestBehavior.AllowGet);
        }
    }

Last up is the view:

@model Mvc3.Models.VehicleModel
@{
    ViewBag.Title = "Cascading Dropdowns Using MVC3 & Jquery";
}

Demo for Cascading DropDownLists Using MVC3 & Jquery



Select your vehicle @Html.ValidationSummary(true, "Please correct the follwing error(s):") @using (Html.BeginForm("index", "pages", FormMethod.Post)) {

@Html.LabelFor(m => m.SelectedYear)
@Html.DropDownListFor(m => m.SelectedYear, Model.Years,"Select a year", new { onchange = "changeYear();" }) @Html.ValidationMessageFor(m => m.SelectedYear)

@Html.LabelFor(m => m.SelectedMake)
@Html.DropDownListFor(m => m.SelectedMake, Model.Makes, new { onchange = "changeMake();" }) @Html.ValidationMessageFor(m => m.SelectedMake)

@Html.LabelFor(m => m.SelectedModel)
@Html.DropDownListFor(m => m.SelectedModel, Model.Models, new { onchange = "changeModel();" }) @Html.ValidationMessageFor(m => m.SelectedModel)

You have choosen:

}

The post Cascading DropDownLists Using MVC3 & Jquery appeared first on Joey Iodice.

]]>
http://joeyiodice.com/cascading-dropdownlists-using-mvc3-and-jquery/feed/ 0
Catching ASP.NET MVC Errors using ELMAH http://joeyiodice.com/catching-asp-net-mvc-errors-using-elmah/ http://joeyiodice.com/catching-asp-net-mvc-errors-using-elmah/#respond Tue, 01 May 2012 16:09:29 +0000 http://joeyiodice.com/?p=4317 ...read more →

The post Catching ASP.NET MVC Errors using ELMAH appeared first on Joey Iodice.

]]>
ELMAH (Error Logging Modules and Handlers) is a great application-wide error logging tool.

ELMAH Features:

  • Logging of unhandled exceptions.
  • A web page for viewing the logged exceptions including stack traces.
  • An e-mail notification whenever an error occurs including the error details.
  • An RSS feed that includes the last 15 errors from the log.

Installing ELMAH:

The easiest way to install ELMAH is using Nuget. If you are using ELMAH in an MVC project, I suggest installing ELMAH.MVC which will install ELMAH and a custom MVC Area for accessing the logs at “/Admin/ELMAH” directory. It will also setup the basic configurations in your web.config file.

ELMAH.MVC Nuget Package

If you don’t want the added ELMAH MVC Area or if you are installing ELMAH on an ASP.net WebForms project, just install the regular ELMAH nuget package.

ELMAH Nuget Package

Configuring ELMAH:

You will need to open up your web.config file to make configuration changes.

Customer Error Pages:

To fully benefit from ELMAH, you should set your Custom Errors configuration to “On” or “RemoteOnly”. The default custom errors settings is “RemoteOnly”.

<customErrors mode="RemoteOnly" defaultRedirect="/Error404" />

Storing errors:

By default, ELMAH stores up to 15 errors in memory. It can be configured to hold up to 500 in memory.
Memory configuration:

<elmah>
  <errorLog type="Elmah.MemoryErrorLog, Elmah" size="50" />
</elmah>

ELMAH can also store errors in XML files with each error having it’s own XML file. The log path must be a sub folder of the application and have write permissions.
XML configuration:

<elmah>
  <errorLog type="Elmah.XmlFileErrorLog, Elmah" logPath="~/App_Data/XML_Logs" />
</elmah>

Along with memory and XML file storage, ELMAH can store errors in SQLite and SQL Server
SQLite configuration:

<connectionStrings>
  <add name="ElmahDB" connectionString="data source=~/App_Data/Elmah.db" />
</connectionStrings>
<elmah>
  <errorLog type="Elmah.SQLiteErrorLog, Elmah" connectionStringName="ElmahDB" />
</elmah>

SQL Server configuration:

<connectionStrings>
  <add name="ElmahDB"
       connectionString="Data Source=.;Initial Catalog=ELMAH;Trusted_Connection=True" />
</connectionStrings>
<elmah>
  <errorLog type="Elmah.SqlErrorLog, Elmah" connectionStringName="ElmahDB" />
</elmah>

Error Emails:

You can have ELMAH send you an email with a detailed report for each error by adding the following to the web.config:

<elmah>
  <errorMail from="sender@domain.com" 
             to="receiver@domain.com" 
             cc="copy@domain.com" 
             subject="Your Subject"
             async="true or false"
             smtpPort="25"
             smtpServer="smtp.domain.com" 
             userName="username"
             password="password" />
</elmah>

Securing ELMAH:

Elmah is set to deny remote access to the error log page but you can enable it and use ASP.net security measures by either securing the controller or the elmah.axd path.

Filtering Errors:

You can programmatically filter errors in your Global.asax file. You can filter errors from being emailed to you or logged. Here is a quick example of how to dismiss URL errors in the error mail. You just need to include the Elmah namespace and add the following function to Global.asax:

void ErrorMail_Filtering(object sender, ExceptionFilterEventArgs e)
{
    if (e.Exception.GetBaseException() is HttpException)
    e.Dismiss();
}

The post Catching ASP.NET MVC Errors using ELMAH appeared first on Joey Iodice.

]]>
http://joeyiodice.com/catching-asp-net-mvc-errors-using-elmah/feed/ 0