允许anonymus用户只能访问登录和注册页面 [英] Allow anonymus users to access only Login and Register page
本文介绍了允许anonymus用户只能访问登录和注册页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图让只有两页(login.aspx的和register.aspx)匿名用户可见,我已经能够使匿名用户只能访问login.aspx的和没有more..but我可以' ŧ使可register.aspx为好,任何提示?
这是我的web.config至今:
<结构>
< configSections>
<节名称=的EntityFrameworkTYPE =System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection,的EntityFramework,版本5.0.0.0 =文化=中性公钥= b77a5c561934e089requirePermission =FALSE/>
< / configSections>
<&是connectionStrings GT;
<添加名称=DefaultConnection的providerName =System.Data.SqlClient的的connectionString =数据源=(的LocalDB)\\ V11.0;初始目录= ASPNET-WebApplication18-20150319150910;集成安全性= SSPI; AttachDBFilename = | DataDirectory目录| \\ ASPNET-WebApplication18-20150319150910.mdf/>
< /&是connectionStrings GT;
<&的System.Web GT;
<编译调试=真targetFramework =4.5.1/>
<的httpRuntime targetFramework =4.5.1/>
<网页和GT;
<&命名空间GT;
<添加命名空间=System.Web.Optimization/>
< /命名空间>
<控制与GT;
<添加组件=Microsoft.AspNet.Web.Optimization.WebForms命名空间=Microsoft.AspNet.Web.Optimization.WebForms标签preFIX =webopt/>
< /控制>< /页>
<身份验证模式=表格>
<形式loginUrl =〜/帐号/登录超时=2880defaultUrl =〜//>
< /认证>
<授权>
<拒绝用户= /&gt的帮助?
< /授权>
<型材defaultProvider =DefaultProfileProvider>
<供应商>
<添加名称=DefaultProfileProviderTYPE =System.Web.Providers.DefaultProfileProvider,System.Web.Providers,版本= 1.0.0.0,文化=中性公钥= 31bf3856ad364e35的connectionStringName =DefaultConnection的applicationName =// >
< /供应商>
< / profile文件>
<会员defaultProvider =DefaultMembershipProvider>
<供应商>
<添加名称=DefaultMembershipProviderTYPE =System.Web.Providers.DefaultMembershipProvider,System.Web.Providers,版本= 1.0.0.0,文化=中性公钥= 31bf3856ad364e35的connectionStringName =DefaultConnectionenablePasswordRetrieval =false的enablePasswordReset设置=真requiresQuestionAndAnswer =假requiresUniqueEmail =假maxInvalidPasswordAttempts =5minRequiredPasswordLength =6minRequiredNonalphanumericCharacters =0passwordAttemptWindow =10的applicationName =//>
< /供应商>
< /会员>
< roleManager defaultProvider =DefaultRoleProvider>
<供应商>
<添加名称=DefaultRoleProviderTYPE =System.Web.Providers.DefaultRoleProvider,System.Web.Providers,版本= 1.0.0.0,文化=中性公钥= 31bf3856ad364e35的connectionStringName =DefaultConnection的applicationName =// >
< /供应商>
< / roleManager>
<的sessionState模式=是InProccustomProvider =DefaultSessionProvider>
<供应商>
<添加名称=DefaultSessionProviderTYPE =System.Web.Providers.DefaultSessionStateProvider,System.Web.Providers,版本= 1.0.0.0,文化=中性公钥= 31bf3856ad364e35的connectionStringName =DefaultConnection/>
< /供应商>
< /&的sessionState GT;
< /system.web>
<&运行GT;
< assemblyBinding的xmlns =瓮:架构 - 微软COM:asm.v1>
< dependentAssembly>
< assemblyIdentity名称=DotNetOpenAuth.Core公钥=2780ccd10d57b246/>
< bindingRedirect oldVersion =1.0.0.0-4.0.0.0NEWVERSION =4.1.0.0/>
< / dependentAssembly>
< dependentAssembly>
< assemblyIdentity名称=DotNetOpenAuth.AspNet公钥=2780ccd10d57b246/>
< bindingRedirect oldVersion =1.0.0.0-4.0.0.0NEWVERSION =4.1.0.0/>
< / dependentAssembly>
< / assemblyBinding>
< /运行>
<&的EntityFramework GT;
< defaultConnectionFactory TYPE =System.Data.Entity.Infrastructure.SqlConnectionFactory,的EntityFramework/>
< /&的EntityFramework GT;
< /结构>
解决方案
在您的帐户目录中创建另一个的web.config
文件,并应用以下
<位置路径=login.aspx的>
<&的System.Web GT;
<授权>
<让用户=*/>
< /授权>
< /system.web>
< /地点>
<位置路径=register.aspx>
<&的System.Web GT;
<授权>
<让用户=*/>
< /授权>
< /system.web>
< /地点>
更新
<结构>
<&的System.Web GT;
<身份验证模式=表格/>
<授权>
<拒绝用户= /&gt的帮助?
< /授权>
< /system.web><位置路径=〜/ YourFolder / Register.aspx>
<&的System.Web GT;
<授权>
<让用户=*/>
< /授权>
< /system.web>
< /地点><位置路径=〜/ YourFolder /的Login.aspx>
<&的System.Web GT;
<授权>
<让用户=*/>
< /授权>
< /system.web>
< /地点>
< /结构>
进一步阅读 <一个href=\"http://weblogs.asp.net/gurusarkar/setting-authorization-rules-for-a-particular-page-or-folder-in-web-config\"相对=nofollow>这里
I'm trying to make only two pages (login.aspx and register.aspx) visible to anonymous users, I've been able to make anonymous user to access only login.aspx and no more..but I can't make register.aspx available as well, any hints? This is my web.config so far:
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
<add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-WebApplication18-20150319150910;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-WebApplication18-20150319150910.mdf" />
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.5.1" />
<httpRuntime targetFramework="4.5.1" />
<pages>
<namespaces>
<add namespace="System.Web.Optimization" />
</namespaces>
<controls>
<add assembly="Microsoft.AspNet.Web.Optimization.WebForms" namespace="Microsoft.AspNet.Web.Optimization.WebForms" tagPrefix="webopt" />
</controls></pages>
<authentication mode="Forms">
<forms loginUrl="~/Account/Login" timeout="2880" defaultUrl="~/" />
</authentication>
<authorization>
<deny users="?"/>
</authorization>
<profile defaultProvider="DefaultProfileProvider">
<providers>
<add name="DefaultProfileProvider" type="System.Web.Providers.DefaultProfileProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" />
</providers>
</profile>
<membership defaultProvider="DefaultMembershipProvider">
<providers>
<add name="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
</providers>
</membership>
<roleManager defaultProvider="DefaultRoleProvider">
<providers>
<add name="DefaultRoleProvider" type="System.Web.Providers.DefaultRoleProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" />
</providers>
</roleManager>
<sessionState mode="InProc" customProvider="DefaultSessionProvider">
<providers>
<add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" />
</providers>
</sessionState>
</system.web>
<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>
</assemblyBinding>
</runtime>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
</entityFramework>
</configuration>
解决方案
In you account directory create another web.config
file and apply the following
<location path="login.aspx">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>
<location path="register.aspx">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>
Update
<configuration>
<system.web>
<authentication mode="Forms"/>
<authorization>
<deny users="?"/>
</authorization>
</system.web>
<location path="~/YourFolder/Register.aspx">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>
<location path="~/YourFolder/Login.aspx">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>
</configuration>
Further reading here
这篇关于允许anonymus用户只能访问登录和注册页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文