views:

47

answers:

4

Hi,

hope i can explain myself... i have a login control in the masterpage. when you click the login button you go to the accountcontroller's logon method which checks your credentials. whether it is ok or not, you will be redirected to the homepage with a redirecttoaction("home","index"). but, in case login failed, i want to show a message to the user. so what i tried was setting viewdata in the logon method (viewdata["logon"] = "failed") and then check in the masterpage if this viewdata was present and if so, render a span with some text. but as i understand the viewdata is not preserved with the redirect to action method.

what is the best way to make sure my logon method can somehow notify my masterpage view that login failed?

Michel

+1  A: 

Check out MvcContrib. Queen3 somewhere mentioned that they have cure for this
(passing information between redirects).

But it would be better to create separate view for authentication. Then problem would just disappear.

Arnis L.
hmm, nice though. maybe an ajax form, then i have no postback AND a separate view.
Michel
AJAX for authentication form ain't good idea either.
Arnis L.
hmm, makes sense, think i'll do a redirecttoaction on succes, and a return view("") on fail. in the latter case the viewdata will be preserved
Michel
+1  A: 

Hello,

See this project to send FlashMessages in your application http://maff.ailoo.net/2009/06/build-a-flashmessenger-system-in-aspnet-mvc/

I guess that can help you!

[]´s

Juliano Oliveira
Thanks, but this also uses sessionstate (i didn't say that, but i'm not 'allowed' to use sessionstate)
Michel
+2  A: 

If I read your question correctly your problem is that you need to set a value in your action that need to be available after RedirectToAction. You would need to set a key in Tempdata.

TempData["MessageToUser"] = "I dont let you in dude!"

TempData is still available after one redirect.

Malcolm Frexner
yep, that is correct. But tempdata is stored in session, isn't it?the rest of the app works without sessionstate, and i don't think i'm allowed to introduce sessionstate for this one...
Michel
Yes you are right about that.
Malcolm Frexner
+1  A: 

Read too about TempData

See: http://www.persistall.com/archive/2007/12/22/asp.net-mvc-a-ha-moment-tempdata--flash.aspx

[]´s

Juliano Oliveira