单个站点上的多个应用程序 - 会话和表单身份验证范围
我们使用 ASP.NET 和 IIS 6.0。我意识到应用程序、网站和虚拟目录的定义在 IIS 6 中定义不明确,并且在 IIS 7 中发生了很大变化。但是,我现在仍坚持使用 IIS 6.0。
我们在 IIS 中定义了一个网站,并在虚拟目录中定义了许多单独的子站点。
该方案如下所示:-
http://site.example.com/site1
http://site.example.com/site2
.. etc ..
site1、site2...是 IIS 6.0 中“默认网站”下的虚拟目录。
我需要在大多数站点中使用 ASP.NET 会话和表单身份验证,并且我根本不希望它们共享身份验证数据或会话信息。
目前这两种机制都依赖于 cookie。然而,默认创建的cookie使用相同的名称,并且在浏览器中具有“/”路径,这意味着站点的cookie会相互冲突。
在不更改每个 cookie 的默认名称的情况下,如何强制子站点之间分离?我需要更改 IIS 6“应用程序”的虚拟目录吗?或者代码中是否有某种方法可以对 cookie 实施更有限的范围?
提前致谢。
We're using ASP.NET and IIS 6.0. I realise that the definitions of applications, websites and virtual directories are ill-defined in IIS 6, and changed a lot in IIS 7. However, I'm stuck with IIS 6.0 for now.
We have a single web site defined in IIS, and a number of separate sub-sites in Virtual Directories.
The scheme looks like this:-
http://site.example.com/site1
http://site.example.com/site2
.. etc ..
site1, site2, ... are virtual directories in IIS 6.0, under the "Default Web Site".
I need to use ASP.NET sessions and forms authentication in most of these sites, and I don't want them to share authentication data or session information at all.
Both the mechanisms currently depend on cookies. However, the cookies created by default use the same name, and have a path of "/" in the browser, meaning the sites' cookies will clash with each other.
Without changing the default name for each cookie, how can I enforce separation between my sub-sites? Do I need to change the virtual directories for IIS 6 "Applications"? Or is there some way in code to enforce a more limited scope for the cookies?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于表单身份验证,您可以定义 FormsCookiePath 属性来反映每个子站点的虚拟目录。
http://msdn.microsoft.com/en -us/library/system.web.security.formsauthentication.formscookiepath.aspx
对于会话状态,我还没有看到任何可以定义路径的东西,但是您可以定义与标准不同的 cookie 名称 cookieName="ASP.NET_SessionId" 值。这样每个子站点都会寻找不同的会话 cookie。
http://msdn.microsoft.com/en-我们/库/h6bb9cz9(v=VS.100).aspx
For Forms Authentication, you can define the FormsCookiePath property to reflect the virtual directory of each sub site.
http://msdn.microsoft.com/en-us/library/system.web.security.formsauthentication.formscookiepath.aspx
For Session State, I haven't seen anything that can define a path, but you can define different cookie names away from the standard cookieName="ASP.NET_SessionId" value. That way each sub site is looking out for different session cookies.
http://msdn.microsoft.com/en-us/library/h6bb9cz9(v=VS.100).aspx