我从角度调用REST服务,它总是调用工厂两次.这是工厂代码.
app.factory('dataFactory', ['$http', function ($http) {
var urlBase = '/api';
var dataFactory = {};
dataFactory.getMyItems = function () {
return $http.get(urlBase + '/MyItems');
};
return dataFactory;
} ]);
Run Code Online (Sandbox Code Playgroud)
这是从控制器调用的
app.controller('MyItemsController', ['$scope', 'dataFactory',
function ($scope, dataFactory) {
$scope.myItems;
getItems();
function getItems() {
dataFactory.getMyItems()
.success(function (itemsData) {
$scope.myItems = itemsData;
})
.error(function (error) {
$scope.status = 'Unable to load items data: ' + error.message;
});
}
}
]);
Run Code Online (Sandbox Code Playgroud) 在我的 Angular 应用程序上运行 jasmine 测试时出现此错误。
Error: StaticInjectorError(DynamicTestModule)[MyEditDialogComponent -> InjectionToken MatDialogData]:
StaticInjectorError(Platform: core)[MyEditDialogComponent -> InjectionToken MatDialogData]:
NullInjectorError: No provider for InjectionToken MatDialogData!
error properties: Object({ ngTempTokenPath: null, ngTokenPath: [ 'MyEditDialogComponent', InjectionToken MatDialogData ], ngDebugContext: DebugContext_({ view: Object({ def: Object({ factory: Function, nodeFlags: 33669121, rootNodeFlags: 33554433, nodeMatchedQueries: 0, flags: 0, nodes: [ Object({ nodeIndex: 0, parent: null, renderParent: null, bindingIndex: 0, outputIndex: 0, checkIndex: 0, flags: 33554433, childFlags: 114688, directChildFlags: 114688, childMatchedQueries: 0, matchedQueries: Object({ }), matchedQueryIds: 0, references: Object({ }), ngContentIndex: …Run Code Online (Sandbox Code Playgroud) 我[Authorize]在我的WebAPI控制器操作上使用该属性,它总是未经授权返回.
这是我的行动
[Authorize(Roles = "Admin")]
public IQueryable<Country> GetCountries()
{
return db.Countries;
}
Run Code Online (Sandbox Code Playgroud)
这是我在全局MessageHandler中设置授权的地方.这是为了测试我正在测试用户.
public class AuthenticationHandler1 : DelegatingHandler
{
protected override Task<HttpResponseMessage> SendAsync(
HttpRequestMessage request, CancellationToken cancellationToken)
{
if (!HttpContext.Current.User.Identity.IsAuthenticated)
{
HttpContext.Current.User = TestClaimsPrincipal();
}
return base.SendAsync(request, cancellationToken);
}
private ClaimsPrincipal TestClaimsPrincipal()
{
var identity = new ClaimsIdentity(HttpContext.Current.User.Identity.AuthenticationType);
identity.AddClaim(new Claim(ClaimTypes.Name, "some.user"));
identity.AddClaim(new Claim(ClaimTypes.Role, "Admin"));
identity.AddClaim(new Claim(ClaimTypes.Role, "Supervisor"));
var testIdentity = new ClaimsIdentity(identity);
var myPrincipal = new ClaimsPrincipal(testIdentity);
return myPrincipal;
}
}
Run Code Online (Sandbox Code Playgroud)
注册Global.asax.cs于Application_Start
GlobalConfiguration.Configuration.MessageHandlers.Add(new MyProject.AuthenticationHandler1());
Run Code Online (Sandbox Code Playgroud)
它一直显示这个消息 …
通常在更改了运行的ASP.NET MVC Azure Web服务应用程序上的web.config之后,我总是收到此错误。它将第一次运行良好,但是在更改web.config之后重新编译后,通常会出现这种情况。我认为有时是通过启动和停止Web应用程序来实现的。使它消失的唯一方法是再次将应用程序从Visual Studio发布到Azure。
Method not found: 'Microsoft.Practices.Unity.IUnityContainer MyProject.Core.ContainerManager.GetConfiguredContainer()'.
The pre-application start initialization method Run on type WebActivatorEx.ActivationManager threw an exception with the following error message: Exception has been thrown by the target of an invocation
Source File: D:\MyProject-master\src\MyProject.Web\App_Start\UnityMvcActivator.cs Line: 73
Run Code Online (Sandbox Code Playgroud)
堆栈跟踪
MissingMethodException: Method not found:
'Microsoft.Practices.Unity.IUnityContainer
MyProject.Core.ContainerManager.GetConfiguredContainer()'.]
MyProject.Web.App_Start.UnityWebActivator.Start() in D:\MyProject-master\src\MyProject.Web\App_Start\UnityMvcActivator.cs:73
[TargetInvocationException: Exception has been thrown by the target of an invocation.]
System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) +0
System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) +87
System.Reflection.RuntimeMethodInfo.Invoke(Object …Run Code Online (Sandbox Code Playgroud) c# asp.net-mvc unity-container visual-studio azure-web-sites
我有一个Amazon Web Services帐户,用于托管应用程序的支持.后端使用PHP/MySQL并且很可能使用EC2实例和RDS.我有自己的帐户,可以访问所有内容.我需要为开发人员创建一个帐户,将后端放在AWS上,但我不希望他们能够访问除了他们需要的任何东西.我知道如何创建IAM用户和组,但我不知道授予开发人员的权限.在Select Policy Template有一个Power User模板,是很好的一个开发者?有没有人这样做过?
我已经使用Visual Studio在线团队服务作为代码存储库,并想知道Microsoft员工是否可以查看您上传的代码.
该隐私政策并没有解决这个具体,我可以看到,但它确实说,微软可以使用您的数据用于广告目的,他们可以与第三方共享.如果"数据"意味着我的专有代码,那将是很好的知识.
客户数据仅用于向客户提供在线服务,包括与提供这些服务兼容的目的.例如,我们可能会使用客户数据来提供个性化体验,提高服务可靠性,打击垃圾邮件或其他恶意软件,或改进在线服务的功能.Microsoft不会出于任何广告或类似的商业目的使用客户数据或从中获取信息."客户数据"是指由您或您的最终用户通过使用在线服务提供给Microsoft的所有数据,包括所有文本,声音,视频或图像文件以及软件.客户数据不是管理员数据,付款数据或支持数据.有关使您能够控制客户数据的特性和功能的更多信息,请查看特定于在线服务的文档.
我如何获得此查询以获取过去 12 个月的每月计数数据?我不想对范围进行硬编码,我想使用当前日期DateTime.Now并从中获取过去 12 个月的所有数据。我试图避免将日历表添加到数据库中,而仅使用LINQ.
有些月份可能没有任何数据,但我仍然需要0对这些数据进行计数。
例如。如果我的数据包含
Date Count
12/2/2013, 4
10/1/2014, 1
11/5/2014, 6
Run Code Online (Sandbox Code Playgroud)
结果应该是,使用当前日期 11/9/2014
11/2013, 0
12/1013, 4
1/2014, 0
2/2014, 0
3/2014, 0
4/2014, 0
5/2014, 0
6/2014, 0
7/2014, 0
8/2014, 0
9/2014, 0
10/2014, 1
11/2014, 6
Run Code Online (Sandbox Code Playgroud)
我无法让它工作。我认为这就是我的使用方式,Range但我不确定。
TimeSpan ts = new TimeSpan(365, 0, 0, 0);
DateTime yearAgo = DateTime.Now.Subtract(ts);
var changesPerYearAndMonth =
from year in Enumerable.Range(yearAgo.Year, 1)
from month in Enumerable.Range(1, 12)
let key = …Run Code Online (Sandbox Code Playgroud) 我每隔几秒钟就会尝试用服务器上的数据刷新我的表.它正在加载新数据,但分页根本不起作用.我的意思是,这是一个很重要的数据列表.它也说Showing 0 to 0 of 0 entries (filtered from NaN total entries)桌子底部的分页.
我在一个函数中使用draw(false)setInterval来实现刷新.我想在不使用的情况下这样做,"serverSide":"true"但我发现除非我使用该选项,否则draw()不会调用ajaxurl serverSide.
function myFunction() {
var table1 = $("#example1").dataTable({
"ajax": '/api/GetData',
"serverSide": "true",
"columns": [
{
"data": "DateCreated",
},
{ "data": "UserName" }
],
"destroy": true
});
setInterval(function test() {
table1.draw(false);
}, 3000);
}
Run Code Online (Sandbox Code Playgroud)
当我省略"serverSide":"true"该表时,使用分页正确绘制,但不调用ajax draw().如何获取ajax数据并正确设置分页?
从ApiController,我正在生成一个通过电子邮件发送给用户的密码重置链接.一切正常,但Url.Route函数不会生成与主机名的链接.我不确定是不是因为我正在使用localhost它导致问题.
这是生成链接的代码
string callbackUrl = Url.Route("DefaultApi", new { controller = "Account", action= "ResetPassword", UserId = user.Id, code = code });
Run Code Online (Sandbox Code Playgroud)
这是生成的链接
https:///api/Account/ResetPassword?UserId=aaaaaaaaaa&code=aaaaaaaaa
Run Code Online (Sandbox Code Playgroud)
注意https:///api,它应该包括主机名和端口之类的https://localhost:4040/api.为什么不包含主机名?
c# ×4
asp.net-mvc ×3
.net ×2
angular ×1
angularjs ×1
asp.net ×1
azure-devops ×1
datatables ×1
jasmine ×1
javascript ×1
linq ×1