6

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?

6
  • 1
    I don't have much experience with MVC, but aren't you redirecting to the same Action, thus getting in a loop?
    – nphx
    Jun 19, 2014 at 7:21
  • 1
    Have you tried to debug your action method? If not debug it and if you are getting any exception, post it here. Jun 19, 2014 at 7:26
  • 1
    I forgot to mention something I'll update. Jun 19, 2014 at 7:28
  • 2
    in my local machine it works fine, but after i published to the server then this error occurred. Jun 19, 2014 at 7:30
  • 1
    I suggest you retrieve and paste server event log here. There is no clue whats going wrong
    – qamar
    Jun 19, 2014 at 9:22

3 Answers 3

23

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.

1
  • This was really helpful to see the actual error on the server.
    – sgtcadet
    May 5 at 21:16
0

I don't know if it will help you, but I ran into an issue where the POST action had [RequireHttps], but the GET didn't. That caused the issue for me. So, check you don't have restrictions on one verb and not the other, especially with a form post.

The issue didn't show until I published to Production because DEBUG directives removed the [RequireHttps] attribute :)

-4

TRY THIS :

 public ActionResult Job(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");
            }
  }
2
  • 2
    Why? State what the problem is when posting an answer don't just post a block of code. Also, the only difference I can see is you have added a return View(); statement at a point where the code is unreachable. Jun 19, 2014 at 9:14
  • Please explain what your answer is doing.
    – Vikas
    Dec 9, 2016 at 14:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.