【发布时间】:2013-01-17 13:51:46
【问题描述】:
我的 asp.net 会员授权有问题,我配置了我的主 web 配置如下:
<connectionStrings>
<add name="xxx" connectionString="Data Source=; Initial Catalog=; Integrated Security=;" providerName="System.Data.SqlClient" />
<remove name="LocalSqlServer"/>
<add name="LocalSqlServer"
connectionString="Data Source=; Initial Catalog=; Integrated Security=;"
providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<roleManager enabled="true" defaultProvider="MyProvider">
<providers>
<add name="MyProvider"
type="System.Web.Security.SqlRoleProvider"
connectionStringName="Devices"
applicationName="MembersTable" />
</providers>
</roleManager>
<membership defaultProvider="MyProvider">
<providers>
<add name="MyProvider"
type="System.Web.Security.SqlMembershipProvider"
connectionStringName="" />
</providers>
</membership>
<authentication mode="Forms">
<forms loginUrl="Denied.aspx" name=".ASPXFORMSAUTH"/>
</authentication>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>`
在指定文件夹中,我的 config 看起来像
<configuration>
<location>
<system.web>
<authorization>
<allow roles="role1"/>
<deny users="*" />
</authorization>
</system.web>
</location>
</configuration>
但登录后我无法访问文件夹文件,它会在Denied.aspx 页面返回我
我使用Membership.ValidateUser 方法验证用户并使用Response.Redirect 调用页面。这是否足够,或者我需要一种不同的方式来请求受保护的页面
if (
Membership.ValidateUser(this.txtUsername.Text, this.txtPassword.Text))
{
Response.Redirect("/tempUser/Role1Page.aspx");
}
else {
Response.Redirect("Denied.aspx");
}
【问题讨论】:
-
您是否验证了您的用户是该角色?
-
查看您的配置 - 会员用户和角色不是都有应用程序设置吗?从您的配置来看,您似乎只为角色提供者指定了 applicationName="MembersTable" 。 msdn.microsoft.com/en-us/library/… 表示会员提供者也有一个应用程序名称。
-
不,改了,但问题似乎是别的。
标签: asp.net c#-4.0 web-config asp.net-membership asp.net-roles