locked
Getting error "Hmmm...can’t reach this page Try this Make sure you’ve got the right web address: https://localhost:5001" RRS feed

  • Question

  • User756776635 posted

    Hello everyone!

    My first post. Was thrown in the ring to write a razor app...

    The app implements the PRG pattern whereby a search page is presented, the user enters a criteria, hits the search button and the result of the search is presented at the bottom of the same page. The items listed in the results table have a link that open a detail page, which has a "back" link to the first page. All that was working...I made some changes along the way and now when I run the app for the first time, it comes up. I enter the search criteria, hit the submit button and the page fails with 

    "Hmmm...can’t reach this page

    Try this <id id="dnserror_unavailable_righturl">Make sure you’ve got the right web address: </id> https://localhost:5001..."

    Below is a simplified version of the code in the page model.

    [TempData]
     public string FileSearchCriteriaAuto { get; set; }
    //...more code here
    public void OnGet()
            {
                if (!String.IsNullOrEmpty(FileSearchCriteriaAuto))
                {
                    FileSearchCriteria = JsonConvert.DeserializeObject<SearchCriteria>(FileSearchCriteriaAuto);
    
                    HasSearch = FileSearchCriteria.FileName.Length > 0 || FileSearchCriteria.Criteria.Exists(c => c.Trim().Length  > 0);
    
                    ContentSearchCriteria = new List<string>();
                    ContentSearchCriteria.AddRange(FileSearchCriteria.Criteria);
    
                    if (!(TempData == null))
                    {
                        FileSearchCriteriaAuto = JsonConvert.SerializeObject(FileSearchCriteria);
                        TempData["FileSearchCriteriaManual"] = FileSearchCriteriaAuto;
    
                        if (TempData.ContainsKey("MatchedFilesJson"))
                        {
                            MatchedFiles = JsonConvert.DeserializeObject<List<FileProcessed>>(TempData["MatchedFilesJson"].ToString());
                            TempData.Keep();
                        }
                    }
                    FileName = FileSearchCriteria.FileName;
                }
                else
                {
                    FileSearchCriteria = new SearchCriteria(string.Empty, 3);
                }
    
            }
    
            public async Task<IActionResult> OnPostAsync()
            {
                FileName = Request.Form["fname"].ToString().Trim();
                var elements = Request.Form.Where(e => e.Key.Contains("criteria")).ToList();
                ContentSearchCriteria = new List<string>();
                foreach (var ele in elements)
                {
                    ContentSearchCriteria.Add(ele.Value.ToString().Trim());
                }
                FileSearchCriteria = new SearchCriteria(FileName, ContentSearchCriteria.ToList());
    
                string criteria = JsonConvert.SerializeObject(FileSearchCriteria);
    
                await LoadFilesAsync(FileName);
    
                MatchedFilesJson = JsonConvert.SerializeObject(MatchedFiles);
                TempData["MatchedFilesJson"] = MatchedFilesJson;
    
                return RedirectToPage("/Index");
            }

    NB: I have tried passing a parameter to the OnGet method, from a property decorated with the

    [BindProperty(SupportsGet = true)]
    

    . Then the browser cannot render the page, as if the link is broken. 

    Does anyone know why the page won't open? Thank you in advance!

    Tuesday, May 26, 2020 4:50 PM

All replies

  • User-474980206 posted

    you don't show the code, but most likely you are binding get to a value type (non-nullable) that is required by default. so the url requires the parameter. make it a nullable type if you want it optional.

     

    Tuesday, May 26, 2020 5:07 PM
  • User756776635 posted

    Hi Bruce. Thank you for taking the time to answer. I have posted my code. I can see it. If you can't please let me know how to make it visible to you. In the meantime I am pasting it raw below. Not sure where exactly to make the parameter optional; I tried @ page "{fileSearchCriteriaAuto?} and it did not make a difference.

    ***Unformatted code

    [TempData]
    public string FileSearchCriteriaAuto { get; set; }

    public void OnGet()
    {
    if (!String.IsNullOrEmpty(FileSearchCriteriaAuto))
    {
    FileSearchCriteria = JsonConvert.DeserializeObject<SearchCriteria>(FileSearchCriteriaAuto);

    HasSearch = FileSearchCriteria.FileName.Length > 0 || FileSearchCriteria.Criteria.Exists(c => c.Trim().Length > 0);

    ContentSearchCriteria = new List<string>();
    ContentSearchCriteria.AddRange(FileSearchCriteria.Criteria);

    if (!(TempData == null))
    {
    FileSearchCriteriaAuto = JsonConvert.SerializeObject(FileSearchCriteria);
    TempData["FileSearchCriteriaManual"] = FileSearchCriteriaAuto;

    if (TempData.ContainsKey("MatchedFilesJson"))
    {
    MatchedFiles = JsonConvert.DeserializeObject<List<FileProcessed>>(TempData["MatchedFilesJson"].ToString());
    TempData.Keep();
    }
    }
    FileName = FileSearchCriteria.FileName;
    }
    else
    {
    FileSearchCriteria = new SearchCriteria(string.Empty, 3);
    }

    }

    public async Task<IActionResult> OnPostAsync()
    {
    FileName = Request.Form["fname"].ToString().Trim();
    var elements = Request.Form.Where(e => e.Key.Contains("criteria")).ToList();
    ContentSearchCriteria = new List<string>();
    foreach (var ele in elements)
    {
    ContentSearchCriteria.Add(ele.Value.ToString().Trim());
    }
    FileSearchCriteria = new SearchCriteria(FileName, ContentSearchCriteria.ToList());

    string criteria = JsonConvert.SerializeObject(FileSearchCriteria);

    await LoadFilesAsync(FileName);

    MatchedFilesJson = JsonConvert.SerializeObject(MatchedFiles);
    TempData["MatchedFilesJson"] = MatchedFilesJson;

    return RedirectToPage("/Index");
    }

    Tuesday, May 26, 2020 5:50 PM
  • User1120430333 posted

    Try this Make sure you’ve got the right web address: https://localhost:5001..."

    Maybe, https is not being used. Maybe nothing is listening on TCP port 5001. Maybe the url is wrong.

    Tuesday, May 26, 2020 6:09 PM
  • User-474980206 posted

    but there is no:

    [BindProperty(SupportsGet = true)]

    in the sample code. the line you say breaks your code. 

    Tuesday, May 26, 2020 7:13 PM
  • User711641945 posted

    Hi TheBugSlayer,

    I could not reproduce your issue.Could you share the razor view?And share more detailed code that could reproduce your issue.

    Best Regards,

    Rena

    Wednesday, May 27, 2020 9:26 AM