1 Replies - 465 Views - Last Post: 01 June 2013 - 01:52 PM Rate Topic: -----

#1 intentarr  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 16-September 11

How to handle httpException in asp.net mvc application?

Posted 01 June 2013 - 10:17 AM

Hello,

I am writing my first asp.net mvc application. In my application I am using session variables and when I am checking if session variable exists (if it not exist) I would like for the user to show my error page. The problem is that I checking session variables not only in ActionResult methods (in ActionResult type methods I can simply redirect page to my error page) but also in void/string type methods. I can't see the right way how to handle this and how I should be able always to show for the user my own error page. Any ideas ?

Is This A Good Question/Topic? 0
  • +

Replies To: How to handle httpException in asp.net mvc application?

#2 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3453
  • View blog
  • Posts: 10,659
  • Joined: 05-May 12

Re: How to handle httpException in asp.net mvc application?

Posted 01 June 2013 - 01:52 PM

The correct way: Check for all the session variable you need in the controller's entry point. Do not check for session variables in other methods. If other methods need the session variables, pass the value from the controller to the helper methods.

The expedient way: Have your own custom exception that you throw when you are missing a session variable. In your controller entry point, have a try-catch which catches your custom exception and redirects to your error page.

I urge you to follow the correct way, rather than the expedient way.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1