Tuesday, March 13, 2012

The model backing the 'MyDBContext' context has changed since the database was created. Either manually delete/update the database, or call Database.SetInitializer with an IDatabaseInitializer instance. For example, the DropCreateDatabaseIfModelChanges strategy will automatically delete and recreate the database, and optionally seed it with new data.

Today I have faced a problem when working with a previous developed ASP.NET MVC application. Just copy the database(.sdf) from previous version to new version. I have changed some validation and business logic. But when run the application it shows me the following error:


The model backing the 'MyDBContext' context has changed since the database was created. Either manually delete/update the database, or call Database.SetInitializer with an IDatabaseInitializer instance. For example, the DropCreateDatabaseIfModelChanges strategy will automatically delete and recreate the database, and optionally seed it with new data.


It was a running application after searching on community I have got the solution.

Solution 1:
However, even if you manually update the database to follow the model, this exception will still occur. The reason is that EF does not check model schema completely: tables, columns, keys, indexes etc.

It calculates a hash of the model and compares with the hash of model which the database was built with. The hash is stored at EdmMetadata table.

Monday, March 12, 2012

ASP.NET Single Page Application (SPA)

My previous article wrote about new features of MVC 4.0 beta. Today I want to share with you another cool feature "ASP.NET Single Page Application (SPA)" known as ASP.NET SPA.
The ASP.NET Single Page Application (SPA) is a new feature in MVC 4 beta preview.

This project type is based on a stack of open source libraries and the MVVM pattern made popular by WPF and Silverlight. Single Page Application(SPA) Frameworks are growing popularity in the web community with lot of libraries such as JavaScriptMVC, Backbonejs and many other libraries.

(Img src: asp.net official site)


ASP.NET MVC 4 introduces experimental support for building single page application (SPA) through a template. Much of the plumbing work of wiring up the client side scripts, javascript modelviews and the controllers is automated, making it a quick start to develop SPAs relatively easier.

The ASP.NET Single Page Application (SPA)includes the following components:

1.A set of JavaScript libraries for richer local interactions with cached data
2.Additional Web API components for unit of work and DAL support
3.An MVC project template with scaffolding to get started quickly

For more info:http://www.asp.net/single-page-application

New cool features in MVC 4.0

Last few days I have worked on MVC3 and MVC4 beta. In MVC4 beta some cool features added like:

1.ASP.NET Web API
2.ASP.NET Single Page Application
3.Enhancements to Default Project Templates
4.Mobile Project Template


5.Display Modes

Friday, March 2, 2012

Error: Unable to Validate Data

Recently I have made some changes on my application after upload I have found this error:

Unable to validate data at
System.Web.Configuration.MachineKey.GetDecodedData(Byte[] buf, Byte[] modifier,
Int32 start, Int32 length, Int32& dataLength) at
System.Web.UI.LosFormatter.Deserialize(String input)

But I don't understand why this error was happening. Because I have changed on business logic not any architecture. After doing some r&d got the answer:)


Potential causes:

1.An application pool recycling between the time the viewstate was generated and the time that the user posts it back to the server (unlikely).
2.Modification of viewstate by firewalls/anti-virus software
3.A web farm where the machineKeys are not synchronized (not your issue).
4.Posting from one aspx page to another.

After studying various tutorial I have found that the problem is with the viewstate. The viewstate is actually decrypted in the server using a secret Machine key which resides on the server. The interesting thing is the key gets regenerated after a certain time. Therefore when the user returns the viewstate, if the machine identified key is changed, the decryption of viewstate fails and thus throws this nasty error.

Solution 1:

The solution is simple. First of all, to solve the issue, I disabled the ViewState for the current page by putting EnableViewState = false. I even disabled this for the entire viewstate for the website using Web.config. But still the error.

Finally I used "EnableViewStateMac =false" in pages section.this cause the problem.

<pages buffer="true" enableViewStateMac="flase"/>
</pages>


Just place the following between the system.web section and the site starts working.

Solution 2:

Second solution that we might use as well is to place the machine key directly on our web.config, so that it always decrypts and encrypts using the static key values. To do this, we need to use the following:

<machinekey validationkey="22E995276703B846C4AD0881EE3159FFCB376CD48B27F64
9A074815C83D5C925038938F6943555687582CBC186DB22E552FCDB4D46
124BAADEE85A857CC135BC"
decryptionkey="60588EB661A6483348C20F92659775872CB06427AF20733C"
validation="SHA1"></machinekey>


You can also try to use this site to generate validation key.

Viewstate & Machine config interaction:

When a request for a page in the server. After you place the request the server processes it, encrypts the viewstate that the server receives using the encryption mentioned. Basically it uses the key mentioned in the Machine.config to encrypt the viewstate data. Finally it converts to Base64 and embeds into some hidden fields.

We can mention the machine key in Web.config too so that it uses it for the current website. You might use the AutoGenerate option too to enable/disable autogeneration of key during runtime.
For more information visits.

For further study please visits: MS article

Orchard 1.4 Is released!!

Last day officially announced that the new Orchard release - version 1.4. It's a big step forward from the previous, 1.3.10 version, both in terms of performance and features.

Orchard 1.4 is here! The release is published on our Orchard CodePlex website and Microsoft Web Application Gallery.


What's new?

Orchard 1.4.0 fixes bugs, improves performance and introduces the following features:

Autoroute: Set-up token-based patterns for your URLs. David Hayden has a good post describing the feature: http://www.davidhayden.me/blog/autoroute-custom-patterns-and-route-regeneration-in-orchard-1.4

Projector: Create arbitrary queries on your site contents, then display the results in projection pages and widgets.

Fields: Orchard now comes with new field types for Boolean, Date/Time, Enumeration, HTML5 Input, Links, Media Picker and Numeric. The text field has a new setting for the flavor which adds html, markdown and textarea to the default text box.


Breaking Changes

Orchard 1.4 introduces a breaking change with the Autoroute and Alias features by removing the Route part that was previously handling URLs and titles for content items.

Migrating existing content items can be done with a special module (see next section), but it may also happen that some modules that were relying on the presence of Route may stop working.

We've asked all module developers to review their code with the new version, but there may still be incompatible ones out there. If a module misbehaves, please check whether a new version is available. If there isn't one, please contact its author through the contact form on the Orchard Gallery.

You may also attempt to fix the modules you need: we have a set of instructions on this thread.

Method 'StartWorkflowOnListItem' in type 'Microsoft.SharePoint.WorkflowServices.FabricWorkflowInstanceProvider'

Exception: Method 'StartWorkflowOnListItem' in type 'Microsoft.SharePoint.WorkflowServices.FabricWorkflowInstanceProvider'...