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)?
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With