Reputation: 9537
I am trying to update an Asp.Net web forms website to using MVC 5. There is a shopping cart component that extends the profile provider. This xml located in the web.config appears to auto generate code in the old website project that provides a shopping cart property but does nothing in the mvc version:
<!-- Profile provider -->
<profile defaultProvider="SQLProfileProvider">
<providers>
<clear/>
<add name="SQLProfileProvider" connectionStringName="LocalSqlServer" applicationName="/" type="System.Web.Profile.SqlProfileProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
</providers>
<properties>
<!-- Define our shopping cart which is contained in customerManager and serialized as binary -->
<add name="ShoppingCart" allowAnonymous="true" type="customerManager.ShoppingCart, customerManager" serializeAs="Binary"></add>
</properties>
</profile>
Hence the following code fails:
Profile.ShoppingCart.AddItem(1500);
Error 3 'System.Web.Profile.ProfileBase' does not contain a definition for 'ShoppingCart' and no extension method 'ShoppingCart' accepting a first argument of type 'System.Web.Profile.ProfileBase' could be found (are you missing a using directive or an assembly reference?) D:\VirtualWeb2\VirtualWeb2\Controllers\AccountController.cs 92 29 VirtualWeb2
The original code for the shopping cart is in a stand alone DLL although I can get to the source if I really need to. I'd prefer to handle it through configuration if this is possible.
I've looked at many posts online and can't find anything that covers my same scenario. Any idea why this "ShoppingCart" property does not autogenerate when building the mvc project but works in the asp net web forms website?
Upvotes: 1
Views: 330
Reputation: 56869
KingOfHypocrites answer (from comment):
public static ShoppingCart GetCart(this Controller c)
{
var cart = c.Profile["ShoppingCart"];
return (customerManager.ShoppingCart)cart;
}
Upvotes: 1