title: C# mvc4 - direct URL to controller
body: <p>I have an external URL that points directly to a function in my controller but when I click on it for the first time, instead of reaching the page, I get to the home page. However, on the second click (and the following ones), I can reach the desired page.</p>
  
  <p>Is there something I should add to my function or controller to allow to have it reached on the first click? Or would it be my sessions that aren't initialized on the first time? I tried debugging, but I never reached the desired function on the first click.</p>
  
  <p>Here is my external URL pointing to my controller:
  <a href="http://localhost/careers/postings/index?pvnID=HC-1505-000533" rel="nofollow">http://localhost/careers/postings/index?pvnID=HC-1505-000533</a></p>
  
  <p>and here is the method from the controller:</p>
  
  <pre><code>public ActionResult Index(string pvnID)
      {
  
          //if pvnid matches legacy PVN application pater -&gt; refirect to legacy application
          Regex pattern = new Regex("[A-Z]{3}-\\d{3,4}");
          Match match = pattern.Match(pvnID);
          if (match.Success)
          {
           //redirect to legacy application
          }
          else 
          {
              model.Job = jobPostingMgr.GetJobPosting(pvnID);
  
              string maxSalary = "";
              string minSalary = "";
  
              if(model.Job.MaximumSalary.ToString() != "0.00"){
                  maxSalary = String.Format("{0:C}", model.Job.MaximumSalary);
              }
              if (model.Job.MinimumSalary.ToString() != "0.00")
              {
                  minSalary = String.Format("{0:C}", model.Job.MinimumSalary);
              }
  
              if (maxSalary != "" &amp;&amp; minSalary != "")
              {
                  ViewBag.SalaryRange = minSalary + " - " + maxSalary;
              }
              else if (maxSalary == "" &amp;&amp; minSalary != "")
              {
                  ViewBag.SalaryRange = minSalary;
              }
              else if (maxSalary != "" &amp;&amp; minSalary == "")
              {
                  ViewBag.SalaryRange = maxSalary;
              }
  
  
              //data processing
              Session["category"] = model.Job.Category;
              model.Job.Category = miscInfoMgr.GetAJobCategory(model.Job.Category).Description;
              model.Job.CollegeCode = PvnHelper.GetCollege(model.Job.CollegeCode).Description;
              Session["pvnid"] = pvnID;
  
  
              //Change to lower case 
              model.Job.DisplayJobTitle = System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(model.Job.DisplayJobTitle.ToLower());
              model.Job.Department = System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(model.Job.Department.ToLower());
              model.Job.CollegeCode = System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(model.Job.CollegeCode.ToLower());
          }
          return View(model);
      }
  </code></pre>
  
  <p>Thanks a lot in advance for your help.</p>