Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 我的asp.net mvc web应用程序将始终检查请求是否经过身份验证_C#_Asp.net_Asp.net Mvc_Asp.net Mvc 4 - Fatal编程技术网

C# 我的asp.net mvc web应用程序将始终检查请求是否经过身份验证

C# 我的asp.net mvc web应用程序将始终检查请求是否经过身份验证,c#,asp.net,asp.net-mvc,asp.net-mvc-4,C#,Asp.net,Asp.net Mvc,Asp.net Mvc 4,我有以下行动方法:- [Authorize] [RequireHttps] [CheckUserPermissions(Action = "Read", Model = "Server")] public class ServerController : Controller { Repository repository = new Repository(); [OutputCache(CacheProfile = "NoCache")] pu

我有以下行动方法:-

[Authorize]
[RequireHttps]
[CheckUserPermissions(Action = "Read", Model = "Server")]
    public class ServerController : Controller
    {
        Repository repository = new Repository();

[OutputCache(CacheProfile = "NoCache")]
        public ActionResult Index(string searchTerm = "", int page = 1, string sort = "",int? pagesize=null)
现在我想测试一下,如果我们删除任何身份验证检查,索引操作方法将如何运行。因此,我删除了所有将检查用户是否经过身份验证的过滤器,如下所示:-

   // [Authorize]
    [RequireHttps]
  //  [CheckUserPermissions(Action = "Read", Model = "Server")]
        public class ServerController : Controller
        {
            Repository repository = new Repository();

   // [OutputCache(CacheProfile = "NoCache")]
            public ActionResult Index(string searchTerm = "", int page = 1, string sort = "",int? pagesize=null)
但是我得到的结果是,如果用户尝试访问Index操作方法,他仍然会被重定向到login视图!!尽管我已经删除了所有相关的过滤器,但有人能告诉我是什么导致请求被重定向到逻辑视图的吗?
谢谢

您可能需要检查您或框架是否已在应用程序的“开始”文件夹中添加了筛选器配置文件。可能正在分配全局授权属性。

我在web.config中有这些身份验证和授权标记。
i have these authentication and authorization tags inside web.config.
<authentication mode="Forms"> 
   <forms loginUrl="~/Account/Login" timeout="2880"/> 
</authentication> 
<authorization> 
   <deny users="?"/> 
   <allow users="*"/> 
</authorization>
是的,授权标签就是问题所在

如果您的应用程序仅为MVC(不与Web表单混合),则不应在Web.config中使用授权标记

解决方案
删除授权标记(仅保留身份验证标记)。

我已经检查了此项,并且FilterConfig仅注册defualt筛选器以进行错误处理…您是否可以确保web.config(一个在根目录下,另一个在内部视图文件夹中)没有授权标记?我在web.config中有这些身份验证和授权标记。这些可能是问题的原因吗?是的,我只使用asp.net mvc?但为什么这是一个问题?请给出建议好吗?@johnG授权标签不是必需的,因为如果您想锁定web应用程序中的所有资源,则可以应用全局筛选器。或者,如果要锁定特定的控制器,请将其应用于控制器。@johnG您不应该在MVC项目的web.config中使用授权标记,因为MVC使用路由,并且不会映射到像web表单这样的物理文件。这将打开一个安全漏洞。好吧,我从web.config中删除了授权标签,但这并没有改变任何东西,而且即使没有提到[Authorize]属性,用户仍将被重定向到登录页面??您可以提供建议吗?在所有web.configs中搜索,并确保没有授权标记。