简体   繁体   English

ASP.NET 2.0 HttpModule或HttpHandler

[英]ASP.NET 2.0 HttpModule or HttpHandler

I'm improving an app for authentication/authorization. 我正在改进用于身份验证/授权的应用程序。 The app is asp but I'm pretty unfamiliar with it. 该应用程序是asp,但我并不熟悉。

So far I have been able to create a HttpModule and HttpHandler and register them in the IIS Manager. 到目前为止,我已经能够创建HttpModule和HttpHandler并将其注册到IIS管理器中。

First I have tried an HttpModule and had success with doing the AA with the module run on managed resources. 首先,我尝试了一个HttpModule,并成功地对在托管资源上运行的模块进行了AA。 I'm using the PreRequestHandlerExecute method so I have access to session. 我正在使用PreRequestHandlerExecute方法,因此可以访问会话。 For some reason when other pages run pieces like menus begin to go missing. 由于某些原因,当其他页面运行时,菜单等内容将丢失。 In the module code I have have simply put a variable in session. 在模块代码中,我只是简单地将变量放入会话中。 why does this happen? 为什么会这样?

Next I have tried an HttpHandler for a specific path. 接下来,我尝试了HttpHandler的特定路径。 I seemed to have luck there but then the actual login form post submit causes an error. 我似乎很幸运,但是实际提交的登录表单提交后导致错误。 Probably because the form is runat server and it sees something session etc bad because of the handler being in front of it. 可能是因为表单是runat服务器,并且由于处理程序在表单的前面,所以它看到了会话等错误。

If I remove the HttpModule/HttpHandler the app works just fine but obviously does not have the AA needed. 如果我删除HttpModule / HttpHandler,则该应用程序可以正常运行,但显然没有所需的AA。 So I'm missing key parts to using HttpModule/HttpHandler 所以我缺少使用HttpModule / HttpHandler的关键部分

I've already ran across many common issues like null session etc. that I have resolved. 我已经遇到了许多常见问题,例如null session等,这些问题已经解决。

I've done this type of work in Java Server/Jsp using Filter/FilterChain many times but ASP.NET is simply too new to me to figure out the API/Syntax. 我已经多次使用Filter / FilterChain在Java Server / Jsp中完成了这类工作,但是ASP.NET对我来说太新了,无法弄清楚API /语法。

I need to find the simplest way to add an HttpModule/HttpHandler that can work with the existing form login but allow me to do some AA and do a redirect or session management for AA. 我需要找到最简单的方法来添加可以与现有表单登录一起使用的HttpModule / HttpHandler,但允许我执行一些AA并为AA进行重定向或会话管理。 I've considered just using scripting <% %> etc in the aspx page. 我已经考虑过只在aspx页面中使用脚本<%%>等。

Any suggestions appreciated. 任何建议表示赞赏。

An HttpModule will be hit on every request. 每个请求都会命中一个HttpModule A HttpHandler is usually run on a specific extension. HttpHandler通常在特定扩展上运行。

Generally for authentication, you'll want it in a module, since you'll want to examine every request to see if it's authenticated. 通常,对于身份验证,您将需要在模块中,因为您将需要检查每个请求以查看其是否已通过身份验证。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM