ASP.NET MVC的问题与窗体身份验证部分的配置 [英] ASP.NET MVC issue with configuration of forms authentication section
问题描述
我对IIS运行ASP.NET MVC 3测试版应用程序。在我的的web.config
我定义下列负责窗体身份验证部分:
I have an ASP.NET MVC 3 Beta application running on IIS. In my web.config
I defined following section responsible for forms authentication:
<authentication mode="Forms">
<forms
loginUrl="~/Account/LogOn"
name=".VNK"
protection="All"
timeout="43200"
cookieless="UseCookies" />
</authentication>
该定义的登录地址是〜/帐号/ LogOn支持
。
当我尝试使用,以获得登录网址:
When I try to get the login url using:
FormsAuthentication.Initialize();
string loginUrl = FormsAuthentication.LoginUrl;
我收到: / VNK /网站/帐号/登录
为什么我在定义的获取不同的地址的web.config
?
Why do I get a different address from the one defined in web.config
?
更新:在/ VNK /网站/preFIX是不会此问题。问题是, LoginUrl
FormsAuthentication
类物业并不反映web.config中的价值。这意味着,如果我改变 loginUrl
属性的值从〜/帐号/登录到web.config中如〜/ foobar的 FormsAuthentication.LoginUrl
还有/ VNK /网站/帐号/登录的价值。为什么呢?
UPDATE: The "/VNK/site/" prefix is not a problem here. The problem is that LoginUrl
property of FormsAuthentication
class does not reflect the value from web.config. It means that if I change the value of loginUrl
attribute in web.config from "~/Account/LogOn" to e.g. "~/foobar", FormsAuthentication.LoginUrl
still has value of "/VNK/site/Account/Login". Why ?
推荐答案
我觉得这是在ASP.NET MVC 3 Beta版中的错误。此问题不会出现在ASP.NET MVC的previous版本。
I think there is a bug in ASP.NET MVC 3 Beta. This problem does not appear in previous releases of ASP.NET MVC.
如果有人想重播此错误,他应该遵循这样的:
If anyone wants to replay this error, he should follow this:
1 。下载请查看mvc framevork 。
2 .Create新的 ASP.NET MVC 3 Web应用程序
2.Create new ASP.NET MVC 3 Web Application
3
.Applay 授权
属性关于行动 HomeController的
3.Applay Authorize
attribute on About
action in HomeController
[Authorize]
public ActionResult About()
{
return View();
}
4 。开始申请并调用关于行动通过点击关于标签。你会得到服务器错误,因为应用程序试图将您重定向到此类网址:
4.Start application and invoke About action by clicking on About tab. You will get server error, because application is trying to redirect You to such URL:
的http://本地主机:[port_num] /帐号/登录RETURNURL =%2fHome%2fAbout
有显然是没有的登录查看。有 LogOn支持视图。网址登录动作是在web.config中触及定义:
There is obviously no Login view. There is LogOn view. Url to LogOn action is defined in untouched web.config:
<authentication mode="Forms">
<forms loginUrl="~/Account/LogOn" timeout="2880" />
</authentication>
但应用程序不反映这一点。任何人有任何线索,这是怎么回事?
But application does not reflect that. Have anyone any clue what's going on ?
更新:
我是对的,没有在 MVC 3测试版的错误。从已知问题:
I was right, there is a bug in MVC 3 Beta. From known issues:
的有一个已知的问题,导致窗体身份验证始终重定向未授权的用户/客户/登录,忽略在Web.config中使用窗体身份验证设置。解决方法是添加下面的应用程序设置。
<add key="autoFormsAuthentication" value="false" />
更新2:
亚历山大Prokofyev注意到,该 ASP.NET 3 RTM 寻找其他设置。因此,你需要这行,而不是:
Alexander Prokofyev noticed, that ASP.NET 3 RTM looks for another setting. So you need this line instead:
&LT;添加键=loginUrlVALUE =〜/登录/&GT;
这篇关于ASP.NET MVC的问题与窗体身份验证部分的配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!