我有一个在consol应用程序中托管的WCF服务(也充当Windows服务安装程序),请在此处查看更多信息:http://msdn.microsoft.com/en-us/library/ms733069.aspx
这是consol应用程序中的类看起来像:
public class MyAppWindowsService : ServiceBase
{
public ServiceHost _MyAppClientServiceHost = null;
public ServiceHost _MyAppIntegrationServiceHost = null;
public ServiceHost _MyAppserviceHost = null;
public MyAppWindowsService()
{
// Name the Windows Service
ServiceName = "MyApp Service";
}
public static void Main()
{
ServiceBase.Run(new MyAppWindowsService());
}
private void StopService(ServiceHost serviceHost)
{
if (serviceHost != null)
{
serviceHost.Close();
serviceHost = null;
}
}
private ServiceHost StartService(Type serviceType)
{
ServiceHost serviceHost = null;
// Create a ServiceHost for the CalculatorService type …Run Code Online (Sandbox Code Playgroud) 我有一台来自我公司的服务器。该服务器上未安装 git (并且在不久的将来也不会安装)。(在许多免费服务器托管网站上,也没有安装 git)
有没有办法在不安装 git 的情况下使用 git 二进制文件(因此不需要另一个文件夹中所需的依赖项,独立)?
另一个服务器对我来说是没有选择的。
我想要 git 作为 Web git 存储库查看器,这当然需要 git 二进制文件在任何文件夹中工作,也许有一个带有集成 git 二进制文件的 Web git 存储库查看器。
我试过:
服务器操作系统是linux 64位。我已将 git 二进制文件从本地 linux 复制到服务器上的可执行路径。它不起作用。所以我查找依赖关系。需要这些库:
它们只是指向名为的库的链接:
所以我重命名了这些库并将它们复制到 git 二进制文件所在的服务器。但不幸的是,git 二进制文件在 /lib/linux-64-gnu...os 文件夹中查找库,而不是在同一文件夹中。我不知道接下来要尝试什么。
我有一个带有以下控制器的 WebApi 应用程序:
public class ContentController : ApiController
{
[HttpPost]
public HttpResponseMessage Post(string contentType)
{
//do stuff
return new HttpResponseMessage(HttpStatusCode.OK);
}
}
Run Code Online (Sandbox Code Playgroud)
路线是这样的
routes.MapHttpRoute("content",
"api/content/{contentType}",
new { controller = "Content", contentType = RouteParameter.Optional });
Run Code Online (Sandbox Code Playgroud)
当我在 IIS / cassini 中托管服务时,如果我api/content/whatever按预期POST 到那时,我的控制器操作就会被命中。
然而,
我有一个测试项目,SelfHosts 这个 api
using (var client = new HttpClient(Server))
{
var result = client.PostAsync(BaseAddress + "api/content/whatever"
var message = result.Content.ReadAsStringAsync().Result;
}
Run Code Online (Sandbox Code Playgroud)
如果我调试单元测试并进入它,result则是:
{StatusCode: 500, ReasonPhrase: 'Internal Server Error', Version: 1.1, Content: System.Net.Http.ObjectContent`1[[System.Web.Http.HttpError, System.Web.Http, Version=5.0.0.0, Culture=neutral, …
我们正在使用自托管的 WebApi,我们需要删除所发送响应的服务器标头(服务器:Microsoft-HTTPAPI/2.0)。
由于它是自托管的,因此 HttpModule 不是一种选择。实现 a DelegatingHandler,访问标头以及添加是可能的。在asp.net网站很好的细节,如何能够做到这一点。
但是服务器标头似乎是在管道中稍后添加的,因为它没有在HttpResponseMessage我们从DelegatingHandler. 但是,我们可以添加值。
async protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
HttpResponseMessage response = await base.SendAsync(request, cancellationToken);
response.Headers.Server.Add(new ProductInfoHeaderValue("TestProduct", "1.0"));
response.Headers.Add("Server", "TestServerHeader");
return response;
}
Run Code Online (Sandbox Code Playgroud)
双方Server.Add并.Add正常工作。response.Headers.Remove("Server");但是不起作用,因为服务器标头未设置,response.Headers.Server为空。
有什么我想念的吗?
我需要自己托管(在IIS的Windows进程中)现有的.ashx服务.该服务实现了IHttpHandler.
我对 HTML 和 Javascript 知之甚少,我想了解以下内容:
我有一个主 HTML 文件,其中包含一些文本、图像......并且它还包含对其他本地 HTML 文件的内部引用,这些文件放在相对目录中。是否可以制作一个完全独立的 HTML 文件,其中其他文件仍然通过 URL 链接引用,但它们的内容只是记录在主文件中?
我在使用--self-containedPandoc 中的选项时遇到了这个问题,它只将所有必要的内容(CSS 样式表等)写入 HTML 标头,而主 HTML 文档仍然需要“查看”实际的本地文件。
到目前为止,我尝试过该iframe标签,但它总是打开,并且不是像一行 URL 链接那样简单地放在页面中。我已使用 HTML+javascript 阅读了此答案,但我不确定这是否与 Pandoc 兼容。
谁能帮助我了解这项任务的难度?
在为自主主机Owin控制台应用程序设置HTTP时出现问题.浏览器始终显示连接重置错误.
我已尝试根据此链接http://chavli.com/how-to-configure-owin-self-hosted-website-with-ssl/手动创建证书,但我仍然在该端口上遇到连接重置问题.我已经检查了Windows事件日志,并且没有错误消息.
应用程序将自行创建X509证书并自动运行netsh命令.
没有Ssl,应用程序可以正确显示网页.
任何人都可以在下面运行我的代码并查看它是否可以在您的计算机上运行?提前致谢.
需要添加COM引用CertEnroll 1.0 Type Library来编译下面的代码(vs2015已在类型库中包含此COM引用)
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
using CERTENROLLLib;
using Microsoft.Owin.Hosting;
using AppFunc = System.Func<System.Collections.Generic.IDictionary<string, object>, System.Threading.Tasks.Task>;
namespace Owin.Startup
{
class Program
{
static void Main(string[] args)
{
int port = 8888;
string url = $"https://localhost:{port}";
var cert = GetCert("localhost", TimeSpan.FromDays(3650), "devpwd", AppDomain.CurrentDomain.BaseDirectory + "cert.dat");
ActivateCert(cert, port, GetAppId());
using (WebApp.Start<Startup>(url))
{
Console.WriteLine($"Hosted: {url}");
Console.ReadLine(); …Run Code Online (Sandbox Code Playgroud) 很明显,如果您正在为桌面/服务器应用程序开发Web UI,那么owin/nancy托管是一个合乎逻辑的选择.同样清楚的是,对于高流量的网站而言,这是不够的,但IIS托管更可取.
我想知道使用自托管Web应用程序时的实际考虑/限制是什么.我们假设我们不需要任何IIS提供的功能特性,例如gzip压缩.从纯粹的性能角度来看,在哪个负载级别(大约)自托管开始崩溃,为什么?IIS是否能更有效地进行线程调度?
我有一个自托管的 Owin WebAPI。我想通过身份验证保护一些路由。大多数路由应该可以匿名访问。我已经成功实现了 Windows-Auth,但是现在我401 - Unauthorized在尝试访问标记为[AllowAnonymous]匿名访问它们的路由时得到了。如果我使用有效凭据调用该方法,则一切正常。
完美的解决方案是默认允许匿名,并且仅在操作具有该[Authorize]属性时才需要凭据。
public void Configuration(IAppBuilder appBuilder)
{
// Enable Windows Authentification
HttpListener listener = (HttpListener)appBuilder.Properties["System.Net.HttpListener"];
listener.AuthenticationSchemes = AuthenticationSchemes.IntegratedWindowsAuthentication;
HttpConfiguration config = new HttpConfiguration();
config.MapHttpAttributeRoutes();
appBuilder.Use(typeof(WinAuthMiddleware));
appBuilder.UseWebApi(config);
}
Run Code Online (Sandbox Code Playgroud)
public class WinAuthMiddleware : OwinMiddleware
{
public WinAuthMiddleware(OwinMiddleware next) : base(next) {}
public async override Task Invoke(IOwinContext context)
{
WindowsPrincipal user = context.Request.User as WindowsPrincipal;
//..
}
}
Run Code Online (Sandbox Code Playgroud)
public class ValuesController : ApiController
{
[AllowAnonymous] // attribute …Run Code Online (Sandbox Code Playgroud) 当应用程序运行多个线程时,owin 自托管 Web 服务器的响应能力出现了一个奇怪的问题。
我提供了一个简单的例子来说明问题:
申请代码:
using System;
using System.Threading;
using System.Threading.Tasks;
using Test.Api;
namespace Test.Web
{
class Program
{
public static void RunWebServer()
{
Task.Factory.StartNew(() =>
{
StartWebServer();
}, TaskCreationOptions.LongRunning);
}
private static void StartWebServer()
{
WebServer.StartWebServer();
while (true)
{
Thread.Sleep(10);
}
}
private static void StartThreads(int maxthreads)
{
for (int m = 0; m < maxthreads; m++)
{
Task.Factory.StartNew(() =>
{
while (true)
{
Thread.Sleep(1000);
}
});
Thread.Sleep(10);
}
} …Run Code Online (Sandbox Code Playgroud)