locked
Http Extensions Error! RRS feed

  • Question

  • User1421620300 posted

    Is their anyway possible to clear the following error? Markus

    ViewStart.cshtml

    {
    if (Context.Request.Headers["X-Requested-With"] == "XMLHttpRequest")//if ajax request
    {
    Context.Response.Headers["Location"] = Microsoft.AspNet.Http.Extensions.UriHelper.GetDisplayUrl(Context.Request); //RawUrl                
    Context.Response.Headers["Cache-Control"] = "no-store";//context.HttpContext.Response.Cache.SetNoStore(); //stop caching(partial content) on client's browser
    }
    else
    {
    Layout = "_Layout";
    }
    }

    Severity Code Description Project File Line Suppression State
    Error CS1503 Argument 1: cannot convert from 'System.Web.HttpRequestBase' to 'Microsoft.AspNet.Http.HttpRequest' Sports_ C:\Users\Andrew\Documents\Visual Studio 2015\My Projects\Sports_ - Copy - Copy\Sports_\Views\_ViewStart.cshtml 4 Active

    Monday, November 12, 2018 10:00 PM

Answers

  • User1520731567 posted

    Hi Markus33,

    Context.Response.Headers["Location"] = Microsoft.AspNet.Http.Extensions.UriHelper.GetDisplayUrl(Context.Request); //RawUrl     

    Actually,I don't know what you want clearly.

    And this library Microsoft.AspNet.Http.Extensions is old version.

    I suggest you could try to code like:

    Context.Response.Headers["Location"] =  Request.RawUrl; 

    Best Regards.

    Yuki Tao

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, November 13, 2018 4:16 AM
  • User753101303 posted

    Hi,

    Where is your _Layout.cshtrml file ? Usually this is Layout="~/Views/Shared/_Layout.cshtml"; (and the file is in the corresponding folder).

    See https://docs.microsoft.com/en-us/aspnet/mvc/overview/getting-started/introduction/adding-a-view#changing-views-and-layout-pages 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, November 13, 2018 6:56 PM

All replies

  • User1520731567 posted

    Hi Markus33,

    Context.Response.Headers["Location"] = Microsoft.AspNet.Http.Extensions.UriHelper.GetDisplayUrl(Context.Request); //RawUrl     

    Actually,I don't know what you want clearly.

    And this library Microsoft.AspNet.Http.Extensions is old version.

    I suggest you could try to code like:

    Context.Response.Headers["Location"] =  Request.RawUrl; 

    Best Regards.

    Yuki Tao

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, November 13, 2018 4:16 AM
  • User1421620300 posted

    Hello Yuki, i added the code snippet as you directed. And it cleared the erro. But now i get an exception from the _Layout method? I dont quite understand can you help?? Markus.

    {"The layout page \"_Layout\" could not be found at the following path: \"~/Views/_Layout\"."}

    @{if (Context.Request.Headers["X-Requested-With"] == "XMLHttpRequest")//if ajax request
    {
    Context.Response.Headers["Location"] = Request.RawUrl; //RawUrl
    Context.Response.Headers["Cache-Control"] = "no-store";//context.HttpContext.Response.Cache.SetNoStore(); //stop caching(partial content) on client's browser
    }
    else
    {
    Layout = "_Layout";      //program throws exception here.
    }
    }

    Tuesday, November 13, 2018 6:38 PM
  • User753101303 posted

    Hi,

    Where is your _Layout.cshtrml file ? Usually this is Layout="~/Views/Shared/_Layout.cshtml"; (and the file is in the corresponding folder).

    See https://docs.microsoft.com/en-us/aspnet/mvc/overview/getting-started/introduction/adding-a-view#changing-views-and-layout-pages 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, November 13, 2018 6:56 PM