Thursday, February 6, 2014

Allowing HttpDelete in ASP.NET MVC

In a previous post, I explained how to enable IIS (and IIS Express) to allow the HTTP DELETE verb in your ASP.NET application. This worked great for Web Forms applications and when the file was for a handler file, which typically ends with a .ashx extension.

If you need to allow the HTTP DELETE verb when developing an ASP.NET MVC application, add the following to your application's web.config file:

<system.webServer>
    <handlers>
    <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
    <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
    <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
    <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
    <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
    <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
</system.webServer>

Saturday, September 28, 2013

How to Get Cash From a Prepaid Debit Card using Gmail and Google Wallet

You have noticed this by now: brands and retailers issue Prepaid Visa or MasterCard debit cards for rebates instead of checks. The brands surely get a kickback, because I'm sure the card issuers are scraping a fee for each swipe of the debit card.

I understand the thinking by the businesses. But it stinks. The consumer usually loses in this scenario, because it's really hard to use up those last few dollars. Add on fees for keeping a balance beyond a year or 6 months, and it's easy to see how the consumer typically never quite gets the complete rebate for which they were entitled.

Another thing that bothers me about these prepaid debit cards is that the majority (if not all) online retailers will not accept them as a form of payment. I'm assuming this has something to do with mailing address verification or something along those lines. Additionally, most online retailers are unable or unwilling to perform split payment transactions, where a portion of the total price is paid with one form of payment (in this case, the prepaid debit card) and the balance with another form, such as a typical credit card.

All of this is to say that prepaid debit cards are a pain.

But I'm here to provide a solution. Or at least a solution that worked for me. Therefore, YMMV (your mileage may vary).

We'll be using two of Google's finest products, Gmail and Wallet. Wallet is Google's financial transaction application, akin to Paypal. You are able to add credit cards and bank accounts, then use Wallet to make payment at online and brick-and-mortar stores, send money to people, and withdraw funds. The best part is, there is no fee for sending money to another person via an email address! At least not for now. I don't know if that will change in the future.

So what follows are steps to follow. Disclaimer: These steps worked for me. They may not work for you. I am not liable if following these steps send your prepaid debit card balance into some sort of financial limbo. I actually tried this with $1 before I did the remaining balance. I suggest you do the same, just to be on the safe side.

Now then: 
  1. Add your activated, prepaid debit card (in my case, Visa) as a credit card in your Wallet account.
  2. In Gmail, compose a new email to the email address tied to your Wallet account, but with a + filter. Essentially, you can add +whatever to the end of your name to create an alternate email address. It is still your account and still comes back to your email inbox. So, if your email address is joe.blow@gmail.com, just use joe.blow+wallet@gmail.com
    1. I found that Gmail/Wallet will not allow you to send money to yourself. This is a workaround.
  3. Enter whatever you like for subject and body, although these are probably not required.
  4. At the bottom of the compose window, hover on the plus sign to see the expanded menu. Click the Attach Money option, indicated by a currency symbol.
  5. In the window that appears, enter the full balance of the prepaid debit card in the Amount field.
  6. Choose the prepaid debit card from the funding source dropdown list.
  7. Click Attach.
  8. There may be a verification or confirmation step or two. Accept those and send the email.
  9. In just a few short seconds, you'll receive a couple emails: you sent money and you received money! Open the email saying you received money and click the Claim Money button.
You should now see a balance at the bottom of the left column in your Wallet account. You can simply use this as a payment source when making purchases online or you can simply transfer it to a bank account.

Also, you may be able to accomplish all of this from directly within Wallet, by clicking the Send Money button. I did not try this, but it seems to have the same send money dialog as in Gmail.

Test with a small amount first and good luck!


Tuesday, June 4, 2013

WebSecurity.IsAuthenticated returns false after WebSecurity.Login

When you're explicitly calling WebSecurity.Login, behind the scenes, .NET writes a cookie to the client's browser. As you know, cookie data is sent to the server with each request.

Because WebSecurity.IsAuthenticated looks for the authentication cookie, it will return false until the user makes a new request.

Friday, May 10, 2013

How to specify the table name for a child table in a many-to-many relationship using ASP.NET MVC EF5 Code First


Here's some typical POCO code for using EF5 code first:

    public class Book
    {
        public int ID { get; set; }
        public string Name { get; set; }
        public ICollection<Author> Authors { get; set; }
    }

    public class Author
    {
        public int ID { get; set; }
        public string Name { get; set; }
        public ICollection<Book> Books { get; set; }
    }

EF will generate the following tables:

  • Books
  • Authors
  • BookAuthors

So, what if you wanted to control the naming of the tables EF is generating? You might do this:

    [Table("bookstore_Books")]
    public class Book
    {
        public int ID { get; set; }
        public string Name { get; set; }
        public ICollection<Author> Authors { get; set; }
    }

    [Table("bookstore_Authors")]
    public class Author
    {
        public int ID { get; set; }
        public string Name { get; set; }
        public ICollection<Book> Books { get; set; }
    }

Here are the table names now:

  • bookstore_Books
  • bookstore_Authors
  • BookAuthors
Not really what we want.

Unfortunately, you cannot control the name of the child table using simple DataAnnotations. You can, however, use the Fluent API. Simply override the OnModelCreating method in your DbContext class.

    public class MegaStoreDbContext : DbContext
    {
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Book>()
                .HasMany(a => a.Authors)
                .WithMany(b => b.Books)
                .Map(mc =>
                {
                    mc.MapLeftKey("BookID");
                    mc.MapRightKey("AuthorID");
                    mc.ToTable("bookstore_BookAuthors");
                });
        }
        public DbSet<Book> Books{ get; set; }
        ....
    }

Now, here are your tables:

  • bookstore_Books
  • bookstore_Authors
  • bookstore_BookAuthors

Happy Coding!


Monday, March 25, 2013

Living Off the Paid Television Grid

After a 10 year relationship with DirecTV, we finally decided we were paying way too much for "cable" and decided to cancel our account. This had nothing to do with the quality of their service. In fact, I very much love their service and technology. It's just that the cost became too high.

But we didn't exactly quit cold turkey.

For a while now, I've run a $15 set of rabbit ears to my main computer running Windows Media Center. I can pull in every local HD channel (which numbers over 20) and record most of the programming we were watching on DirecTV. Shows like Last Man Standing, Vegas, America's Test Kitchen, Joel Osteen, Shark Tank, and many others can be had over-the-air or OTA.

And since we already have a few Xbox 360s scattered about the house, by registering them in Windows Media Center, we can stream live and recorded television to all but 1 TV in the house. Life is good.

But what about live sports?

Yes, that's a problem. Here's a look at where my teams' games are broadcast:
NFL (Cincinnati Bengals): CBS, FOX, NBC, ESPN, NFL Network.
MLB (Cincinnati Reds): FOX, Fox Sports Ohio, ESPN, MLB Network.
NHL (Philadelphia Flyers): NBC, NBCSN, NHL Network.
NCAAB (Cincinnati, Florida): ESPN, ESPN2, ESPNU, Fox Sports Ohio
NCAAF (Cincinnati, Florida): ESPN, ESPN2, ESPNU, sometimes a local affiliate.

So, other than NFL, I have a serious problem when I want to watch my sports teams.

My plan was to simply buy each sport's streaming service and for those that have local blackout restriction, buy a VPN service that allows me to switch my "location" to some other locale.

I bought NHL Gamecenter and watched several Flyers games on the Xbox. This was great some of the time, when the video quality was good. Sadly, it rarely was and I experienced the "white ring of death" buffering animation far too often, sometimes as much as once every 30 seconds. After a 3-email tech support conversation over the course of a half-hour, my account was cancelled and full purchase price refunded.

Another issue for me is that since I don't subscribe to video programming, I am unable to access WatchESPN for their streaming service. This is really frustrating, since it's rare to find my teams on local affiliates (although Florida football is on CBS quite often).

So for now, I make do with so-called highlights on ESPN.com or the sports' official site. Not the greatest, but until I buy a CableCard tuner, it'll have to do.


Wednesday, March 13, 2013

Allowing DELETE Verb on .ashx file in IIS 7+

If you ever need to use the DELETE verb with an .ashx file on IIS 7 and above, you'll need to modify the SimpleHandlerFactory Handler Module either in IIS or in your web.config. I'll show you the code to add to your web.config below.

In your system.webServer node, simply add the following:

<handlers>
    <remove name="SimpleHandlerFactory-Integrated-4.0" />
    <add name="SimpleHandlerFactory-Integrated-4.0" path="*.ashx" verb="GET,HEAD,POST,DEBUG,DELETE" type="System.Web.UI.SimpleHandlerFactory" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>

I've seen other information suggesting disabling or removing a WebDAV handler, but it was not installed on my local IIS or on my production web server. The solution above worked for me.

Source: http://stackoverflow.com/a/10616736/256885