我已经构建了一个.net4.5 ASP.NET MVC4 Web应用程序,它在本地工作正常(IIS Express和开发服务器)但是一旦我将它部署到我的Web服务器,它就会抛出403错误.我已经在服务器上安装了.Net 4.5RC,甚至尝试了
aspnet_regiis -i
每个人都推荐用于以前版本的MVC/.Net的问题,但它没有帮助.
有任何想法吗?
编辑:有关情况的更多信息.服务器是32位,我有4个其他MVC3应用程序可以正常工作.这只是我的MVC4应用程序无法正常工作.
即使我已经编码了很长时间,我对单元测试也很陌生.我想把它作为我发展方式的一部分.我遇到了关于如何对集合进行单元测试的问题.我通常有我的jQuery脚本调用ASP.Net Server方法来获取数据和填充表格等.他们看着像是
Get_*Noun*()
Run Code Online (Sandbox Code Playgroud)
通常返回一个JsonResult.关于使用MSTest进行单元测试的测试方法和方法的任何想法?
我是Moq的新手,一般都在测试,所以这是我的noobish Q.如何测试请求中的Status属性是否已使用Moq设置?
public class DudeManager
{
private readonly IDRepository _repo;
public DManager(IDRepository repo)
{
_repo = repo;
}
public void Create(Request r)
{
r.Status = Status.Submitted;
_repo.AddRequest(r);
}
}
Run Code Online (Sandbox Code Playgroud)
有没有比以下更好的方法?也许使用VerifySet?
[TestMethod]
public void AddingNewRequestSetsStatusToSubmitted()
{
//Arrange
var mock = new Mock<IDRepository>();
var mockRequest = new Mock<Request>();
var dManager = new DManager(mock.Object);
//Act
dManager.Create(mockRequest.Object);
//Assert
Assert.AreEqual(Status.Submitted, mockRequest.Object.Status);
}
Run Code Online (Sandbox Code Playgroud)
编辑:这是我在所有有用的建议后最终使用的方法:
//Arrange
var request = new Request();
var mock = new Mock<IDRepository>();
var dManager = new DManager(mock.Object);
mock.Setup(x …
Run Code Online (Sandbox Code Playgroud) 我到处寻找希望找到一个教程,告诉我如何使用Cloud 9来构建Node.js应用程序.谁知道有什么好资源?
Cloud 9是否支持任何数据库?我的应用可以与数据库通信吗?MongoDB,Sqlite ......什么的?如果是这样,我该如何设置?我愿意与任何数据库合作.我只想将一些信息保存到数据库中.
我在ASP.Net MVC 5项目中看到了捆绑的奇怪行为.当我在BundleConfig.cs文件中显式声明所有文件时,我的项目工作得很好,如下所示:
bundles.Add(new ScriptBundle("~/bundles/app").Include(
"~/app/app.js",
"~/app/config.js",
"~/app/dir1/file1.js",
"~/app/dir1/subdir1/file2.js",
.....
Run Code Online (Sandbox Code Playgroud)
但是,如果我转而使用IncludeDirectory
,则开发(BundleTable.EnableOptimizations = false
)期间的脚本路径不完整.这就是我所看到的:
bundles.Add(new ScriptBundle("~/bundles/app").Include(
"~/app/app.js",
"~/app/config.js")
.IncludeDirectory("~/app/dir1", "*.js", true)
Run Code Online (Sandbox Code Playgroud)
当Chrome试图获取时,Chrome会向我显示404 file2.js
.捆绑系统将以下内容添加到我的布局页面:
<script src="/app/app.js"></script>
<script src="/app/config.js"></script>
<script src="/app/dir1/file1.js"></script>
<script src="/app/dir1/file2.js"></script>
Run Code Online (Sandbox Code Playgroud)
通往file2.js
错误的道路.它省略subdir1
了路径的一部分.我在这里错过了什么吗?
我有一个延迟加载其功能组件的应用程序.只要我不进行AOT编译(经过几天的努力,我就开始工作),一切都很好,花花公子.
我的初始页面加载速度非常快.但是,当我点击任何应该延迟加载该功能的导航链接时,我得到了404,这是正确的.有一个请求,myfeature.module.ngfactory.js
但该文件不存在.我已经关注了开发网站上的食谱,但它没有详细介绍如何让延迟加载工作.我看到我的AOT编译创建了一个myfeature.module.ngfactory.ts
但不创建myfeature.module.ngfactory.js
文件.我该如何创建这个文件?我的tsconfig-aot.json
文件看起来像这样:
{
"compilerOptions": {
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [
"es2015",
"dom"
],
"module": "es2015",
"moduleResolution": "node",
"noImplicitAny": false,
"sourceMap": true,
"suppressImplicitAnyIndexErrors": true,
"target": "es5"
},
"files": [
"app/shared/shared.module.ts",
"app/app.module.ts",
"app/myfeature/myfeature.module.ts",
"main.ts"
],
"angularCompilerOptions": {
"skipMetadataEmit": true
},
"exclude": [
"node_modules/*",
"**/*-aot.ts"
]
}
Run Code Online (Sandbox Code Playgroud)
我觉得我错过了什么.看起来引导过程是创建过程app.module.ngfactory.js
但没有触发创建的过程 myfeature.module.ngfactory.js
.
我正在尝试构建一个自定义数据网格,可以显示数据作为卡或更传统的表/列表/网格.如果我不希望模板可以自定义,我可以很容易地完成它,如此plunker中所示
在这里,我有一个my-grid
组件可以传递要呈现的数据.然后我循环数据并根据所需的视图渲染card-view
或list-view
组件,该视图由view toggle
(app/my-grid.ts
文件中的代码)控制
我想提供传递自定义模板的能力,我想这样的事情:
<my-grid>
<card-view-template>
<template var-item>
<h4>{{item.name}}</h4>
{{item.home}}
</template>
</card-view-template>
<list-view-template>
<template var-item>
<span>{{item.name}}</span>
{{item.home}}
</template>
</card-view-template>
</my-grid>
Run Code Online (Sandbox Code Playgroud)
我怎样才能从我所处的位置找到我想要的东西?
当从服务器获取模型时,我遇到了一个问题.我在chrome dev工具中看到从服务器返回的正确JSON,但模型不会使用返回的值进行更新.
var listtemplate = new ListTemplateModel.Model({id: id}); listtemplate.fetch();
此时我在Chrome开发工具中看到了正确的数据.以下是从服务器返回的内容:
{ "title": "Template one", "id": "template_one", "steps": [ { "description": "I love it", "id": 1, "created_at": "2012-12-24T18:01:48.402Z" }, { "description": "This is rubbish!", "id": 1, "created_at": "2012-12-24T18:01:48.402Z" } ], "created_at": "2012-12-24T18:01:48.402Z" }
但是控制台记录JSON只显示默认值和模型创建期间传入的id.
console.log(listtemplate.toJSON());
这会返回:
{id: "template_one", title: "", steps: Array[0]}
我的模型看起来像这样(我使用的是Require.js,因此模型已经重命名为上面的ListTemplateModel)
var Model = B.Model.extend({ defaults: { title: '', id: 0, steps: [] }, urlRoot: 'xxx' });
有任何想法吗?
编辑 @ Amulya的答案让我走上正轨,然后我发现了"然后".希望这可以帮助有人遇到同样的问题:
listtemplate.fetch().then(function(){ //update the view });
我试图对我的一条路线进行单元测试,我得到臭名昭着的"错误:意外请求"错误.我的路线采用"resolve"参数,如下所示:
when('/Users',
{
templateUrl: 'app/users/user-list.tpl.html',
controller: 'UserListCtrl',
resolve: {
userAccounts: ['UserAccounts', function(UserAccounts) {
return UserAccounts.query({ id: 123 });
}]
}
})
Run Code Online (Sandbox Code Playgroud)
其中UserAccounts是一种"资源".我正在测试我的路线如下:
beforeEach(inject(function (_$route_, _$location_, _$rootScope_, _$httpBackend_) {
$route = _$route_;
$location = _$location_;
$rootScope = _$rootScope_;
$httpBackend = _$httpBackend_;
$httpBackend.when('GET', 'api/Accounts/123/UserAccounts').respond([]);
$httpBackend.when('GET', 'app/users/user-list.tpl.html').respond({});
}));
it('/Users should get user-list template and use UserListCtrl', inject(function($controller) {
$httpBackend.expectGET('app/users/user-list.tpl.html');
$httpBackend.expectGET('api/Accounts/123/UserAccounts');
expect($route.current).toBeUndefined();
$location.path('/Users');
$rootScope.$digest();
expect($route.current.loadedTemplateUrl).toBe('app/users/user-list.tpl.html');
expect($route.current.controller).toBe('UserListCtrl');
}));
Run Code Online (Sandbox Code Playgroud)
测试失败了Error: Unexpected request: GET http://myserver/api/Accounts/123/UserAccounts
.这是我的决心所要求的.有什么想法正确的方法来测试这样的路线?
我正在开发 SPA 并想知道在页面上显示和隐藏 HTML 元素的最佳方法是什么取决于用户凭据。
我有一个使用 AngularJS 的 RestfulAPI 后端和 JS 重客户端。获得身份验证后,我希望页面的某些元素变得可见,而其他元素则取决于用户有权执行的操作。
现在,我在身份验证时从服务器发送一个 JSON 对象,该对象包含权限列表(只是一个字符串数组)并根据权限数组中相应键的存在显示/隐藏元素。
我有我的服务器端 API,并确保在处理每个请求之前 - 用户授权。
我认为,这将帮助我防止人们篡改我的 HTML 和 JS 并在客户端启用元素并尝试发出他们未经授权的请求。
作为另一个级别的伪安全,我确保发送给客户端的权限名称只是实际权限的别名。当 API 尝试授权请求时,它查找的声明会以不同的方式命名。
我的问题是 - 这是一种安全的方法吗?
那里有更好的方法吗?
我是否应该仅在授权后才从服务器获取 HTML 模板,该模板仅包含用户有权查看的 HTML?
如果我的服务器端授权是无懈可击的,那么用户查看所有 HTML 的能力是否重要?
这是我第一次玩SignalR.我想建立一个通知系统,其中定期服务器检查,看看是否有什么(查询数据库)来播放,如果有那么它广播到所有的客户.我碰到这个职位#2,想知道是否修改代码以使DB调用在一个特定的时间间隔确实是这样做的正确方法.如果不是,有更好的方法吗?
我确实在这里发布了许多与通知相关的问题,但没有任何代码.因此这篇文章.
这是我正在使用的确切代码:
public class NotificationHub : Hub
{
public void Start()
{
Thread thread = new Thread(Notify);
thread.Start();
}
public void Notify()
{
List<CDCNotification> notifications = new List<CDCNotification>();
while (true)
{
notifications.Clear();
notifications.Add(new CDCNotification()
{
Server = "Server A", Application = "Some App",
Message = "This is a long ass message and amesaadfasd asdf message",
ImgURL = "../Content/Images/accept-icon.png"
});
Clients.shownotification(notifications);
Thread.Sleep(20000);
}
}
}
Run Code Online (Sandbox Code Playgroud)
我已经看到一些奇怪的行为,其中通知比他们应该更频繁.即使我应该每隔20秒就能得到它,我会在4-5秒左右得到它并且我收到多条消息.这是我的客户:
var notifier = $.connection.notificationHub;
notifier.shownotification = function (data) {
$.each(data, function (i, …
Run Code Online (Sandbox Code Playgroud) asp.net-mvc ×3
c# ×3
unit-testing ×3
angular ×2
cloud9-ide ×2
.net ×1
angularjs ×1
backbone.js ×1
html ×1
iis ×1
javascript ×1
mocking ×1
moq ×1
mstest ×1
node.js ×1
security ×1
signalr ×1