提前感谢您抽出宝贵时间提供帮助。
我的目标是,当有人访问我正在构建的网站的首页时,会将其转发到另一个页面(人们登录后会转到同一页面)
这是我的代码:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (HttpContext.Current.User.Identity.IsAuthenticated)
{
Response.Redirect("~/inside.aspx");
}
}
}
inside.aspx的c#代码目前为空。但是如果用户登录,我在浏览器中会出现重定向循环错误。我不知道为什么。
以下是我的web.config:
<configuration>
<system.web>
<!--<roleManager enabled="true" />-->
<authentication mode="Forms">
<forms loginUrl="default.aspx" defaultUrl="inside.aspx" />
</authentication>
<compilation debug="true" targetFramework="4.0"/>
<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="ApplicationServices" applicationName="/"/>
</providers>
</profile>
<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="ApplicationServices" 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="ApplicationServices"/>
</providers>
</sessionState>
<membership>
<providers>
<clear/>
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/"/>
</providers>
</membership>
</system.web>
<connectionStrings>
<add name="ApplicationServices" connectionString="Data Source=SERVERNAME;Initial Catalog=SCRUMAPIUI;User Id=tunnelld;Password=PASSWORD;" providerName="System.Data.SqlClient"/>
</connectionStrings>
</configuration>
我做错了什么?我为什么要获得重定向循环?如果用户已登录,如何才能将我网站的默认页面正确转发到另一个页面?
编辑:
以下是Chrome中显示的错误:
答案 0 :(得分:2)
我看到的循环是:
等
作为良好做法,请确保经过身份验证的用户不是匿名用户。这可能是你绊倒的原因。
您是否有可能使用IE 10进行测试?
答案 1 :(得分:1)
尝试将此添加到webconfig的配置部分..
<location path="default.aspx">
<system.web>
<authorization>
<allow users ="*" />
</authorization>
</system.web>
</location>
并将其添加到现有的结束</authentication>
标记下方,以防止访问任何其他网页,除非经过身份验证。
<authorization>
<deny users="?" />
</authorization>
答案 2 :(得分:0)
问题是两个文件的CodeFile引用是相同的。愚蠢的错误,但如果你有这个问题,一定要检查它!