2013-09-04 4 views
0

내 면도기 웹 애플리케이션에서 Request.IsAuthenticatedWebSecurity.IsAuthenticated은 항상 true를 반환합니다. 데이터베이스가 비어 있더라도이 동작을 어떻게 해결할 수 있습니까?Request.IsAuthenticated 데이터베이스가 비어 있더라도

<?xml version="1.0" encoding="utf-8"?> 
    <!-- 
    Weitere Informationen zum Konfigurieren der ASP.NET-Anwendung finden Sie unter 
    &quotehttp://go.microsoft.com/fwlink/?LinkId=169433. 
    --> 
    <configuration> 
    <configSections> 
     <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --> 
     <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> 
    </configSections> 
    <system.diagnostics> 
     <trace> 
     <listeners> 
      <add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=2.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="AzureDiagnostics"> 
      <filter type="" /> 
      </add> 
     </listeners> 
     </trace> 
    </system.diagnostics> 
    <connectionStrings> 
     <add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-Coding.Lizards.Video.Manager.Web-20130903001018;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-Coding.Lizards.Video.Manager.Web-20130903001018.mdf" providerName="System.Data.SqlClient" /> 
     <add name="WebsiteModel" connectionString="metadata=res://*/Models.WebsiteModel.csdl|res://*/Models.WebsiteModel.ssdl|res://*/Models.WebsiteModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=(LocalDb)\v11.0;attachdbfilename=|DataDirectory|\aspnet-Coding.Lizards.Video.Manager.Web-20130903001018.mdf;initial catalog=aspnet-Coding.Lizards.Video.Manager.Web-20130903001018;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" /> 
    </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> 
    <system.web> 
     <compilation debug="true" targetFramework="4.5"> 
     <assemblies> 
      <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> 
     </assemblies> 
     </compilation> 
     <httpRuntime targetFramework="4.5" /> 
     <authentication mode="Forms"> 
     <forms loginUrl="~/Account/Login" timeout="2880" /> 
     </authentication> 
     <pages> 
     <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.Optimization" /> 
      <add namespace="System.Web.Routing" /> 
      <add namespace="System.Web.WebPages" /> 
     </namespaces> 
     </pages> 
    </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" /> 
     </handlers> 
    </system.webServer> 
    <runtime> 
     <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
     <dependentAssembly> 
      <assemblyIdentity name="DotNetOpenAuth.Core" publicKeyToken="2780ccd10d57b246" /> 
      <bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.1.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
      <assemblyIdentity name="DotNetOpenAuth.AspNet" publicKeyToken="2780ccd10d57b246" /> 
      <bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.1.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
      <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" /> 
      <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
      <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" /> 
      <bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.0.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
      <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" /> 
      <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
      <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" /> 
      <bindingRedirect oldVersion="1.0.0.0-1.3.0.0" newVersion="1.3.0.0" /> 
     </dependentAssembly> 
     </assemblyBinding> 
    </runtime> 
    <entityFramework> 
     <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework"> 
     <parameters> 
      <parameter value="v11.0" /> 
     </parameters> 
     </defaultConnectionFactory> 
    </entityFramework> 
    </configuration> 
+1

IMO 이는 귀하가 데이터베이스가 아니라 WebServer에서 인증되었음을 의미합니다. – Dannydust

+0

그래, 어떻게이 행동을 바꿀 수 있니? – Knerd

+0

성취하고자하는 바를 잘 이해하고 있는지 확신 할 수 없습니다. 당신은 : "데이터베이스가 비어 있더라도 항상 true를 반환합니다" 나는 정말로 이해하지 못한다. 왜냐하면 인증은 아무 관련이 없기 때문이다. 데이터베이스는 비어있을 수 있으며 성공적으로 연결하고 인증 할 수 있습니다. – Dannydust

답변

0

좋아, 해결책을 찾았습니다. 내 자신의 AuthorizeAttribute를 만들었습니다.

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.Mvc; 
using WebMatrix.WebData; 

namespace Coding.Lizards.Video.Manager.Web.Filters { 
    public class CustomAuthorizeAttribute : AuthorizeAttribute { 
     protected override bool AuthorizeCore(HttpContextBase httpContext) { 
      if (WebSecurity.UserExists(httpContext.User.Identity.Name)) 
       return true; 
      return false; 
     } 
     protected override HttpValidationStatus OnCacheAuthorization(HttpContextBase httpContext) { 
      if (WebSecurity.UserExists(httpContext.User.Identity.Name)) 
       return HttpValidationStatus.Valid; 
      return HttpValidationStatus.Invalid; 
     } 
    } 
} 

그리고 HttpRequestBase가 확장되었습니다.

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using WebMatrix.WebData; 

namespace Coding.Lizards.Video.Manager.Web.Filters { 
    public static class RequestExtensions { 
     public static bool IsAuthenticated(this HttpRequestBase request) { 
      if (WebSecurity.UserExists(request.RequestContext.HttpContext.User.Identity.Name)) 
       return true; 
      return false; 
     } 
    } 
} 
관련 문제