我的WebAPI项目中有一些控制器使用的服务.该服务需要生成URL,因此理想情况下它将UrlHelper通过构造函数参数获得.
public class MyService
{
public MyService(UrlHelper urlHelper) { ... }
}
Run Code Online (Sandbox Code Playgroud)
我正在使用Autofac作为我的IoC容器.我怎样才能UrlHelper在容器中注册?它需要一个HttpRequestMessage,我无法弄清楚如何获得"当前"消息.
我的库正在使用独立存储,但只能按需使用.所以我正在使用Lazy<T>.
但是,这会引发:
System.IO.IsolatedStorage.IsolatedStorageException"无法确定已授予程序集的权限."
对于混淆隔离存储初始化的线程,Lazy是否会做一些奇怪的事情?
示例代码:
using System;
using System.IO.IsolatedStorage;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
var thisWorks = IsolatedStorageFile.GetMachineStoreForAssembly();
thisWorks.Dispose();
var lazyStorage = new Lazy<IsolatedStorageFile>(IsolatedStorageFile.GetMachineStoreForAssembly);
var thisFails = lazyStorage.Value;
thisFails.Dispose();
}
}
}
Run Code Online (Sandbox Code Playgroud)
完整堆栈跟踪:
System.IO.IsolatedStorage.IsolatedStorageException was unhandled
Message=Unable to determine granted permission for assembly.
Source=mscorlib
StackTrace:
Server stack trace:
at System.IO.IsolatedStorage.IsolatedStorage.InitStore(IsolatedStorageScope scope, Type domainEvidenceType, Type assemblyEvidenceType)
at System.IO.IsolatedStorage.IsolatedStorageFile.GetMachineStoreForAssembly()
at System.Lazy`1.CreateValue()
Exception rethrown at [0]:
at System.IO.IsolatedStorage.IsolatedStorage.InitStore(IsolatedStorageScope scope, Type domainEvidenceType, Type assemblyEvidenceType)
at System.IO.IsolatedStorage.IsolatedStorageFile.GetMachineStoreForAssembly() …Run Code Online (Sandbox Code Playgroud) 我的ASP.NET库安装了一个响应过滤器来解析和更改页面的HTML输出.这是有效的,直到在web.config中启用以下内容:
<system.webServer>
<urlCompression doDynamicCompression="true" dynamicCompressionBeforeCache="true" />
</system.webServer>
Run Code Online (Sandbox Code Playgroud)
我的响应过滤器仍然被调用,但传递的似乎是压缩数据,而不是原始HTML.
如何在页面存储到输出缓存之前确保重写?
将dynamicCompressionBeforeCache设置为false不是一个选项,因为此库旨在用于其他人可能有充分理由启用压缩的Web应用程序中.
根据我的客户端错误日志,我的ReactJS应用程序有时会抛出以下异常.
TypeError: Unable to get property 'remove' of undefined or null reference
at M.willDeleteListener (eval code:17:25544)
at v.deleteAllListeners (eval code:1:25843)
at m.Mixin.unmountComponent (eval code:16:15442)
at i.unmountComponent (eval code:15:5262)
at unmountChildren (eval code:17:3368)
at _.Mixin.unmountChildren (eval code:17:2153)
at m.Mixin.unmountComponent (eval code:16:15442)
at i.unmountComponent (eval code:15:5262)
at _.unmountComponent (eval code:15:16416)
at i.unmountComponent (eval code:15:5262)
Run Code Online (Sandbox Code Playgroud)
我一直无法复制(无论是在本地还是在制作中).
什么可能导致这个问题发生?我需要一些可以重现错误的事情想法.
我不希望在我的JQuery UI datepicker上显示"今天"突出显示.gotoCurrent选项用于突出显示移动到所选日期.这没关系.但是将gotoCurrent设置为true无效.我究竟做错了什么?
我正在创建一个使用区域的ASP.NET MVC 2(RTM)项目.一个区域的Home控制器的Index操作需要使用RenderAction来生成页面的子部分.调用的操作也在同一个Home控制器中定义.所以电话应该只是:
<% Html.RenderAction("List") %>
Run Code Online (Sandbox Code Playgroud)
但是,我得到一个例外:
在控制器'RareBridge.Web.Areas.Events.Controllers.HomeController'上找不到公共操作方法'List'.
请注意,我不在 "活动"区域!我在一个完全不同的领域.如果我删除"事件"主控制器,那么异常仍然会发生,但命名一个不同的控制器(仍然不是我想要它调用的控制器).
我也尝试过为RenderAction方法提供控制器名称和区域,但是会发生同样的异常.这里发生了什么?
BTW:我使用Autofac作为我的IoC容器
我已经制作了一个相当复杂的Silverlight 4浏览器外应用程序.我的一个主视图模型为Application.Current.MainWindow.Closing事件添加了一个事件处理程序.这在最初运行应用程序时工作正常.它可以取消关闭操作.
但是,有时在执行显示和关闭ChildWindow等操作后,MainWindow的Closing事件不再调用我的处理程序.
在调试器中,我向MainWindow的底层结束事件委托添加了一个监视.在显示ChildWindow之前它不是null.然后有时在关闭ChildWindow后,委托为空.这就解释了为什么我的处理程序不再被调用.但为什么这个代表被搞砸了呢?为什么它偶尔会发生?我的应用程序不会在任何时候取消绑定我的事件处理程序.
这是我正在观看的代表:
System.Windows.Application.Current.MainWindow.m_closingEvent
Run Code Online (Sandbox Code Playgroud)
其他的东西:我正在使用Caliburn Micro
我想使用以下内容将AWS S3异步方法转换为Task:
using (var client = AWSClientFactory.CreateAmazonS3Client(accessKey, secretKey))
{
var request = new PutObjectRequest();
// ... set request properties ...
await Task.Factory.FromAsync<PutObjectRequest, PutObjectResponse>(
client.BeginPutObject,
client.EndPutObject,
request,
null
);
}
Run Code Online (Sandbox Code Playgroud)
但是,我得到以下异常:
System.ArgumentException: The IAsyncResult object was not returned from the corresponding asynchronous method on this class.
Parameter name: asyncResult
at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at Amazon.S3.AmazonS3Client.getResponseCallback[T](IAsyncResult result)
at Amazon.S3.AmazonS3Client.endOperation[T](IAsyncResult result)
at Amazon.S3.AmazonS3Client.EndPutObject(IAsyncResult asyncResult)
at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)
Run Code Online (Sandbox Code Playgroud)
我的电话是FromAsync不正确还是其他地方出了问题?
PS
我需要从目录中的DLL加载所有程序集.
我的基本代码是:
var assemblies = from filename in Directory.GetFiles(HttpRuntime.BinDirectory, "*.dll")
select Assembly.LoadFrom(filename);
Run Code Online (Sandbox Code Playgroud)
但是,如果该目录中存在非托管DLL,则Assembly.LoadFrom将失败.有没有一种只加载托管DLL的好方法?捕获加载异常是一种选择,但我想知道是否有更好的方法.
我的代码在应用程序启动时在ASP.NET上运行.所以我也接受一个ASP.NET特定的解决方案.
我有一个MSBuild任务,具有LoadInSeparateAppDomainAttribute和继承自AppDomainIsolatedTask.
成功构建后,此任务将运行.它加载新编译的程序集并执行一些工作.因此需要单独的appdomain,否则Visual Studio将加载程序集并将其锁定.
但是,创建的appdomain不知道Web.config应用程序的文件.此配置包含成功加载程序集引用的DLL所需的绑定重定向.
有没有办法以编程方式将绑定重定向添加到appdomain?
.net ×3
asp.net ×3
c# ×3
autofac ×2
amazon-s3 ×1
asp.net-mvc ×1
async-await ×1
datepicker ×1
jquery ×1
jquery-ui ×1
msbuild ×1
reactjs ×1
renderaction ×1
silverlight ×1