我有一个在godaddy.com注册的网站(在ASP.NET 2.0(C#)中开发)但是当我在我的web.config中添加HttpModule时如下:
<httpModules>
<add type="WwwSubDomainModule" name="WwwSubDomainModule" />
</httpModules>
Run Code Online (Sandbox Code Playgroud)
但它给了我"500内部服务器错误".当我删除上面的标签,然后我的网站工作正常.谁能猜到为什么它会造成这个问题?
我的身份验证HttpModule有问题.问题是它显然是针对我在Web服务器(IIS7)上获得的每个请求运行的.因为它也使用Session变量,所以它无法在CSS,JS文件等上正常工作.
我试着用:
<add name="AuthModuleName" type="..." preCondition="managedHandler" />
Run Code Online (Sandbox Code Playgroud)
但无济于事.它仍然可以在每个请求上运行,无论其扩展名或mime类型如何.我还要补充一下,有一个设置
<modules runAllManagedModulesForAllRequests="true">
Run Code Online (Sandbox Code Playgroud)
这对我来说似乎很可疑,并且实际上禁用了模块上的preConditions.但是将其更改为false会以完全不同的方式破坏应用程序并使用不同的异常(SessionStateTempDataProvider要求启用SessionState).
当有人请求静态内容文件时,有人可以帮助我强制IIS7排除我的HttpModule吗?
我正在运行VS 2008和.NET 3.5 SP1.
我想在我的ASP.NET应用程序中的HttpModule中实现命中跟踪.我想,很简单.但是,我的HttpModule的BeginRequest事件对每个页面命中都会触发两次.该网站现在非常简单......没有安全性,只需要一些数据库工作.应该每页登录一行.为什么这个事件会发射两次?
此外,IHttpModule.BeginRequest实际上第一次运行时(从关闭的Web浏览器)触发第一页时触发的次数不同... ...当我点击数据库为页面提供动态数据时,3次并且只有1次没有命中数据库的页面.无论我是否触摸数据库,它在第一个页面之后每次点击时会触发2次.
有趣的是,Application_BeginRequest(在Global.asax中)始终只触发一次.
这是代码:
using System;
using System.Data;
using System.Data.Common;
using System.Net;
using System.Web;
using BluHeron.BusinessLayer;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
namespace BluHeron.HttpModules
{
public class SiteUsageModule : IHttpModule
{
public void Init(HttpApplication httpApp)
{
httpApp.BeginRequest += OnBeginRequest;
}
static void OnBeginRequest(object sender, EventArgs a)
{
UsageLogger.LogSiteUsage(((HttpApplication)sender).Context.Request);
}
public void Dispose()
{ }
}
public static class UsageLogger
{
public static void LogSiteUsage(HttpRequest r)
{
string ipAddress = GetHostAddress(Dns.GetHostAddresses(Dns.GetHostName()));
string browserVersion = r.Browser.Type;
string[] urlChunks = r.RawUrl.Split('/');
string …Run Code Online (Sandbox Code Playgroud) 我在ASP.NET中实现了一个HttpModule(框架2.0).
从我在服务器上的日志记录中,我可以看到我的HttpModule正在拾取http请求,并且我的代码成功运行(将内容写回Response流).
但是,Web浏览器(IE,FF,Chrome,都是相同的)只是给我一个"连接重置"错误消息.
我检查了服务器上的事件日志; 那里没有相关的错误或消息.
额外信息:当我在FF中使用"Live HTTP Headers"插件时,它甚至不显示我的客户端请求(虽然我确信它到达服务器,因为在服务器日志中捕获了请求).
我如何解决这里发生的事情?
我正在尝试创建一个自定义HttpModule,它控制哪些用户可以查看网站.
我正在尝试利用Windows身份验证来执行此操作.
在单个页面上,我可能会这样做:
if (HttpContext.Current.User.Identity.Name.Contains("jsmith"))
{
Response.Write("You do not have the correct permissions to view this site.");
Response.End();
}
Run Code Online (Sandbox Code Playgroud)
但是因为我想在应用程序级别使其更易于配置,所以我想使用HttpModule.
这是我对代码的开始:
using System;
using System.Web;
public class CustomAuthHttpModule : IHttpModule
{
public void Dispose() { }
public void Init(HttpApplication context)
{
context.BeginRequest += new EventHandler(OnBeginRequest);
context.EndRequest += new EventHandler(OnEndRequest);
}
void OnBeginRequest(object sender, EventArgs e) { }
void OnEndRequest(object sender, EventArgs e)
{
HttpApplication appObject = (HttpApplication)sender;
HttpContext contextObject = appObject.Context;
if (contextObject.User.Identity.Name.Contains("jsmith"))
{
contextObject.Response.Clear();
contextObject.Response.End();
}
}
}
Run Code Online (Sandbox Code Playgroud)
如果我可以将它放在OnBeginRequest()函数中,我可以使用我拥有的代码.但是在OnEndRequest()运行之前,不会在HttpContext对象中创建User属性. …
我收到以下错误
'事件处理程序只能在IHttpModule初始化期间绑定到HttpApplication事件.在以下代码中(粗体或双线**)
protected void Application_BeginRequest(object sender, EventArgs e)
{
HttpApplication app = (HttpApplication)sender;
**app.EndRequest += new EventHandler(Application_EndRequest);**
}
protected void Application_EndRequest(object sender, EventArgs e)
{
UnitOfWork.Commit();
}
Run Code Online (Sandbox Code Playgroud)
在Global.asax文件中提到.有人可以弄清楚,我缺少的地方吗?谢谢.
我有一个使用ISAPI Rewrite的站点以及一个自定义的HttpModule,它们都进行了Url重定向和重写.
在IIS 6中,一切正常:首先运行ISAPI Rewrite过滤器,然后运行HttpModule.在IIS 7(集成模式)中,顺序现在是相反的,这会产生问题.
我的问题,特别是,HttpModule有一个条件,它会发出一个Url重写使用context.RewritePath.如果没有提供文档,它将显式地向路径添加"index.aspx",因此请求/test/被重写为/test/index.aspx.
在重写路径之后的某个时刻,执行ISAPI重写过滤器.我们有一个与模块相反的规则:/test/index.aspx获取301重定向的请求/test/.因此,我们有一个无限循环.
如何在IIS 7中确定HttpModules和ISAPI过滤器的执行顺序?订单可以更改吗?我发现了这个问题,但它并没有真正帮助.我不是IIS 7的主人,但我确实在某种程度上理解模块和ISAPI过滤器"一起"运行.不幸的是,他们的管理方式不同,我无法弄清楚如何强迫一个人跑到另一个人面前.救命!
注意:我们假设我无法更改现有代码.它在IIS 6中有效.我只想知道是否有办法使其在IIS 7集成模式下工作.
我有一个包含以下代码的同步HttpModule.
/// <summary>
/// Occurs as the first event in the HTTP pipeline chain of execution
/// when ASP.NET responds to a request.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">An <see cref="T:System.EventArgs">EventArgs</see> that
/// contains the event data.</param>
private async void ContextBeginRequest(object sender, EventArgs e)
{
HttpContext context = ((HttpApplication)sender).Context;
await this.ProcessImageAsync(context);
}
Run Code Online (Sandbox Code Playgroud)
当我尝试从空的MVC4应用程序(NET 4.5)运行该模块时,我收到以下错误.
此时无法启动异步操作.异步操作只能在异步处理程序或模块中启动,或者在页面生命周期中的某些事件中启动.如果在执行页面时发生此异常,请确保将页面标记为<%@ Page Async ="true"%>.
我似乎错过了一些东西但是通过我的阅读,错误实际上不应该发生.
我有一个挖掘,但我似乎无法找到任何帮助,有没有人有任何想法?
你如何设置它们?
如果我在HttpModule中有以下代码.
public static event EventHandler<PostProcessingEventArgs> OnPostProcessing;
Run Code Online (Sandbox Code Playgroud)
并在使用的异步PostAuthorizeRequest任务中设置EventHandlerTaskAsyncHelper.
// Fire the post processing event.
EventHandler<PostProcessingEventArgs> handler = OnPostProcessing;
if (handler != null)
{
handler(this, new PostProcessingEventArgs { CachedPath = cachedPath });
}
Run Code Online (Sandbox Code Playgroud)
然后使用它来点击它.
ProcessingModule.OnPostProcessing += this.WritePath;
private async void WritePath(object sender, PostProcessingEventArgs e)
{
await Task.Factory.StartNew(() => Debug.WriteLine(e.CachedPath));
}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误.
在异步操作仍处于挂起状态时完成异步模块或处理程序.
编辑
好吧,所以在我看到所有这些答案之前,我得到它不通过提升事件处理程序抛出错误,如下所示.
EventHandlerTaskAsyncHelper postProcessHelper =
new EventHandlerTaskAsyncHelper(this.PostProcessImage);
context.AddOnPostRequestHandlerExecuteAsync(postProcessHelper.BeginEventHandler,
postProcessHelper.EndEventHandler);
private Task PostProcessImage(object sender, EventArgs e)
{
HttpContext context = ((HttpApplication)sender).Context;
object cachedPathObject = context.Items[CachedPathKey];
if (cachedPathObject != …Run Code Online (Sandbox Code Playgroud) 我正在学习Http modules并且在最后一次尝试中我收到了:
HTTP错误500.22 - 内部服务器错误检测到的ASP.NET设置不适用于集成管理管道模式.
建议的解决方案之一是:
从IIS Express安装目录中,运行appcmd migrate config"Default Web Site /".
所以从命令提示符我去了C\Program Files\IIS Express然后我执行:appcmd migrate config "Default Web Site/"
我收到命令"对象配置"不支持"Migrate".
怎么做得好?
httpmodule ×10
asp.net ×6
iis-7 ×4
c# ×3
asp.net-mvc ×2
async-await ×1
asynchronous ×1
events ×1
global-asax ×1
isapi ×1