我可以通过Ajax.ActionLink("获取客户","GetCustomers","客户")调用asp.net mvc控制器;
我可以使用Html.ActionLink和jquery ajax调用来做同样的事情.
区别在哪里?
我正在运行集成测试,当我到达那行代码时:
WebApiDependencyResolverConfig.Register(config);
Run Code Online (Sandbox Code Playgroud)
(在里面使用autofac容器)
我得到这个例外:
{"Could not load file or assembly 'System.Web.Http, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)":"System.Web.Http, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"}
Run Code Online (Sandbox Code Playgroud)
Fusionlog:
=== Pre-bind state information ===
LOG: DisplayName = System.Web.Http, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
(Fully-specified)
LOG: Appbase = file:///C:/TLP/TLP.API.IntegrationTests/bin/Debug
LOG: Initial PrivatePath = NULL
Calling assembly : Autofac.Integration.WebApi, Version=3.0.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da.
===
LOG: This bind starts in default load context.
LOG: Using application configuration …Run Code Online (Sandbox Code Playgroud) 自托管不支持HttpContext.
当我运行自我托管的内存中集成测试时,这段代码也不起作用:
// OWIN Self host
var owinEnvProperties = request.Properties["MS_OwinEnvironment"] as IDictionary<string, object>;
if (owinEnvProperties != null)
{
return owinEnvProperties["server.RemoteIpAddress"].ToString();
}
Run Code Online (Sandbox Code Playgroud)
owinEnvProperties始终为null.
那么我应该如何使用自托管来获取客户端IP地址?
在ngOnDestroy方法中,我取消订阅我订阅的一个observable,否则代码被多次执行...
ngOnInit()
{
this.sub = this.route.params.subscribe(params =>
{
this.projectId = +params['id'];
this.projectStore.project = this.projectId;
// load data when the route changes
this._tasksService.gettasks(this.projectId).subscribe(years => { this.tasks = years.map(y => new task(y)) }); // no need to clean up the subscription
});
// load data when the component is initialized
this._tasksService.gettasks(this.projectId).subscribe(years => { this.tasks = years.map(y => new task(y)) }); // no need to clean up the subscription
}
ngOnDestroy()
{
this.sub.unsubscribe();
}
Run Code Online (Sandbox Code Playgroud)
现在我想把它放在路由器解析类中,但是没有ngOnDestroy - 当然 - 只是一个我再次订阅的NavigationEnd事件.
这意味着我订阅了一个NavigationStart事件(当我离开路线时发生)以取消订阅另一个订阅,这是路由参数更改订阅HAHAHA ...
我想这不是可行的方法,但谷歌什么也没提供.
任何人都知道如何处理这种情况?或者应该路由params更改订阅真的只属于一个组件? …
这是一个可以玩的玩家:
https://plnkr.co/edit/qTjftING3Hk2fwN36bQa?p=preview
一切都运行良好,除非您手动更改网址栏中的id参数,因为项目下拉列表不会将新projectId显示为当前项目.当用户将网址保存为收藏链接并将其复制/粘贴到网址栏时,会发生这种情况!我会说一个常见的情况!
为了解决这个问题,我可以收听route.params中的更改TestsListComponent并添加一个检查,sharedService/EventEmitter其中更改的ID存在于该下拉列表中.TestsListComponent中的bool返回值existsProjectId决定我应该重定向到/projects页面,因为id不存在.
但老实说,TestsListComponent至少从用户体验的角度来看,重定向是太迟了,因为route projects/:id/tests它已经被激活了.
你会如何解决这种不端行为?
PS
也许有一种全局参数更改我可以听,并检查ProjectsListComponent中的路径及其ID,这将有所帮助!
如果有人知道如何在窗口模式下编辑plunkr的url栏来测试这种不一致性,请告诉我你是如何使readonly url bar可编辑的...即使将url复制到新的选项卡也不行,因为我得到了一个plunkr找不到错误... => 答案
如何获取订阅的router.events内部的活动路由数据(如params)?
我也没有想订阅this.route.params!
// Catch any events in a certain component, where I subscribe to it!
this.router.events.subscribe(event =>
{
// The event object has only the url (when is NavigationStart/End), there is nothing useful for me
});
Run Code Online (Sandbox Code Playgroud)
更新
我的问题有所不同,因为我不问如何对路由器事件做出反应!
我要求如何在router.events中获取激活的路由参数!
那肯定是有区别的!
我的 API 控制器位于一个与托管 Owin 的控制台项目分开的额外项目中。
对控制器的请求起作用了,但是这个魔法是如何实现的呢?
我的控制台项目从哪里知道我的控制器所在的项目?
枚举所有添加的引用并检查从 ApiController 继承的类型?
我在新的Visual Studio 2015中创建了一个Web项目.
我可以选择asp.net 4.6或5.0预览web api模板.旧4.6有
身份验证,但我想使用新的5.0预览也web http://www.i.
但是这个模板缺乏身份验证,但为什么呢?
如何使用 bootstrap4 ONLY 类更改 btn-group 的方向垂直/水平,我找不到任何 btn-group-vertical-xs 、 -md、-lg 类。
<div class="btn-group-vertical">
...
</div>
Run Code Online (Sandbox Code Playgroud) 通常我必须在我的 IdP 注册授权回调 url/redirect_url。
但是,如果该 redirect_url 始终是用户试图在未经授权的状态下激活的那个,那将意味着我必须在我的 IdP 上注册所有 1000 条可能的路由。
那不能解决!
那我还能做什么?
更新
我使用用于基于 javascript 的应用程序的隐式流。
angular ×3
c# ×2
owin ×2
actionlink ×1
ajax ×1
asp.net ×1
asp.net-mvc ×1
autofac ×1
bootstrap-4 ×1
jquery ×1
openid ×1
self-hosting ×1
typescript ×1