我正在.net 2.0中编写一个Windows服务.
我应该做内OnStart()如果由于某种原因,我不希望我的服务启动方法?我可以简单地调用Stop()基类(ServiceBase)的方法吗?我已经尝试过了,并且获得了一些有趣的内存访问异常.是否需要启动一个单独的线程来调用该Stop()方法?
Azure正在快速变化,所以有人可以给我一些关于如何记录的建议:
我希望能够将这些记录到表存储中,以便可以使用代码检索它们并在管理网页上查看它们.我对代码看起来并不多,但我真正想知道的是知道我应该在哪里看.Azure变化如此之快,我希望确保使用最好的.
谢谢
onStart()当客户没有许可证时,我想在方法中停止Windows服务.我用service.Stop(),但它不起作用.
protected override void OnStart(string[] args)
{
try
{
_bridgeServiceEventLog.WriteEntry("new OnStart");
if (LicenseValidetor.ValidCountAndTypeDevices())
{
WsInitializeBridge();
}
else
{
service = new ServiceController("BridgeService");
service.Stop();
_bridgeServiceEventLog.WriteEntry("LicenseValidetor Error");
}
_bridgeServiceEventLog.WriteEntry("end Start");
}
catch (Exception e)
{
_bridgeServiceEventLog.WriteEntry("error In onstart method ");
}
}
Run Code Online (Sandbox Code Playgroud) 我需要一个非常简单的事情 - 在Web API控制器中获取远程主机IP地址.本文将介绍如何在您进行虚拟主机或自托管时执行此操作.不幸的是,所描述的解决方案不适用于使用Owin自托管的Web API(好吧,我无法使其工作:)).我使用Windows服务来托管Web API.
所以,问题是:如何在使用Owin的Windows服务中自托管的Web API控制器中获取远程主机IP地址?
我需要远程IP地址的控制器:
internal class ItemController : ApiController
{
[HttpPost]
public HttpResponseMessage AddItem([FromBody] string data)
{
// Need to get remote host IP address here
return Request.CreateResponse(HttpStatusCode.OK);
}
}
Run Code Online (Sandbox Code Playgroud)
启动配置Web API的类:
internal class StartUp
{
public void Configuration(IAppBuilder appBuilder)
{
var httpConfig = new HttpConfiguration();
httpConfig.Routes.MapHttpRoute(
name: "Default",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
appBuilder.UseWebApi(httpConfig);
}
}
Run Code Online (Sandbox Code Playgroud)
我使用Windows服务来托管Web API.以下是服务的OnStart方法:
protected override void OnStart(string[] args) …Run Code Online (Sandbox Code Playgroud) 当我将PhoneGap项目移动到另一个文件夹时,我无法再运行phonegap local命令.例如,这个命令:
phonegap本地插件添加https://git-wip-us.apache.org/repos/asf/cordova-plugin-console.git
导致此错误:
找不到[错误]项目目录
我的猜测是,PhoneGap在配置中的某个地方定义了项目目录,但由于我将其移动到另一个文件夹,因此无法找到我的项目.我有办法在配置中更改PhoneGap项目目录吗?
我有一个包含HTTP和HTTPS页面的站点.
我已尝试以下方法使Cookie安全:
<httpCookies requireSSL="true" />带有表单身份验证的Web.config .Application_End在这两种情况下,页面都不适用于HTTP.我认为上述解决方案仅在所有页面都使用HTTPS时才有效.
如何解决这个难题?
我正在使用phonegap来开发我的iPhone应用程序.在index.html页面中,我正在实现一个小的javascript代码,只是为了检查Internet中是否有可用的onBodyLoad()功能,如下所示:
function onBodyLoad() {
if (!navigator.onLine) {
alert('offline');
}
document.addEventListener("deviceready",onDeviceReady,false);
//alert("here!");
}
Run Code Online (Sandbox Code Playgroud)
这只是工作正常,但我想在用户点击该警报消息的"确定"按钮时退出应用程序.
我navigator.device.exitApp()在警报后尝试添加,但没有奏效.
从警报消息中点击"确定"按钮后,如何退出应用程序?
谢谢
app.UseDeveloperExceptionPage()如果在方法中添加到IApplicationBuilderMVC(app.UseMvc())之后,Developer Exception Page()为空白Startup.cs Configure.
如果在MVC之前添加,Developer Exception Page工作正常.
这种行为是故意还是做错了?
这是我编写的代码,用于理解异常处理的工作原理:
using System;
using System.IO;
class ExceptionHandling
{
public static void Main()
{
try
{
StreamReader streamReader = new StreamReader("C:\\Sample Files\\Data.txt");
Console.WriteLine(streamReader.ReadToEnd());
streamReader.Close();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.WriteLine(ex.StackTrace);
}
}
}
Run Code Online (Sandbox Code Playgroud)
我理解这个try块,但我很难理解catch块是如何工作的.我知道这Exception是一个class和ex.Message是例外消息.
ex?如果这是一个对象,那么我们如何在没有实例化的情况下使用?将Exception ex放入catch的参数中会做什么?try和catch方法?如果是,那么它们是否在System命名空间中?我正在使用Visual Studio Code在Mac上开发ASP.NET 5应用程序.我遇到的问题是,除了我之前输入的方法和变量名称的简单自动完成之外,我没有获得任何IntelliSense支持(例如可用的类方法).
该应用针对DNX Core 5.0:
"frameworks": {
"dnxcore50": { }
},
Run Code Online (Sandbox Code Playgroud)
我通过DNVM安装了CoreCLR 1.0.0-rc1-update1:
$ dnvm列表
活动版本运行时体系结构OperatingSystem别名
------ ------- ------- ------------ --------------- --- -
- 1.0.0-rc1-update1 coreclr x64 darwin默认值
我尝试了以下方法来解决这个问题,但没有运气:
明确转向的建议 settings.json
{
"editor.quickSuggestions": true`
}
Run Code Online (Sandbox Code Playgroud)任何建议将不胜感激.
c# ×7
cordova ×2
.net ×1
.net-2.0 ×1
asp.net ×1
asp.net-core ×1
azure ×1
cookies ×1
exception ×1
intellisense ×1
ip-address ×1
iphone ×1
javascript ×1
omnisharp ×1
owin ×1
security ×1
service ×1