在 ASP.NET 中使用成员身份处理身份验证

发布于 2024-08-05 03:43:59 字数 786 浏览 4 评论 0原文

好的,问题是:

我有两个网站:www.mysite.com 和 blog.mysite.com(假网站名称),它们假设共享身份验证。 登录页面位于 www.mysite.com/login/login.aspx

现在,博客网站的 web.config 具有以下身份验证部分:

<authentication mode="Forms">
  <forms timeout="50000000" 
   loginUrl="http://www.mysite.com/login/login.aspx"
   defaultUrl="~/"/>
</authentication>
<authorization>
   <deny users="?"/>
</authorization>

现在我点击 blog.mysite.com/andrey/page.aspx 它会将我重定向到 www 网站上的登录页面。真正的问题是“reditect”查询字符串只包含相对页面 URL (andrey/page.aspx),因此当我登录时,它会尝试将我重定向到 www.mysite.com /andrey/page.aspx,而不是我开始的 blog.mysite.com/andrey/page.aspx 所以当然一​​切都会失败。

有没有办法告诉会员对象在弹跳到登录页面时将完整路径放入“重定向”查询字符串参数中?

谢谢! 安德烈

Ok, here is the problem:

I have two sites: www.mysite.com and blog.mysite.com (fake site names) which suppose to share authentication.
The login page is on www.mysite.com/login/login.aspx

Now, the blog website has web.config with following authentication section:

<authentication mode="Forms">
  <forms timeout="50000000" 
   loginUrl="http://www.mysite.com/login/login.aspx"
   defaultUrl="~/"/>
</authentication>
<authorization>
   <deny users="?"/>
</authorization>

Now I hit blog.mysite.com/andrey/page.aspx and it redirects me to login page which is on www site. The real problem is that "reditect" query string will only contain relative page url (andrey/page.aspx), so when I login it will try to redirect me to www.mysite.com/andrey/page.aspx, not blog.mysite.com/andrey/page.aspx where i started so of course everything fails.

Is there a way to tell Membership object to put the full path into "redirect" query string parameter when it bounces to login page?

Thanks!
Andrey

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

沧桑㈠ 2024-08-12 03:43:59

假设每个域都有自己的 web.config,我认为这可能有效。

1) 为 www.mysite.com 和 blog.mysite.com 创建登录页面
2)将两者指向同一个会员数据库
3) 确保两个站点具有相同的成员资格 applicationName 属性集:

<membership><providers><add applicationName="mySite">

4) 确保两个站点具有相同的表单名称集:

<authentication mode="Forms"><forms  name="mySite">

这应确保两个站点使用相同的成员资格数据库和相同的身份验证 cookie,但它们将使用各自的登录名页面,所以返回 url 应该没问题。


您可以调用 FormsAuthentication.SetAuthCookie 方法 并手动重定向到http引荐来源网址?


我刚刚在 FormsAuthentication.RedirectFromLoginPage 的文档中看到了这一点

默认情况下,ReturnUrl 变量
必须引用内的页面
当前的应用程序。如果返回网址
引用不同的页面
应用程序或不同的服务器上,
从登录页面重定向方法
重定向到中的 URL
DefaultUrl 属性。如果你想
允许重定向到外部页面
当前应用程序,您必须设置
EnableCrossAppRedirects 属性到
true 使用enableCrossAppRedirects
表单配置的属性
元素。安全说明安全说明:

设置启用CrossAppRedirects
属性为 true 以允许
跨应用程序重定向是
潜在的安全威胁。什么时候
跨应用程序重定向是
允许,您的网站容易受到
使用您的恶意网站
登录页面说服您的网站
用户认为他们正在使用安全的
您网站上的页面。提高安全性
当使用跨应用程序时
重定向,你应该覆盖
允许的 RedirectFromLoginPage 方法
仅重定向到批准的网站。

弄乱该财产有什么帮助吗?

Assuming that each domain has its own web.config, I think this might work.

1) Create a login page for both www.mysite.com and blog.mysite.com
2) Point both to the same membership database
3) Make sure both have the same membership applicationName attribute set:

<membership><providers><add applicationName="mySite">

4) Make sure both have the same forms name set:

<authentication mode="Forms"><forms  name="mySite">

This should ensure that both sites use the same membership database and the same authentication cookie, but they'll use their individual login pages and so the return url should be fine.


Can you call the FormsAuthentication.SetAuthCookie Method and manually redirect to the http referrer?


I just saw this in the documentation for FormsAuthentication.RedirectFromLoginPage

By default, the ReturnUrl variable
must refer to a page within the
current application. If ReturnUrl
refers to a page in a different
application or on a different server,
the RedirectFromLoginPage method
redirects to the URL in the
DefaultUrl property. If you want to
allow redirects to a page outside the
current application, you must set the
EnableCrossAppRedirects property to
true using the enableCrossAppRedirects
attribute of the forms configuration
element. Security noteSecurity Note:

Setting the EnableCrossAppRedirects
property to true to allow
cross-application redirects is a
potential security threat. When
cross-application redirects are
allowed, your site is vulnerable to
malicious Web sites that use your
login page to convince your Web site
users that they are using a secure
page on your site. To improve security
when using cross-application
redirects, you should override the
RedirectFromLoginPage method to allow
redirects only to approved Web sites.

Does messing with that property help at all?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文