This is a migrated thread and some comments may be shown as answers.

remote webapi and authentication for MVC wrappers

1 Answer 121 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Jelly Master
Top achievements
Rank 1
Jelly Master asked on 31 Mar 2014, 11:39 AM
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%;" })

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 01 Apr 2014, 08:47 AM
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.

 
Tags
General Discussions
Asked by
Jelly Master
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or