ASP.NET MVC Beta版授权属性把我送到错误的行动 [英] ASP.NET MVC Beta Authorize attribute sends me to wrong action

查看:118
本文介绍了ASP.NET MVC Beta版授权属性把我送到错误的行动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天,我开始与MVC 3测试版播放。开始从默认的MVC 3模板的应用程序,在主控制器增加了一个新的动作如下(与它的视图)

Today I started playing with the MVC 3 Beta. Started with an application from default MVC 3 template, added a new action in the Home controller as follows(with a view for it)

[Authorize]
public ActionResult Secured()
{
    ViewModel.Message = "This is secured area, only authenticated users should be here.";
    return View();
}

现在,当我尝试去导航到受保护的动作,我得到一个404页未找到错误。

Now when I try to go to navigate to Secured action I get a 404 page not found error.

下面是从我的web.config中的身份验证部分。

Here is the authentication section from my web.config.

<authentication mode="Forms">
  <forms loginUrl="~/Account/LogOn" timeout="2880" />
</authentication>

如果我的理解是正确的授权属性应导致本应由认证处理程序截获了401未经授权HTTP响应和重定向我到loginUrl。这将导致帐户/ LogOn支持采取行动。

If I understood it right the Authorize attribute should result in a 401 unauthorized HTTP response which should be intercepted by the authentication handler and redirect me to the loginUrl. Which should result in Account/LogOn action.

我的MVC 2应用程序运行正常,并带我到帐户/ LogOn支持采取行动,我失去的东西吗?或者这是MVC 3测试版中的错误?

My MVC 2 application works as expected and takes me to Account/LogOn action, am I missing something? or Is this a bug in MVC 3 beta?

推荐答案

<一个href=\"http://weblogs.asp.net/scottgu/archive/2010/10/06/announcing-nupack-asp-net-mvc-3-beta-and-webmatrix-beta-2.aspx#7624536\">ScottGu答复在他的博客类似的问题的,这显然是一个错误。

ScottGu replies to a similar question on his blog that this is apparently a bug.

解决方法是添加此项:

<add key="autoFormsAuthentication" value="false" />

你的&LT;的appSettings />在Web应用程序的根web.config文件栏目

to your <appSettings/> section in the web application's root web.config file.

这篇关于ASP.NET MVC Beta版授权属性把我送到错误的行动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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