0

this is what I'm doing: 1: Custom Authorization which loads Home/NoAccess 2: the NoAccess method will redirect to the page the user came from.

What I want added to this, is that when the user goes through the NoAccess controller something is placed in the viewbag or w.e.. that I can use to show a small messagebox saying something like "You've got no access".

The problem I am having is that when I put something in my ViewBag it doesn't reach the View. Is there an easy way to redirect the user to his previous page when he doesn't pass authorization and show a alert popup?

1 Answer 1

4

The ViewBag contents is lost in the redirect.

Use TempData instead. The contents are stored until it's read.

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

2 Comments

I didn't really want to use anything with Sessions... even if it has another name. Isn't their a more cleaner way to do this? I did get it to work wit TempData by the way.
@user1682627: Although its underlying implementation is Session, why are you reluctant to use TempData? This is the perfect use case for it. The payload is small and very short-lived.

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.