remote webapi and authentication for MVC wrappers

2 posts, 0 answers
  1. Jelly Master
    Jelly Master avatar
    39 posts
    Member since:
    Oct 2010

    Posted 31 Mar 2014 Link to this post

    Hi there,

    I am just getting to grips with WebApi and how to use them with the MVC wrappers. But I am at a loss on how to ensure that the authentication is working correctly as part of the project.

    My scenario is I have front end website (www.myfrontendwebsite.com) which is running on one server and then I have the service website with all my Business logic running on a webapi back end website (www.mywebapiwebsite.com) this may/ may not be running on a separate website.

    I am forcing my users to log in to ensure that they can access only the parts of the sites they should have.

    Obviously with the web api project this needs to be protected as well so I need the user to be authenticated.

    Now I am  trying to do something like this with a combobox:


    Html.Kendo().ComboBox()
    .Name("DateSetup")
    .Suggest(true)
    .Filter(FilterType.Contains)
    .DataSource(data =>
    {
    data.Read(read => read.Url("http://localhost:59236/api/GenericReport/GetDateFilterTypes"));
    })
    .Placeholder("Select date setup")


    so I know I need to add some additional information to the header that is being provided but how can I do that from the read.Url method? Do I do this via adding .Data afterwards or is there another way of do it.

    I have already enabled CORS to work as this works when I an using allow annoynomous.

    Thanks in advance.


                          .HtmlAttributes(new { style = "min-width:100%;" })

  2. Daniel
    Admin
    Daniel avatar
    2117 posts

    Posted 01 Apr 2014 Link to this post

    Hello,

    I posted my reply in the support ticket on the same topic. For convenience, I am pasting it below:

    Adding headers to the request is not supported with the default builder but can be achieved by using the Custom builder that was introduced in the latest release. For example:
    • setting additional headers with the Ajax request headers option:
      .DataSource(source => source
          .Custom()
          .Transport(transport => transport
                  .Read(new
                  {
                      url ="http://localhost:59236/api/GenericReport/GetDateFilterTypes",
                      headers = new
                      {
                          key = "value"
                      }
                  })
          )
      )
    • setting additional headers in the request beforeSend callback:
      .DataSource(source => source
          .Custom()
          .Transport(transport => transport
                  .Read(new
                  {
                      url ="http://localhost:59236/api/GenericReport/GetDateFilterTypes",
                      beforeSend = new Kendo.Mvc.ClientHandlerDescriptor()
                      {
                           HandlerName = "onBeforeSend"
                      }
                  })
          )
      )
      function onBeforeSend(e) {
          e.setRequestHeader("key""value");
      }



    Regards,
    Daniel
    Telerik
     

    Build cross-platform mobile apps using Visual Studio and .NET. Register for the online webinar on 03/27/2014, 11:00AM US ET.. Seats are limited.

     
  3. UI for ASP.NET MVC is VS 2017 Ready
Back to Top