asp.net mvc - How Data is posted (POST) to Service in Servicestack , is it through URL? -


i have complex requstdto composed of other list of dto's (entity framework entities)

[route("/demoservice/{username}/{employerid}/{report}/{selecteddatalist}/", "post")]         public class reportdemo : ireturn<string>         {             public string username { get; set; }             public int employerid { get; set; }             public userreport report { get; set; }             public list<selectedidlist> selecteddatalist{ get; set; }                      }  

where userreport follows

public class userreport           {             public string username { get; set; }             public datetime createdon{ get; set; }                                 }  

when try post request gives me following error

a potentially dangerous request.path value detected client (:)

i think gives error due : in createdon field ( time part).

is post values sent through url servicestack url ? if yes

1) if have large , complex requestdto resulting large number of characters (greater allowed )in url?

2) how make above scenario work ":" reserved , cant sent through url?

3) how see request url generated client ?

my client code in mvc.net

var client = new jsonserviceclient(configurationmanager.appsettings["applicationurl"])                 {                     //for windows authentication                     credentials = credentialcache.defaultcredentials                        };   var result = client.post (new reportdemo                   {                      username = userreportviewmodel.username,                      employerid = userreportviewmodel.employerid,                      report = userreportviewmodel.report,                      selecteddatalist =userreportviewmodel.selecteddatalist                    }); 

thanks in advance, amol

only /path/info of url should specified in [route]. ideally routes should use human-readable logically-structured url refers "resource" (noun). see sevicestack rest events example different examples.

routes should never include complex types , variable isn't on [route] automatically sent in http request body post requests or querystring get requests.

for user report choose url identifies report, if report has name "demo report" use path info like:

[route("/reports/demo")]  public class reportdemo : ireturn<string> { ... } 

otherwise if report users may instead want use like:

[route("/users/{username}/reports/demo")]  public class reportdemo : ireturn<string> { ... } 

you can check url used using reverse routing extension methods, e.g:

var request = reportdemo { username = "foo", ... };  request.toposturl().print(); //= /users/foo/reports/demo 

now can send request property not in route getting post'ed above url, e.g:

string result = client.post (new reportdemo {      username = userreportviewmodel.username,      employerid = userreportviewmodel.employerid,      report = userreportviewmodel.report,      selecteddatalist =userreportviewmodel.selecteddatalist   }); 

if report return string can use ireturn<string> if returns response dto you'll want use instead, e.g ireturn<reportdemoresponse>.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -