【发布时间】:2009-01-01 20:00:54
【问题描述】:
现在我正在尝试使用 System.Web.Routing。一切都很好,但我不明白如何使表单身份验证与 url 路由(返回 url、重定向等)一起工作。谷歌什么也没说。帮助! :)
UPD:我忘了 - 我不使用 MVC。那就是问题所在。如何在没有 MVC 的情况下使用 rounig 和表单身份验证
UPD2:更多关于我的问题
我想得到:使用路由的 URL,例如“mysite.com/content/123”、“mysite.com/login/”等。重要的是让登录页面像“常规” ASP.NET 登录表单一样工作(未登录时重定向到安全区域登录,登录时重定向回安全区域)。
这就是我正在做的事情。
在global.asax 上的Application_Start 中,像这样注册路由:
routes.Add("LoginPageRoute", new Route("login/", new CustomRouteHandler("~/login.aspx")));
routes.Add("ContentRoute", new Route("content/{id}", new ContentRoute("~/content.aspx"))
{
Constraints = new RouteValueDictionary {{ "id", @"\d+" }}
});
CustomRouteHandler 和 ContentRoute 的位置——简单的 IRouteHandler 类,就像:
...
public IHttpHandler GetHttpHandler(RequestContext requestContext)
{
var page = BuildManager.CreateInstanceFromVirtualPath(VirtualPath, typeof(Page)) as IHttpHandler;
return page;
}
...
一切似乎都很完美:当转到“/content/10” 时,我得到content.aspx,当转到“/login/” 时,我得到login.aspx。但是……
当我确保内容安全时(在web.config 中,使用deny=”?”),登录表单无法正常工作。
现在我无法访问 “/content/10” 页面:
0. 我正在浏览器中输入 “/content/10”。
1. 网站重定向到“/login/?ReturnUrl=%2fcontent%2f10”。 (嗯……似乎所有的问题都从这里开始,对吧?:)
2. 我正在尝试登录。无论我输入什么凭据...
3. …网站将我重定向到 “login?ReturnUrl=%2fContent%2f10”(黄屏错误 - Access is denied. 描述:An error occurred while accessing the resources required to serve this request. The server may not be configured for access to the requested URL。)
所以,问题是如何让 ASP.NET 理解真正的ReturnUrl 并在登录后提供重定向。
【问题讨论】:
标签: asp.net authentication routing