授权登录网址在asp.net MVC 3 [英] Authorize login URL in asp.net MVC 3

查看:119
本文介绍了授权登录网址在asp.net MVC 3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个Asp.Net MVC 3应用程序。我已经创建了管理区域为网站和登录后应用于 [授权] 属性actionmethods。当我尝试直接访问这些网址不一样管理员/家庭或管理/产品列表登录,我重定向到/ home /登录身份验证错误。我想重定向到管理员/登录。

I am working on an Asp.Net MVC 3 application. I have created admin area for the website and applied [Authorized] attribute to actionmethods after login. When I try to access these urls directly without login like admin/home or admin/productlist, I am redirected to /Home/Login with authentication error. I want to redirect to Admin/Login.

请建议。
谢谢

Please suggest. Thanks

推荐答案

有关ASP.NET应用程序(包括那些MVC3)登录URL被控制在web.config中,在窗体身份验证部分:

The login URL for ASP.NET applications (including MVC3 ones) is controlled in web.config, in the forms authentication section:

<configuration>
  <system.web>
    <authentication mode="Forms">
      <forms loginUrl="~/Home/Login" timeout="2880" />
    </authentication>
  </system.web>
</configuration>

你的技巧是,你希望两个不同的登录网址。 ASP.NET有一个很大的特点,你可以在你的项目的每个目录下的web.config文件,并根据需要将使用最具体的设置就可以发现,达根web.config。因此,文件夹中,你有你的管理视图(管理我猜),你应该能够创建第二个web.config文件,这将只适用于树中的这些页面和更低的:

The trick for you is that you want two different login URLs. ASP.NET has a great feature where you can have a web.config file in each directory of your project, and as needed it will use the most specific setting it can find, up to the root web.config. So in the folder where you have your admin views ("Admin" I'm guessing), you should be able to create a second web.config, which will apply only to those pages and lower in the tree:

<configuration>
  <system.web>
    <authentication mode="Forms">
      <forms loginUrl="~/Admin/Login" timeout="2880" />
    </authentication>
  </system.web>
</configuration>

这篇关于授权登录网址在asp.net MVC 3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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