i using asp.net 4.5 , have following controller.
public class accountcontroller : controller { // // post: /account/jsonlogin [system.web.mvc.allowanonymous] [system.web.mvc.httppost] public jsonresult login(logindto loginrequest) { if ( loginrequest.email == null ) throw new httpresponseexception(new httpresponsemessage(httpstatuscode.unauthorized)); return null; } }
here dto
public class logindto { public string email { get; set; } public string password { get; set; } public boolean rememberme { get; set; } }
based on fiddler being posted service
post host/account/login http/1.1 host: host connection: keep-alive content-length: 71 accept: application/json, text/javascript, */*; q=0.01 origin: clientdifferentthanhost user-agent: mozilla/5.0 (windows nt 6.1; wow64) applewebkit/537.36 (khtml, gecko) chrome/27.0.1453.116 safari/537.36 content-type: application/x-www-form-urlencoded; charset=utf-8 referer:clientdifferentthanhost/? accept-encoding: gzip,deflate,sdch accept-language: en-us,en;q=0.8 {"email":"keith@kssoftware.net","password":"afasdf","rememberme":false}
i expect asp.net convert json c# object instead data in loginrequest null (except boolean has default value of false)
here javascript using
this.login = function () { var dto = json.stringify({email:"test@test.com",password:"avafa",rememberme:false}); $.ajax({ url: app.homeurl + "account/login", data: dto, success: self.loginsuccess, processdata: false, type: "post", datatype: "json", traditional: true }).fail(self.loginfail) ; };
when try set contenttype: "application/json; charset=utf-8" request never makes service. assume bug in thinktecture.idenitymodel cross-origin package i'm using try figure out once can work. appreciated. have gotten work in past , i'm sure need second set of eyes help.
using fiddler i've been able pass following
content-type: application/json; charset=utf-8 referer: http://localhost:8900/ accept-encoding: gzip,deflate,sdch accept-language: en-us,en;q=0.8 {"loginrequest":[{"email":"test@test.com","password":"avafa","rememberme":false}]}
still no values processed correctly
looks issue contenttype has = "application/json; charset=utf-8" moved service same origin , changed contenttype , worked expected.
will investigate why contenttype change causing issues thinktecture
Comments
Post a Comment