我已经创建了一个示例项目来简化我的问题.我有这个简单的处理程序:
public class HandleThis : IHttpHandler, IRequiresSessionState
{
public void ProcessRequest( System.Web.HttpContext context )
{
// Score.aspx just says "success"
context.Response.Redirect( "Score.aspx" );
}
public bool IsReusable { get { return true; } }
}
Run Code Online (Sandbox Code Playgroud)
然后,在我的配置中,我有这个:
<httpHandlers>
<add verb="*"
path="Survey"
type="HttpHandlerTest.HandleThis, HttpHandlerTest" />
Run Code Online (Sandbox Code Playgroud)
现在,当我点击http:// server/Survey我的处理程序触发时.
如果我将项目更改为使用IIS 6运行,则不会触发(404).我尝试通过以下方式在IIS中手动添加处理程序: - 网站属性 - 主目录 - 配置 - 添加(浏览到我的网站的.dll),扩展:调查,取消选中"验证文件是否存在"
我注意到IIS(如此有用)添加了"." 在我的扩展面前,所以我用"b.Survey"点击了网站; 仍然是404.
当然可以在IIS 6中添加处理程序吗?
我看了一些较老的问题,但我找不到任何东西.
我在我的网络应用程序上有一个Wildcard HttpHandler,正在处理网址并确定它是否能用它做任何事情
如果它不能,那么StaticFile Handler应该把它拿起来,然后将它作为静态文件(如html文件)提供.
问题是,它通过通配符处理程序,然后似乎没有去StaticFileHander.我需要对Wildcard处理程序或Web配置做些什么吗?
这是我的web.config:
<add name="Wildcard" path="*" verb="*" type="Rewriter.RewriterHttpModule"
modules="IsapiModule" requireAccess="None" allowPathInfo="false"
preCondition="" responseBufferLimit="4194304" />
<add name="StaticFile" path="*.*" verb="*"
modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule"
scriptProcessor="%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll"
resourceType="File" requireAccess="Read" allowPathInfo="false" preCondition=""
responseBufferLimit="4194304" />
Run Code Online (Sandbox Code Playgroud) 我已经将我的asp.net 3.5应用程序移动到asp.net 4.0并从Windows 2003(iis6)移动到Windows 2008 r2(iis7.5),现在我有这个sys is undefined错误.
我让应用程序在集成的应用程序池中运行.一切都有效,除了我的ajaxtoolkit 3.0.20820.0 dll
现在我已经阅读了几篇博客文章,其中大多数都涵盖了asp.net 2.0 web.config文件,而不是最小化的asp.net 4.0配置文件.
这是我当前配置文件中的一些部分:
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<validation validateIntegratedModeConfiguration="false"/>
<handlers>
<add name="AjaxToolkit" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add name="ChartImg" verb="*" path="ChartImg.axd" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</handlers>
Run Code Online (Sandbox Code Playgroud)
另一部分:
<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add verb="GET" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler" validate="false"/>
<add path="ChartImg.axd" verb="GET,HEAD,POST" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false" />
</httpHandlers>
Run Code Online (Sandbox Code Playgroud)
没有太多信息可用于asp.net 4.0和ajaxtoolkit http处理程序问题,所以我希望一些大师@ stackoverflow可以帮助我:)
编辑: …
我在我的一些Web应用程序中使用elmah.我想知道是否有任何报告实用程序或工具可以分析/扫描所有日志并生成报告以向我显示日志中的常见错误.我喜欢http://demo.l4ndash.com/PageDashboard/Dashboard.aspx上的那个,但它适用于Log4Net而不是Elmah.
我到处寻找帮助,开始惹恼我.
我正在创建一个内部工具网站,用于存储工具及其相关信息.
我的愿景是拥有一个网址(Http://website.local/Tool/ID)其中ID是我们想要显示的工具的ID.我的理由是,我可以扩展URL的功能以允许各种其他功能.
目前我使用自定义的httpHandler拦截"工具"文件夹中的任何URL.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Tooling_Website.Tool
{
public class ToolHandler : IHttpHandler
{
public bool IsReusable
{
get { return false; }
}
public void ProcessRequest(HttpContext context)
{
//The URL that would hit this handler is: http://{website}/Tool/{AN ID eg: http://{website}/Tool/PDINJ000500}
//The idea is that what would be the page name is now the ID of the tool.
//tool is an ASPX Page.
tool tl = new tool();
System.Web.UI.HtmlTextWriter htr = new System.Web.UI.HtmlTextWriter(context.Response.Output); …Run Code Online (Sandbox Code Playgroud) 我需要在IIS中处理长时间运行的请求,处理请求本身非常轻量级,但主要是由于IO需要花费大量时间.基本上我需要查询另一台服务器,有时会查询第三台服务器.所以我想同时处理尽可能多的请求.为此,我需要异步处理请求如何正确处理?
使用Socket类我可以轻松地写出类似的东西:
// ..listening code
// ..Accepting code
void CalledOnRecive(Request request)
{
//process the request a little
Context context = new Context()
context.Socket = request.Socket;
remoteServer.Begin_LongRunningDemonicMethod(request.someParameter, DoneCallBack, context);
}
void DoneCallBack( )
{
IAsyncresult result = remoteServer.Begin_CallSomeVeryLongRunningDemonicMethod( request.someParameter, DoneCallBack, context);
Socket socket = result.Context.Socket;
socket.Send(result.Result);
}
Run Code Online (Sandbox Code Playgroud)
在上面的例子中,一旦我调用"Begin ..."方法就释放线程,并且响应在另一个线程上发送,因此您可以轻松实现非常高的并发性.你如何在IIS内的HTTP处理程序中做同样的事情?
我有一个自定义的HttpHandler,我在其中手动启用输出压缩,如下所示:
context.Response.AppendHeader("Content-encoding", "gzip");
context.Response.Filter = new GZipStream(context.Response.Filter, CompressionMode.Compress);
Run Code Online (Sandbox Code Playgroud)
这适用于大多数请求,但遇到异常时,"Content-encoding"标头会从响应中消失,而压缩过滤器仍保留在原位.结果是错误页面被gzip压缩,但是浏览器没有收到表示该事实的标题.然后浏览器尝试将仍然压缩的数据显示为文本,即gobbledygook.
完整的测试用例代码如下所示.尝试交替禁用压缩或不抛出异常.
有人可以解释为什么"内容编码"标题消失了吗?
我想我可以简单地启用压缩作为处理程序的最后一件事,因此如果遇到异常,它永远不会到达添加压缩过滤器的点; 但我看到的行为让我感到害怕.谁能确认一下?
public class TestHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
CompressResponse(context);
context.Response.Write("Hello world");
// Throw an exception for testing purposes
throw new Exception("Just testing...");
}
private void CompressResponse(HttpContext context)
{
string acceptEncoding = context.Request.Headers["Accept-Encoding"];
if (String.IsNullOrEmpty(acceptEncoding))
{
return;
}
// gzip or wildcard
if (acceptEncoding.ToLower().Contains("gzip") || acceptEncoding.Contains("*"))
{
context.Response.AppendHeader("Content-encoding", "gzip");
context.Response.Filter = new GZipStream(context.Response.Filter, CompressionMode.Compress);
return;
}
// Also handles deflate (not …Run Code Online (Sandbox Code Playgroud) 我有可重用HTTPHandler的问题.我想查看该IsReusable物业是如何运作的.所以我创建了两个处理程序:
可重复使用:
public class ReusableHandler : IHttpHandler
{
public bool IsReusable
{
get { return true; }
}
private int _counter;
public ReusableHandler()
{
_counter = 0;
}
public void ProcessRequest(HttpContext context)
{
context.Response.Write("Reusable: " + _counter++);
}
}
Run Code Online (Sandbox Code Playgroud)
而不是可重复使用的:
public class NonReusableHandler : IHttpHandler
{
public bool IsReusable
{
get { return false; }
}
private int _counter;
public NonReusableHandler()
{
_counter = 0;
}
public void ProcessRequest(HttpContext context)
{
context.Response.Write("NonReusable: " + _counter++);
}
}
Run Code Online (Sandbox Code Playgroud)
它们都按预期工作:每次返回递增值时可重用,而NonReusable每次返回0.但是当我使用我的处理程序作为WebHandlers(*.ashx)时,它们每次都返回0(代码完全相同).这是否意味着当我使用WebHandlers时,该 …
我有一个应用程序,其中约20个http generic handler用于ajax call.
我用IReadOnlySessionState我的处理程序访问会话.一切正常.
但是当会话到期时,我的处理程序返回一些html,因为它重定向到默认页面,并且默认页面的html在响应中被发回.
要克服这个问题.
我已经检查了处理程序中的会话变量,如果它是null,我已经写了
context.Response.Write("logout")
Run Code Online (Sandbox Code Playgroud)
我检查jQuery ajax天气它是注销或其他任何东西.
$.ajax({
url: "myhandler.ashx",
contentType: "application/json; charset=utf-8",
success: function (data) { checklogout(data); $("#loading").hide(); },
error: function () { $("#loading").hide(); },
async: false
});
Run Code Online (Sandbox Code Playgroud)
如果它是注销,那么我使用位置重定向到登录页面.
我form-authentication用来验证用户.
有没有更好的方法来检查和使用jquery-ajax调用重定向到登录页面.
我创建了这个HTTP处理程序来更新本地SQL Express数据库中的信息.
我意识到用户可以使用相对URI路径"/../../file.zip"作为查询字符串,并且能够下载受限区域之外的文件.
该网站尚未生效,所以现在不是安全问题,但我真的想要阻止这样的事情.
我添加了一个简单的string.replace行,它从输入查询中删除任何"..".
我还有什么需要做的吗?
public void ProcessRequest(HttpContext context)
{
string filesPath = "C:/Downloads/";
string fileName = context.Request.QueryString["filename"];
fileName = fileName.Replace("'", "''").Replace("..", "").Replace("/", "").Replace("\\", "");
if (!string.IsNullOrEmpty(fileName) && File.Exists(filesPath + fileName))
{
context.Response.ContentType = "application/octet-stream";
context.Response.AddHeader("Content-Disposition", string.Format("attachment; filename=\"{0}\"", fileName));
context.Response.WriteFile(filesPath + fileName);
//Do work to update SQL database here
}
else
{
context.Response.ContentType = "text/plain";
context.Response.Write(filesPath + fileName + " Invalid filename");
}
}
Run Code Online (Sandbox Code Playgroud) httphandler ×10
asp.net ×9
c# ×4
.net ×3
asp.net-4.0 ×1
elmah ×1
http-headers ×1
iis ×1
iis-6 ×1
iis-7.5 ×1
sanitize ×1
security ×1
session ×1
web ×1
web-config ×1