Unity with ASP.NET

I am using ASP.NET 3.5 SP1 with MVC 1.

Is it possible to use IUnity to retain ViewModel between RedirectToAction() so that I don't have to use TempData to forward the the ViewModel from one action to another. If someone can give me very basic example to accoplish this I will very greateful to you.

Note: I've just one controller and one View but different action. Based upon the actions, I have to display the same View with different updated ViewModel.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

When you say IUnity do you mean unity dependancy injection?

Can you give a more concrete example of what you are actually doing?


tech1guyAuthor Commented:
Yes, I'm talking of unity dependancy injection. "Microsoft.Practices.Unity.dll". My problem is the following:

* I have a OrderView with form tag. I also have a Controller with one Action which is accepting user's input from the form. Based upon the user input I need to call some web-services and then re-display the same View but with the updated ViewModel. I cannot use PartialView as my whole View will be updated.

I tried to call the web-services and then update the ViewModel and used "return View("OrderView", updatedOrderViewModel);" to re-display the FULL updated View. While doing so I learnt that I have to use RedirectToAction() method in order to display the updated View. But I have to use TempData so that my updatedViewModel can be passed to another action. But as my data is sensitive, I do not want to use TempData.

Therefore, I am thinking that if I use Unity, then I can do good without TempData and also use RedirectToAction().

I've opened number of other questions, but still I've NOT got the response.


Whenever you perform a sucessful http POST you should always redirect to a GET - PRG pattern - http://en.wikipedia.org/wiki/Post/Redirect/Get

I'm not sure I understand why you can't use TempData - the default TempData provider stores the data for one round trip in the server session. Therefore in this configuration your data never leaves the server and never gets transferred to the client. If you are concerned with something on the server getting access to your data then possibly you should encrypt the data while it's in the TempData store - however I'd think in most cases that would be over kill as there will probably be many other hooks in your application which possibly need attention before this.

Therefore something like

public ActionResult UpdateModel(........)
  // Code to update the model

  TempDate["MyTempDataKey"] = model;
  return RedirectToAction("ViewUpdatedModel");

public ActionResult ViewUpdatedModel()
  var model = TempData["MyTempDataKey"];
  return View("MyView",model);

I'm not sure specifically how Unit will help you - apart from being able to inject a service into your controller which could handle storage of the model data in a local database. But it may be simpler to implement your own TempData provider and use that.
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

tech1guyAuthor Commented:
my concern using TempData is:
First: It is sensitive data and our business unit don't like the idea.
Second: I am concerned about the performance on server as everyone will use TempData on the website. Is it worth to look at the performance or not?

I'm sorry as I am asking a lot, but could you please post a way to encrypt and decrypt tempdata and also comment on the performance.
You certainly need to consider performance - by default session data is stored in the web server's memory so if you've got a lot of users and the data you are storing is quite large then you are likely to consume most of the server's memory. If this is the case then I'd suggest using SQL server to store your session data - this will add an overhead to each request, but it will mean that your application will scale.

In terms of encyrpyting data have a look at articles on encryption - it's a big subject


I'd still suggest that you concentrate on the security of your whole applicartion. A good blog to look at is Barry Dorrans


and the top 10 website vunerabilities are detailed here


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tech1guyAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Frameworks

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.