Asp.net mvc 防止用户获取部分内容
角度路线:Asp.net mvc 防止用户获取部分内容,asp.net-mvc,angularjs,asp.net-mvc-routing,Asp.net Mvc,Angularjs,Asp.net Mvc Routing,角度路线: angular.module('AMS', []). config(['$routeProvider', function ($routeProvider) { $routeProvider. when('/dashboard', { templateUrl: '/Dashboard', controller: dashboardController }). when('/settings', { templateUrl: '/
angular.module('AMS', []).
config(['$routeProvider', function ($routeProvider) {
$routeProvider.
when('/dashboard', { templateUrl: '/Dashboard', controller: dashboardController }).
when('/settings', { templateUrl: '/Settings', controller: settingsController }).
otherwise({ redirectTo: '/dashboard' });
}]);
样本:
/* client side route */
http://localhost:4117/#/dashboard
指向
/* controller that returns the partial */
http://localhost:4117/Dashboard
一切正常,但如果我在浏览器中放入相同的url(没有前导的/#/
),部分内容仍将返回,这是不好的
如何防止这种情况发生?您可以将其用作服务器端方法的自定义操作方法Selector属性。例如:
public class AjaxRequestAttribute : ActionMethodSelectorAttribute
{
public override bool IsValidForRequest(ControllerContext controllerContext,
MethodInfo methodInfo)
{
return controllerContext.HttpContext.Request.IsAjaxRequest();
}
}
和使用:
[AjaxRequest]
public JsonResult GetTemplates()
{
...
}
贫民区钻井方式:没有返回视图的索引操作,但这感觉是错误的,即使它有效。此外,它只会防止意外查看,因为任何人都可以直接转到路由配置并查看ASP.NET MVC路由。