FormsAuthentication 选择 url
有没有办法实现表单身份验证,但仅限于特定的 URL。 例如,我希望 formsAuthentication 能够保护 staging.mydomain.com 上的站点,但如果 web.config 意外移动到生产站点,则不会阻碍对 www.mydomain.com 的访问。
Is there a way to implement forms authentication, but only for a specific URL. For example, I would want the formsAuthentication to protect the site on staging.mydomain.com but not hinder access to www.mydomain.com if the web.config accidentally got moved over to the production site.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这是可以实现的,但您必须为此实现您自己的 IHttpModule。 可惜 FormsAuthenticationModule 是密封的,这意味着您必须从头开始,但是 Reflector可以在那里提供很大的帮助。
This can be achieved, but you'll have to implement your own IHttpModule for it. Alas FormsAuthenticationModule is sealed, meaning that you would have to start from scratch, but Reflector can be a great help there.
我们过去使用过一个简单的解决方法。
我们将默认登录页面设置为可供匿名用户访问的简单页面,我们将其称为 checkDomain.aspx
在该页面中,我们对域进行快速检查,并基于此将用户重定向到中的 login.aspx 页面临时站点,或生产站点中原始请求的 URL。 这并不漂亮,但当我们担心类似的事情可能发生时,它可以在短时间内快速且轻松地实施。
we have used a simple workaround in the past.
We set the default Login page to be a simple page that is accessible to anonymous users, lets call it checkDomain.aspx
In that page, we do a quick check of the domain and based on that we redirect users to the login.aspx page in the staging site, or to the original requested url in the production site. this wasnt pretty but it was quick and easy to implement for a short period of time when we feared something like that could happen.
表单身份验证是在网站实例上实现的。 它不会那样工作。
Forms auth is implemented on the web site instance. Its not going to work that way.
您可以在 web.config 中管理 FormsAuthentication 的功能。 所以,答案就在你的问题中,@Andrew 是对的。
但是,您也许可以在 global.asax 中执行某些操作来识别该站点正在运行的服务器或域并禁用 FormsAuthentication。 如果域是 www.mydomain.com,则可以创建一个有权访问所有内容的用户,并在会话启动时手动为该用户设置 FormsAuthenticationTicket。
这有点骇人听闻,我建议您想出一种带外方式来控制您的 web.config。
The web.config is where you can manage what FormsAuthentication does. So, the answer is kind of in your question and @Andrew is right.
However, you might be able to do something in your global.asax to recognize the server or domain that the site is running on and disable FormsAuthentication. Maybe create a user that has access to everything and manually set a FormsAuthenticationTicket to that user on session start if the domain is www.mydomain.com.
This is a bit hackish and I would suggest coming up with an out of band way to control your web.config instead.