2010-04-21 124 views
5

我的ASP.NET MVC项目中的默认控制器是用[Authorize]属性装饰的。当我在开发计算机上部署网站并访问网站时,我被重定向到登录页面(在Web.Config的表单loginUrl部分定义)。结果:一切都按预期工作。默认页面为ASP.NET MVC:AuthorizeAttribute

当我在生产服务器(Windows Server 2008,IIS 7,DefaultAppPool)上发布网站并访问网站时,预期地址显示在地址栏(/Account/LogOn?ReturnUrl=*my_expected_return_url*)中,但页面显示“您没有权限查看此目录或页面“。而不是登录页面。如果我删除默认控制器/操作中的[授权]属性,页面将正确显示。

我的web.config文件:

sessionState mode="InProc" timeout="30" 
    authentication mode="Forms" 
     forms loginUrl="~/Account/LogOn" timeout="2880" 
+0

请确保您没有另一个web.config在网站的父文件夹中。 – 2010-04-21 17:26:32

+0

您的根目录中是否有名为Default.aspx的文件?另外,请添加您使用的.net框架,asp.net和asp.net mvc的版本。 – 2010-04-22 15:11:25

回答

1

你有没有在你的web.config一节,明确允许非授权用户访问该页面~/Account/LogOn

<configuration> 
    <location path="~/Account/LogOn"> 
    <system.web> 
     <authorization> 
     <allow users="*" /> 
     <allow users="?" /> 
     </authorization> 
    </system.web> 
    </location> 
</configuration>