5

I have a custom HttpModule for authentication. In the AuthenticateRequest event handler of the module I check if a custom SSO ticket is available and in that case perform some authentication logic.

If the SSO ticket is available, but incorrect, I would like to show a friendly error message to the user. I would prefer to be able to somehow set HTTP Status 401 (Unauthorized, used when authentication fails) and pass on a meaningful error message from the http module.

I would then like the MVC application to somehow get this information and use it to render a custom 401 error page which includes the meaningful error message from the module.

What's the best way to raise the error in the http module and what's the best way to have it display the error using the MVC application (to get the error message in the MVC application's layout)?

1
  • This is a good question and I am also interested in the best approach for handling errors outside of the MVC Framework/Request Pipeline when the goal is to return an error view that is part of MVC. Commented Aug 19, 2013 at 18:29

1 Answer 1

1

You could create a custom controllerfactory, and in your:

protected override IController GetControllerInstance(RequestContext context, Type controllerType)

You will have access to the HttpContext and RouteData through your context object. If user is not authenticated you can manipulate your routedata to targed your desired controller/action with desired routeconstraints/parameters (for instance a http status message)

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

Comments

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.