替换 ASP.NET 中的默认身份验证模块
假设我已经编写了自己的身份验证模块来实现 IHttpModule
。虽然还没有真正完成,但有很好的资源,所以我可以弄清楚。
还有有关如何将自定义创建的模块添加到 Web.config
的教程。但是我如何替换某些默认模块?那就是如何从执行路径中删除默认身份验证模块?
我可以从 Web.config
中删除以下行吗?
<authentication mode="Forms">
<forms loginUrl="~/Account/LogOn" timeout="2880"/>
</authentication>
如果我删除它们,默认的身份验证模块仍然有效吗?
当然,即使我不使用该模块,也没有真正需要删除它......但它会节省一些处理器时间,我会感觉更好。
这很简单,而不是困难的部分:我可以替换 HttpContext
实现吗?我有自己的会话类,名为 Session
,但我不希望 HttpSessionState
位于 HttpContext
中。我还想替换 HttpContext
的 User
属性。所以我想我需要创建自己的 HttpContext 实现并强制我的应用程序以某种方式使用它。 我该怎么做?
请随意回答我的问题的任何部分或全部。
Suppose I've written my own authentication module implementing IHttpModule
. It is not really done but there are good resources so I can figure it out.
There are also tutorials on how to add custom created module to Web.config
. But how can I replace some default module ? That is how do I remove default authentication module from execution path ?
Can I just remove following lines from Web.config
?
<authentication mode="Forms">
<forms loginUrl="~/Account/LogOn" timeout="2880"/>
</authentication>
If I remove them will the default authentication module still work ?
Of cause there is no real need to remove that module even if I don't use it... But it'll save some processor time and I'll feel better.
That was easy, not the hard part: can I replace HttpContext
implementation? I have my own session class called Session
and I don't want that HttpSessionState
to be in HttpContext
. I'd also like to replace User
property of HttpContext
. So I guess I need to create my own implementation of HttpContext
and force my aplication to use it somehow.
How do I do it ?
Please feel free to answer any part of my question alone or all of them as you prefer.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这个怎么样?
How about this?
您可以将
模式
设置为无
。我会将您的 HttpContext 命名为不同的名称。You can set
mode
toNone
. I would name yourHttpContext
something different.