我有一个Windows服务,可以获取用户详细信息并将结果保存到日志文本文件中.而且,我的问题是当我关闭或注销我的系统时,我也想将我的系统中的时间保存到该日志文件中.但是,我不知道该怎么做.
我检查了winproc方法来检测关机操作,但我无法在窗口服务上使用它,谷歌搜索发现它只能用于表单.我们如何检测用户是否已点击关机或注销并执行某些操作.所以,请给我一些想法或建议.
我已经将它用于注销,但是当我注销系统时,会在日志条目上进行注销
protected override void OnSessionChange(SessionChangeDescription changeDescription)
{
this.RequestAdditionalTime(250000); //gives a 25 second delay on Logoff
if (changeDescription.Reason == SessionChangeReason.SessionLogoff)
{
// Add your save code here
StreamWriter str = new StreamWriter("D:\\Log.txt", true);
str.WriteLine("Service stoped due to " + changeDescription.Reason.ToString() + "on" + DateTime.Now.ToString());
str.Close();
}
base.OnSessionChange(changeDescription);
}
Run Code Online (Sandbox Code Playgroud) 我有一个文件列表,每个文件都有复选框,如果用户检查了很多文件并点击下载,我必须压缩所有这些文件并下载...就像在邮件附件中一样..
我已经使用本文中提到的代码进行单个文件下载
请帮助如何下载多个文件作为zip ..
我正在使用Response.AddHeader("Content-Disposition","attachment; filename ="+ Server.HtmlEncode(FileName)); 为用户弹出"打开/保存文件"对话框,以便他们可以将文件下载到本地计算机上.
这通常在IE7中运行良好,但在IE6上,当用户单击"打开/保存文件"对话框中的打开按钮时,文件无法打开.我浏览了网络,发现了Response.AddHeader("Content-Disposition","inline; filename ="+ Server.HtmlEncode(FileName)); 应提供IE6中的工作,并且其工作正常..
但问题是大多数可以在浏览器中打开的文件在页面本身打开..即用户在邮件页面上并单击下载它打开的图像文件,我需要它在IE7的情况下在另一个窗口中打开我该怎么做...其他文件无法在系统中使用当前应用程序打开,即(word,excel等)..
请建议一种方法,坚持使用相同的代码为两个IE ...我使用的代码在这里....
Response.AddHeader("Content-Disposition", "attachment; filename=" +FileName);
Response.AddHeader("Content-Length", file.Length.ToString());
Response.ContentType = ReturnExtension(file.Extension.ToLower());
Response.TransmitFile(file.FullName);
Response.End();
private string ReturnExtension(string fileExtension)
{
switch (fileExtension)
{
case ".txt":
return "text/plain";
case ".doc":
return "application/ms-word";
case ".xls":
return "application/vnd.ms-excel";
case ".gif":
return "image/gif";
case ".jpg":
case "jpeg":
return "image/jpeg";
case ".bmp":
return "image/bmp";
case ".wav":
return "audio/wav";
case ".ppt":
return "application/mspowerpoint";
case ".dwg":
return "image/vnd.dwg";
default:
return "application/octet-stream";
}
}
Run Code Online (Sandbox Code Playgroud) 我必须运行一个进程,即Windows关闭时的应用程序,是否有任何方法来延迟Windows关闭并在Windows服务中运行应用程序...
protected override void OnShutdown()
{
// Add your save code here
// Add your save code here
StreamWriter str = new StreamWriter("D:\\Log.txt", true);
str.WriteLine("Service stoped due to on" + DateTime.Now.ToString());
str.Close();
base.OnShutdown();
}
Run Code Online (Sandbox Code Playgroud)
我使用上面的函数覆盖了关闭,我能够写一个日志条目到文本文件,但我之后无法运行应用程序在搜索时我发现延迟低于用户激活关闭后的几秒钟
this.RequestAdditionalTime(250000);
这给关闭事件添加时间延迟25秒,但我无法运行应用程序.任何人都可以提出方法或想法在关机时运行应用程序.
我在我的网站上有一个文件上传,这是使用uploadify完成的,它使用ashx页面将文件上传到数据库.它在IE中工作正常,但在Mozilla中,context.Session变为null.我也习惯于IReadOnlySessionState读取会话.
我怎么能像IE一样在Mozilla中获得会话.
这是我做过的ashx代码
public class Upload : IHttpHandler, IReadOnlySessionState
{
HttpContext context;
public void ProcessRequest(HttpContext context)
{
string UserID = context.Request["UserID"];
context.Response.ContentType = "text/plain";
context.Response.Expires = -1;
XmlDocument xDoc = new XmlDocument();
HttpPostedFile postedFile = context.Request.Files["Filedata"];
try
{
if (context.Session["User"] == null || context.Session["User"].ToString() == "")
{
context.Response.Write("SessionExpired");
context.Response.StatusCode = 200;
}
else
{
// does the uploading to database
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
在IE中Context.Session["User"]总是有值,但在Mozilla中它始终为null
我想使用自动完成小部件允许某人通过在文本框中键入员工姓名来选择员工,但我希望表单发布员工的ID,而不是员工姓名.我提供了数据,即员工姓名作为来源..js中的标签和值与我提供的源相同,我怎样才能将员工姓名和ID分开.
$("#txtEmployeeName").autocomplete({
var suggestions = [] ;
//define callback to format results
source: function(req, add){
ajax call...
on success: function( data )
{
suggestions = data.split('|');
add(suggestions);
}
select: function(e, ui) {
//create formatted friend
var friend = ui.item.value,
span = $("<span>").text(friend)
$("#"+ $(this).attr("id")).val(span);
}
});
Run Code Online (Sandbox Code Playgroud) 我已经使用这里提到的代码来计算通过窗口服务的系统空闲时间.但是在Windows 7和Vista中,我总是得到LastInputInfo.dwTime0,因为我无法计算系统空闲时间.我已经给出了下面的代码示例.
// If we have a value from the function
if (GetLastInputInfo(ref LastInputInfo))
{
// Get the number of ticks at the point when the last activity was seen
LastInputTicks = (int)LastInputInfo.dwTime;
// Number of idle ticks = system uptime ticks - number of ticks at last input
IdleTicks = systemUptime - LastInputTicks;
}
Run Code Online (Sandbox Code Playgroud)
当我在Windows应用程序中测试相同的代码时,我得到了正确的答案dwTime.我需要dwTime在我的服务中正确计算系统的正确空闲时间.
请帮助一些例子
我有一个40-50左右的复选框集合,我为每个复选框设置了一个属性'attr-ID',这是数据库中唯一的值ID.如何通过c#代码中的属性名称获取控件.我想根据页面加载事件的dB值检查一些复选框.
<input type="checkbox" id="rdCervical" attr-ID='111' runat='server' />
Run Code Online (Sandbox Code Playgroud)