Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

An error occurred while processing your request. MVC 4

I'm creating a MVC 4 application, I had error like following.

enter image description here

I tried lot of things but I can't find what is the problem.here is my Controller source

    public ActionResult Index(string EventId)
    {

        HttpCookie cookie = this.ControllerContext.HttpContext.Request.Cookies["User"];

        if (cookie != null)
        {
            string Type = (cookie["Type"] == null || cookie["Type"] == "") ? null : cookie["Type"].ToString();
            string Username = (cookie["Username"] == null || cookie["Username"] == "") ? null : cookie["Username"].ToString();
            ViewBag.Message = Type;
            ViewBag.Username = Username;


            try
            {
                string ReplaceEventID = EventId.Replace('-', '/');

                ViewBag.Message = ReplaceEventID;
                IEnumerable<Job> JobListRelatedToEvent = DBContext.Jobs.Where(x => x.EventId == ReplaceEventID);
                return View(JobListRelatedToEvent);
            }
            catch
            {
                return View();
            }
        }
        else
        {
            return RedirectToAction("Index", "Home");
        }
    }

UPDATE: When it run on my local machine it works fine, but after i published to the server I got this error.

Can anyone tell about what's the wrong?

like image 299
Harshana Narangoda Avatar asked Jun 19 '14 07:06

Harshana Narangoda


1 Answers

I am facing the same issue and this issue we are getting if the custom error is on.

What you need to do the changes in web.config and add the below code. So, you will get the actual error of the application or in code level.

<system.web>
      <customErrors mode="Off" />

Now insted of generic page of IIS it will shows the error.

like image 164
satya Avatar answered Oct 31 '22 20:10

satya