形式LoginUrl - 我怎么格式化这个与地区工作? [英] Forms LoginUrl - how do I format this to work with an area?

查看:116
本文介绍了形式LoginUrl - 我怎么格式化这个与地区工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

其中,我希望能完成所有必要的验证任务我添加一个区域到我的Web项目。该项目的文件夹结构是:

I have added an Area to my Web project wherein I hope to perform all the necessary authentication tasks. The folder structure in the project is:

- Solution
  - Web Project
    - Areas
      - Accounts
        - Controllers
            AccountController.cs

的AccountController 是通常的登录(LogOnModel型号,串RETURNURL)操作。

AccountsAreaRegistration.cs 是自动生成的路线:

context.MapRoute(
   "Accounts_default",
   "Accounts/{controller}/{action}/{id}",
   new { 
       action = "LogOn", 
       id= UrlParameter.Optional 
   }
);

这是发生在我的第一件事情是简单地增加该地区在web.config中的 loginUrl 属性的名称,让路由映射照顾重定向 - pretty简单,我想:

The first thing that occurred to me was to simply add the name of the area to the loginUrl attribute in the web.config, and let the route mapping take care of the redirect - pretty simple, I thought:

<forms loginUrl="~/Accounts/Account/LogOn"
       timeout="2880" />

唯一的问题是,它无法工作。我得到一个错误说无法找到/会计/会计/登录 - 或任何价值,我把loginUrl属性在我看来,我在web.config中指定URL不是通过推动该值路由表中查找匹配。

The only problem is that it doesn't work. I get an error saying "unable to find "/Accounts/Account/Logon" - or whatever value I put in the loginUrl attribute. It seems to me that the URL I specify in the Web.Config isn't pushing that value through the route table to look for a match.

*注意:这一切是由一项行动的[授权]属性我在其他控制器之一触发

*note: all of this is being triggered by an [Authorize] attribute on an action in one of my other controllers.

修改

我已经找到了解决办法是离开的URL作为默认的(即帐户/登录),并在Global.asax增加另一个路线将请求重定向到正确的领域:

The workaround I have found is to leave the URL as the default ("Account/Logon") and add another route in the global.asax to redirect the request to the right area:

routes.MapRoute("LogOn",
                "Account/LogOn/{id}",
                new { controller = "Account", 
                      action = "LogOn", 
                      id = UrlParameter.Optional}
).DataTokens.Add("area", "Accounts");

这干得不错,但我不知道这是否是对问题的最佳方案。

This gets the job done, but I don't know if it's the best solution to the problem.

推荐答案

我已经找到了解决办法是离开的URL作为默认的(即帐户/登录),并在Global.asax增加另一个路线将请求重定向以正确的区域:

The workaround I have found is to leave the URL as the default ("Account/Logon") and add another route in the global.asax to redirect the request to the right area:

routes.MapRoute("LogOn",
            "Account/LogOn/{id}",
            new { controller = "Account", 
                  action = "LogOn", 
                  id = UrlParameter.Optional}
).DataTokens.Add("area", "Accounts");

这干得不错,但我不知道这是否是对问题的最佳方案。

This gets the job done, but I don't know if it's the best solution to the problem.

这篇关于形式LoginUrl - 我怎么格式化这个与地区工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆