HTTP 错误 401.0 - Unauthorized 的解决方案
来源:互联网 发布:淘宝店铺直播要求 编辑:程序博客网 时间:2024/06/05 02:27
我的项目突然间报这个错误....
HTTP 错误 401.0 - Unauthorized
您无权查看此目录或页面。
网上百度了N久都说是文件夹权限问题.我给整个盘都分配了Everyone 的权限,文件夹也分配额Everyone 的权限.
但是我看到报错内容提示登录用户是匿名用户, 又在组策略里面将 Everyone的权限应用在匿名用户身上. 也就是说,系统把匿名用户当作 Everyone的组员来看.
理论上文件系统已经不存在什么权限问题了.
可还是报下面的错误. 这个报错页面很专业,猛地一看好像是iis 系统错误爆出的..
网上也没有关于 401.0的说明全部都是
401.1
401.2
401.3
401.4
的说明,只有几篇是关于401.0的.结果还不对.
实在无奈的情况下发现一篇文章,里面.说把项目的属性里面(不是属性页) 的windows身份验证启用就好了.
打开方法 属性页是右键可以点击出来的. 属性窗口是直接选中项目以后. 属性窗口(右下)自动会显示的.
我也抱着死马当活马医的心态试了下.
奇迹出现了.vs2010调试器有反应了.报了一个异常.异常是从类:
public class UserAuthorizeAttribute : AuthorizeAttribute
里面的AuthorizeCore 方法.爆出来的.
这个方法是用来验证用户是否已登录的过滤器.
我调试跟踪了一下发现.
登录的用户名是 一个系统用户名. .
这个用户名是window系统上固有的用户名. (启用window身份验证,会采取window那套自动登录机制.. 这当然不是我们想要的.)
然后我又把windows身份验证 给关掉了.
发现登录用户名是空的了.代码 return false;
一开始的错误又出来了.
也就是说这个异常.跟AuthorizeCore 这个方法的返回结果有关系.
又百度了一下. AuthorizeCore 这个方法干啥用的. (解释一下,代码是别人写的.网上开源的.)
这篇文章
http://www.tuicool.com/articles/yuUzeq
AuthorizeCore 这个方法直接 return false; 以后会跳转到 web.config 中
<system.web> <authentication mode="Forms"> <forms loginUrl="~/Account/Login" timeout="2880" /> </authentication></system.web>
loginurl指定的 的网址.
我的配置是 <forms loginUrl="~/JiMu/Index/Login"
于是我启动调试,看看有没有进入这个action
输入网址 /JiMu/Index/Login
结果是首先进入了AuthorizeCore 这个方法,然后return false 以后就直接报错了.
都没有进入. /JiMu/Index/Login 这个方法.
我就想了,我是要进入登录页面的 ,既然要登录肯定不能进入 AuthorizeCore 这个验证方法.
要跳过所有对 login这个登录路径的验证.. 否则死循环.用户无法登录..
到这里我突然间就想起来了.
我之前好像删过, [AllowAnonymous] 这种标签..
回去一检查代码..TMD真想骂死自己...
手贱把[AllowAnonymous]这个属性删掉了... 这个属性去掉以后,就会自动运行到AuthorizeCore 函数里面
[HttpPost] [AllowAnonymous] public ActionResult Login(LoginModel item, string RedirectTo) { ///..... }
导致报401.0这个错误.... 转了一大圈,学了一大圈,最后问题竟然是自己手贱造成的...
如果这篇文章对你帮助,那么请施舍点包子钱吧.. 在下支付宝号:273082449@qq.com
这几天有人向我要我的配置.我贴一下.
<?xml version="1.0" encoding="utf-8"?><!-- 有关如何配置 ASP.NET 应用程序的详细信息,请访问 http://go.microsoft.com/fwlink/?LinkId=169433 --><configuration> <configSections> <sectionGroup name="elmah"> <section name="security" requirePermission="false" type="Elmah.SecuritySectionHandler, Elmah" /> <section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah" /> <section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler, Elmah" /> <section name="errorFilter" requirePermission="false" type="Elmah.ErrorFilterSectionHandler, Elmah" /> </sectionGroup> <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> </configSections> <connectionStrings> </connectionStrings> <appSettings> <add key="webpages:Version" value="2.0.0.0" /> <add key="webpages:Enabled" value="false" /> <add key="PreserveLoginUrl" value="true" /> <add key="ClientValidationEnabled" value="true" /> <add key="UnobtrusiveJavaScriptEnabled" value="true" /> </appSettings> <!-- 有关 .NET 4.5 的 web.config 更改的说明,请参见 http://go.microsoft.com/fwlink/?LinkId=235367。 可在 <httpRuntime> 标记上设置以下特性。 <system.Web> <httpRuntime targetFramework="4.5" /> </system.Web> --> <system.web> <httpRuntime requestValidationMode="2.0" /> <pages controlRenderingCompatibilityVersion="4.0"> <namespaces> <add namespace="System.Web.Helpers" /> <add namespace="System.Web.Mvc" /> <add namespace="System.Web.Mvc.Ajax" /> <add namespace="System.Web.Mvc.Html" /> <add namespace="System.Web.Routing" /> <add namespace="System.Web.WebPages" /> <add namespace="System.Linq" /> <add namespace="System.Data" /> </namespaces> </pages> <httpModules> <!--<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" /> <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" /> <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" />--> </httpModules> <compilation debug="true" targetFramework="4.5"> <assemblies> <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> </assemblies> </compilation> </system.web> <system.webServer> <validation validateIntegratedModeConfiguration="false" /> <handlers> <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" /> <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" /> <remove name="ExtensionlessUrlHandler-Integrated-4.0" /> <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" /> <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" /> <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" /> <add name="elmah" verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" /> </handlers> <modules runAllManagedModulesForAllRequests="true"> <!--<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" preCondition="managedHandler" /> <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" preCondition="managedHandler" /> <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" preCondition="managedHandler" />--> </modules> <urlCompression doStaticCompression="false" /> </system.webServer> <elmah> <security allowRemoteAccess="true" /> <errorLog type="Elmah.XmlFileErrorLog, Elmah" logPath="~/App_Data/Elmah.Errors" /> </elmah> <entityFramework> <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework"> <parameters> <parameter value="v11.0" /> </parameters> </defaultConnectionFactory> </entityFramework> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="System.Web" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Data" publicKeyToken="b77a5c561934e089" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Configuration" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="EntityFramework.MappingAPI" publicKeyToken="7ee2e825d201459e" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-5.0.0.9" newVersion="5.0.0.9" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" /> </dependentAssembly> </assemblyBinding> </runtime></configuration>
- HTTP 错误 401.0 - Unauthorized 的解决方案
- HTTP 错误 401.0 - Unauthorized 的解决方案
- HTTP 错误 401.2 - Unauthorized
- HTTP Error 401.2 - Unauthorized iis7 错误
- win7 iis7 HTTP 错误 401.3 - Unauthorized
- HTTP 401 Unauthorized错误--路由器页面获取
- HTTP 401 错误 - 未授权: (Unauthorized)
- win7 iis7 HTTP 错误 401.3 - Unauthorized
- 关于win10 php环境配置后运行php文件出现HTTP 错误 401.3 - Unauthorized的解决方法
- IIS 8.0~10.0 详细错误 - HTTP 错误 401.2 - Unauthorized 解决方法
- 关于报urllib2.HTTPError: HTTP Error 401: Unauthorized错误问题
- Python模拟HTTPS请求返回HTTP 401 unauthorized错误
- Python模拟HTTPS请求返回HTTP 401 unauthorized错误
- 引用部署在IIS里的WebService时,解决“请求因 HTTP 状态 401 失败: Unauthorized。”的错误
- 解决手机unauthorized错误
- HTTP错误500.19解决方案
- Android问题集锦之十五:可笑的unauthorized错误
- (OK) adb 连接错误【error: device unauthorized】的解决
- linux系统信息查询: 内核版本,分支(发行版)名称,位数,cpu信息等
- WordPress实践功能
- 如何使用maven下载阅读源代码
- iOS启动画面
- @Repository、@Service、@Controller 和 @Component
- HTTP 错误 401.0 - Unauthorized 的解决方案
- android 随笔——队列、同步、锁
- 减少报表隐藏单元格提升报表性能
- 好记性不如烂笔头47-java拦截器-用CGLib实现动态代理(2)
- find . -name "*ab*" -exec rm -f {}\;
- java竞争对手及各自优势
- Tomcat内存修改
- System.map符号表
- 每天一点数据库之-----Day 5 过滤查询