是否可以通过F#的交互式窗口添加对.NET库的引用?例如:
> open System.Xml.Linq;;
open System.Xml.Linq;;
----------------^^^^
stdin(2,17): error FS0039: The namespace 'Linq' is not defined.
>
Run Code Online (Sandbox Code Playgroud) 的Internet Explorer在Windows 8.1,IE11更新的版本,具有下列用户代理字符串按照此:
Mozilla/5.0(Windows NT 6.3; Trident/7.0; rv:11.0)就像Gecko一样
我们的网站正在为所有浏览器的"text/html"响应中正确设置Content-Type,除非我们使用IE11 UA.对于发送IE11 UA的浏览器,它错误地发送"application/xhtml + xml".所有浏览器都在请求的Accept标头中发送"text/html,application/xhtml + xml,*/*".
是否有IIS或ASP.NET web.config设置允许为IE11或默认设置"text/html"?我目前没有使用任何.browser文件.
问候!
我有一个包含WebMethod的WebService,它可以完成一些工作并返回一个布尔值.它所做的工作可能需要或可能不需要一些时间,所以我想异步调用它.
[WebService(Namespace = "http://tempuri.com/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
public class MyWebSvc : System.Web.Services.WebService
{
[WebMethod]
public bool DoWork()
{
bool succ = false;
try
{
// do some work, which might take a while
}
catch (Exception ex)
{
// handle
succ = false;
}
return succ;
}
}
Run Code Online (Sandbox Code Playgroud)
此WebService存在于Web场中的每个服务器上.因此,要在每个服务器上调用DoWork()方法,我有一个类库,基于服务器URL列表:
static public class WebSvcsMgr
{
static public void DoAllWork(ICollection<string> servers)
{
MyWebSvc myWebSvc = new MyWebSvc();
foreach (string svr_url in servers)
{
myWebSvc.Url = svr_url;
myWebSvc.DoWork();
}
}
} …Run Code Online (Sandbox Code Playgroud) 我在运行时有一个静态对象,它基本上是其他对象(整数,字符串,字典,其他对象等)的列表.有没有办法在运行时确定我的静态"其他对象列表"对象使用的内存?这对于仪器和报告来说非常方便.
问候!
我创建了一个APSX Web表单,它根据一些提供的参数返回一个远程图像.它可以像这样使用:
<img src="/ImageGetter.aspx?param1=abc¶m2=123" />
Run Code Online (Sandbox Code Playgroud)
ImageGetter.aspx的标记和代码看起来类似于:
<%@ OutputCache Duration="100000" VaryByParam="*" Location="ServerAndClient" %>
<%@ Page Language="C#" AutoEventWireup="false" EnableSessionState="False" CodeBehind="ImageGetter.aspx.cs" Inherits="ACME.Helpers.ImageGetter" %>
Run Code Online (Sandbox Code Playgroud)
此代码在ImageGetter.aspx的Page_Load方法中调用:
byte[] data = null;
Dictionary<string, string> file_locations = GetImageLocations(param1, param2);
try
{
data = new WebClient().DownloadData(file_locations["main"]);
}
catch (WebException wex)
{
try
{
data = new WebClient().DownloadData(file_locations["backup"]);
}
catch (Exception e)
{
throw;
}
}
Response.ContentType = "image/jpeg";
Response.OutputStream.Write(data, 0, data.Length);
Response.End();
Run Code Online (Sandbox Code Playgroud)
从我的测试来看,它似乎不是缓存.这可能与输出缓存有关,还是应该根据查询字符串参数编写自己的缓存来存储字节数组?
我正在HttpModule以这样的方式处理异常:
int errorCode = 500;
HttpApplication httpApp = (HttpApplication)sender;
try
{
if (httpApp.Server != null)
{
Exception ex;
for (ex = httpApp.Server.GetLastError(); ex != null; ex = ex.InnerException)
{
try
{
HttpException httpEx = ex as HttpException;
if (httpEx != null)
errorCode = httpEx.GetHttpCode();
// ... retrieve appropriate content based on errorCode
}
catch { }
}
}
Run Code Online (Sandbox Code Playgroud)
对于HTTP状态代码(例如:302,404,503等),一切都很好.但是,对于IIS状态代码(例如:401.5,403.4等),可以GetHttpCode检索这些,因为它的返回值是整数吗?
我不认为我能找到一个明确的答案,所以我会在这里问一下.什么时候需要ScriptManager(或者在Master Page上使用ScriptManager的情况下是ScriptManagerProxy)?
例如,假设我在MasterPage上有一个ScriptManager:
如果我有一个包含UpdatePanel的Web内容表单,它是否需要ScriptManagerProxy?
如果我有一个包含用户控件的Web内容表单,并且用户控件中有一个UpdatePanel,那么用户控件是否需要ScriptManagerProxy?
如果我有一个包含UpdatePanel的Web内容表单和一个也包含UpdatePanel的UserControl,那么Web内容表单和/或用户控件是否需要ScriptManagerProxy?
谢谢.
我想实现支持资源扩展的RESTful服务,以便服务是自包含的,但如果客户想要限制它们所做的服务调用的数量,他们可以通过查询字符串参数来实现.资源扩展的一些示例是:
假设我有2个服务,每个服务都在自己的CSPROJ中:
ACME.AuthorsService的控制器有一个按ID获取作者的方法:
// GET /api/author/1
public async Task<HttpResponseMessage> Get(int id)
{
Author author = await _authorRepo.GetById(id);
if (author == null)
{
return Request.CreateResponse(HttpStatusCode.NotFound);
}
return Request.CreateResponse(HttpStatusCode.OK, author);
}
Run Code Online (Sandbox Code Playgroud)
这将返回有关作者的信息:
{
"Name": "Alan Moore",
"Href": "https://acme.org/api/author/1",
"Books": [
{
"Id": 9999,
"Title": "V for Vendetta",
"Href": "https://acme.org/api/book/9999"
},
{
"Id": 8888,
"Title": "Neonomicon",
"Href": "https://acme.org/api/book/8888"
}
]
}
Run Code Online (Sandbox Code Playgroud)
同样,ACME.BooksService的控制器有一个按ID获取书籍的方法:
// GET /api/book/1
public async Task<HttpResponseMessage> Get(int id)
{
Book book = await _bookRepo.GetById(id);
if …Run Code Online (Sandbox Code Playgroud) 从这个线程跳出来,我正在尝试使用ConcurrentDictionary来复制以下内容:
public static class Tracker
{
private static Dictionary<string, int> foo = new Dictionary<string, int>();
private static object myLock = new object();
public static void Add(string bar)
{
lock(myLock)
{
if (!foo.ContainsKey(bar))
foo.Add(bar, 0);
foo[bar] = foo[bar] + 1;
}
}
public static void Remove(string bar)
{
lock(myLock)
{
if (foo.ContainsKey(bar))
{
if (foo[bar] > 0)
foo[bar] = foo[bar] - 1;
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我最初的尝试是:
public static class Tracker2
{
private static ConcurrentDictionary<string, int> foo =
new …Run Code Online (Sandbox Code Playgroud) 我正在尝试遵循洋葱架构来获取在OWIN/Katana上托管的WebAPI服务.

我有这样的解决方案结构:
我希望DependencyResolution项目为WebApi项目注入依赖项.DependencyResolution确实有一个构建任务输出到WebApi项目的输出文件夹.
我正在遵循这里概述的方法,使用Autofac和DotNetDoodle.Owin.Dependencies NuGet包:
http://www.tugberkugurlu.com/archive/owin-dependencies--an-ioc-container-adapter-into-owin-pipeline
但是,在我的Startup类中注册服务时,对RegisterApiControllers()的调用将失败.DepenedencyResolution程序集将是第一个执行,因此它将无法获取包含ApiContollers(WebAPI程序集)的程序集:
public IContainer RegisterServices()
{
ContainerBuilder builder = new ContainerBuilder();
builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
builder.RegisterType<MyRepo>()
.As<IRepo>()
.InstancePerLifetimeScope();
return builder.Build();
}
Run Code Online (Sandbox Code Playgroud)
使用Assembly.Load()是唯一可行的选择,或者我应该放弃保持DependencyResolution项目被隔离的想法,只是从WebApi项目中引用它(看起来有点不那么洋葱)?
c# inversion-of-control onion-architecture asp.net-web-api owin
c# ×6
asp.net ×5
asp.net-ajax ×2
.net ×1
.net-3.5 ×1
.net-4.0 ×1
asynchronous ×1
caching ×1
f# ×1
http ×1
iis ×1
iis-6 ×1
outputcache ×1
owin ×1
rest ×1
web-services ×1