asp.net mvc - prevent users from getting partials -


angular route:

angular.module('ams', []).   config(['$routeprovider', function ($routeprovider) {       $routeprovider.           when('/dashboard', { templateurl: '/dashboard', controller: dashboardcontroller }).           when('/settings', { templateurl: '/settings', controller: settingscontroller }).           otherwise({ redirectto: '/dashboard' });   }]); 

sample:

/* client side route */ http://localhost:4117/#/dashboard 

points

/* controller returns partial */ http://localhost:4117/dashboard 

everything works expected, if put same url in browser (without leading /#/), partial still returned, not good.

how prevent happening?

you can use custom actionmethodselectorattribute server-side method. example:

public class ajaxrequestattribute : actionmethodselectorattribute {     public override bool isvalidforrequest(controllercontext controllercontext,                                            methodinfo methodinfo)     {         return controllercontext.httpcontext.request.isajaxrequest();     } } 

and use:

[ajaxrequest] public jsonresult gettemplates() { ... } 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -