c# - Request.IsAuthenticated even if database is empty -


in razor webapp, request.isauthenticated , websecurity.isauthenticated return true, if database empty, how can fix behavior?

  <?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>       <!-- 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> 

ok, found solution. created own 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;         }     } } 

and extended 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;         }     } } 

Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -