0

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

2

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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...
1

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.

2 Comments

hmm, nice though. maybe an ajax form, then i have no postback AND a separate view.
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.