在我的应用程序中,我使用带有基于令牌的身份验证的web api和CORS支持,但是当客户端请求令牌时,由于CORS发生错误(跨源请求被阻止:同源策略不允许在(我的站点)读取远程资源这可以通过将资源移动到同一域或启用CORS来解决.)
我已经配置了CORS支持所需的一切(我想是这样).在这里我的配置
Owin开始上课
public class Startup
{
public void Configuration(IAppBuilder app)
{
var config = new HttpConfiguration
{
DependencyResolver = new StructureMapWebApiDependencyResolver(container)
};
WebApiConfig.Register(config); // registering web api configuration
app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll); // cors for owin token pipeline
app.UseWebApi(config);
ConfigureOAuth(app);
}
public void ConfigureOAuth(IAppBuilder app)
{
var oAuthAuthorizationServerOptions = new OAuthAuthorizationServerOptions()
{
AllowInsecureHttp = true,
TokenEndpointPath = new PathString("/token"),
AccessTokenExpireTimeSpan = TimeSpan.FromDays(1),
Provider = new SimpleAuthorizationServerProvider()
};
// Token Generation
app.UseOAuthAuthorizationServer(oAuthAuthorizationServerOptions);
app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions());
}
}
Run Code Online (Sandbox Code Playgroud)
和我的webapi配置
public static class WebApiConfig
{ …Run Code Online (Sandbox Code Playgroud) 在webApi2中,我可以通过继承IHttpActionResult来编写自定义ActionResult.
样品:
public class MenivaActionResult : IHttpActionResult
{
private readonly HttpRequestMessage _request;
private readonly ServiceResponseBase _response;
public MenivaActionResult(HttpRequestMessage request, ServiceResponseBase response)
{
_request = request;
_response = response;
}
public Task<HttpResponseMessage> ExecuteAsync(CancellationToken token)
{
HttpResponseMessage httpresponseMessage = _response.Exception != null
? _request.CreateErrorResponse((HttpStatusCode)_response.HttpCode,
_response.Exception.Message+":"+_response.Exception.HelpCode)
: _request.CreateResponse((HttpStatusCode)_response.HttpCode, _response.Data);
return Task.FromResult(httpresponseMessage);
}
}
Run Code Online (Sandbox Code Playgroud)
ServiceResponseBase类对象包含来自服务层的所有异常和数据.
我如何将此代码移植到asp.net核心.我试过,但我不知道如何从 .net核心中的HttpRequestMessage对象创建响应消息.该IActionResult只有Task ExecuteResultAsync(ActionContext context)方法.我怎么能修改这个方法的响应
我需要知道如何在 DDD 中使用共享值对象,例如?
如果我有两个称为“注册”和“准入”的聚合根,则这两个聚合都会消耗一个称为“地址”的值对象。尽管我的通用语言不同(入学地址和注册地址),但该地址对象的模型是相同的(我的意思是它具有共同的属性)。所以我决定将这个值对象从这两个聚合根移动到我的上下文中的共同位置(说 SharedValuess)。我想知道这种做法是否良好,或者是否有任何成熟的方法可以处理此类情况。
注意:这篇文章可能违反堆栈溢出的规则,因为它的答案是基于意见的,但我没有找到任何其他活跃的论坛来提出这个问题。
我正在使用restangular,但我有"Put"方法的问题,它没有按预期工作
我的angularService代码
var userService = function (restangular) {
var resourceBase = restangular.all("account/");
restangular.addResponseInterceptor(function (data, operation, what, url, response, deferred) {
if (operation == "getList") {
return response.data;
}
return response;
});
this.getUserById = function (id) {
return resourceBase.get(id);
// return restangular.one("account", id).get();
};
this.updateUser = function(user) {
return user.Put();
};
}
Run Code Online (Sandbox Code Playgroud)
我的控制器代码
var userEditController = function (scope, userService, feedBackFactory, $routeParams) {
scope.user = undefined;
scope.updateUser = function () {
userService.updateUser(scope.user).then(function (data) {
feedBackFactory.showFeedBack(data);
}, function (err) {
feedBackFactory.showFeedBack(err);
});
}; …Run Code Online (Sandbox Code Playgroud) 我有一个服务与休息角度与以下结构
function countrySvc(restangular) {
restangular.addResponseInterceptor(function (data, operation, what, url, response, deferred) {
if (operation === 'getList') {
var newResponse = response.data;
return newResponse;
}
return response;
});
var baseCountry = restangular.all('country');
this.countries = function() {
baseCountry.getList();
};
}
Run Code Online (Sandbox Code Playgroud)
也是一个控制器
function countryCtrl(scope, countrySvc) {
scope.countries = countrySvc.countries();
}
Run Code Online (Sandbox Code Playgroud)
但是当我从控制器访问国家时,结果是空的,数据成功请求,我的问题是如何从具有正确承诺模式的响应中提取数据,即(当我访问scope.countries时我需要一组国家/地区)
在我的一个项目中,我有两个应用程序.让我们说PurchaseApp和SalesApp.这两个应用程序正在使用名为Resourcesvc.js的共享服务(或工厂).目前,下面给出了两个应用程序的结构
PurchaseApp.js
var PurchaseApp= angular.module('PurchaseApp', []);
PurchaseApp.factory("Resourcesvc", ["$http", "$q", Resourcesvc]); // Registering Resource DI in app
PurchaseApp.controller("organizationCtrl", ["$scope", "organizationFactory",organizationCtrl]);
Run Code Online (Sandbox Code Playgroud)
SalesApp.js
var SalesApp= angular.module('SalesApp', []);
SalesApp.factory("Resourcesvc", ["$http", "$q", Resourcesvc]); / Registering Resource DI in app
SalesApp.controller("organizationCtrl", ["$scope", "organizationFactory",organizationCtrl]);
Run Code Online (Sandbox Code Playgroud)
它的工作正常.但有没有更好的方法或实践可用于跨模块/应用程序共享公共服务.(我真的很混淆角度应用与模块)
在我的项目中,我使用的是StructureMap.Net4(版本3.0.3)和StructureMap(3.0.3).我使用以下代码为Ioc配置了setter注入
public static IContainer Initialize()
{
ObjectFactory.Initialize(x =>
{
x.For<ICacheManager>().Use<MemmoryCacheManager>();
x.SetAllProperties(y => y.OfType<ICacheManager>);
//x.ForConcreteType<AuthorizationManager>()
// .Configure.Setter<ICacheManager>(y => y.CacheManager)
// .IsTheDefault();
});
return ObjectFactory.Container;
}
Run Code Online (Sandbox Code Playgroud)
但我得到一个错误无法解析符号SetAllProperties.我已经引用了以下命名空间
using StructureMap;
using StructureMap.Graph;
Run Code Online (Sandbox Code Playgroud)
为什么我收到此错误?我怎么能解决这个问题?或者我应该引用任何其他命名空间
我有一个具有以下结构的类:
public class OilCategory
{
public OilCategory Parent { get; set; } // For representing parent
public string Name { get; set; }
public int Position { get; set; }
public int Id { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我有 OilCategories 的列表集合:
OilCategory rootCategory = new OilCategory {Id = 1, Name = "Root", Position = 1, Parent = null};
OilCategory firstLevel1 = new OilCategory {Id = 2, Name = "fl-1", Position = 1, Parent = rootCategory};
OilCategory firstlevel2 = new OilCategory …Run Code Online (Sandbox Code Playgroud) ngClass指令生成以下错误
ERROR Error: Uncaught (in promise): Error: Template parse errors:
Can't bind to 'ngClass' since it isn't a known property of 'li'.
Run Code Online (Sandbox Code Playgroud)
代码段.
<li [ngClass]="{'active':true}"><a href="">Home</a></li>
Run Code Online (Sandbox Code Playgroud)
注意:我已经导入了通用模块
import {CommonModule} from "@angular/common"
Run Code Online (Sandbox Code Playgroud)
库版本角4.0.1
angularjs ×3
asp.net-mvc ×3
c# ×3
asp.net ×2
javascript ×2
restangular ×2
.net-core ×1
angular ×1
asp.net-core ×1
cors ×1
ddd-service ×1
katana ×1
linq ×1
owin ×1
structuremap ×1