c# - ASP.NET MVC - Request.IsAuthenticated is always false -
i'm writing simple login page in asp.net mvc where, if user logged in, displays specific view. problem request.isauthenticated
returns false
. i've tried solutions explained in other answers it's still false.
here web.config:
<configuration> <configsections> <sectiongroup name="system.web.webpages.razor" type="system.web.webpages.razor.configuration.razorwebsectiongroup, system.web.webpages.razor, version=3.0.0.0, culture=neutral, publickeytoken=xxx"> <section name="host" type="system.web.webpages.razor.configuration.hostsection, system.web.webpages.razor, version=3.0.0.0, culture=neutral, publickeytoken=xxx" requirepermission="false" /> <section name="pages" type="system.web.webpages.razor.configuration.razorpagessection, system.web.webpages.razor, version=3.0.0.0, culture=neutral, publickeytoken=xxx" requirepermission="false" /> </sectiongroup> </configsections> <system.web.webpages.razor> <host factorytype="system.web.mvc.mvcwebrazorhostfactory, system.web.mvc, version=5.2.3.0, culture=neutral, publickeytoken=xxx" /> <pages pagebasetype="system.web.mvc.webviewpage"> <namespaces> <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" /> </namespaces> </pages> </system.web.webpages.razor> <appsettings> <add key="webpages:enabled" value="false" /> </appsettings> <system.webserver> <modules> <remove name="formsauthenticationmodule" /> </modules> <handlers> <remove name="blockviewhandler"/> <add name="blockviewhandler" path="*" verb="*" precondition="integratedmode" type="system.web.httpnotfoundhandler" /> </handlers> </system.webserver> <system.web> <compilation> <assemblies> <add assembly="system.web.mvc, version=5.2.3.0, culture=neutral, publickeytoken=xxx" /> </assemblies> </compilation> </system.web> </configuration>
in controller, set authentication value true following command:
formsauthentication.setauthcookie(cvm.username, false);
but in view if check value of request.isauthenticated
, it's false.
how can resolve problem?
if using mvc 5, formsauthentication module, removed in web.config.
remove line.
if doesn't work, try writing:
<remove name="formsauthentication" /> <add name="formsauthentication" type="system.web.security.formsauthenticationmodule" />
Comments
Post a Comment