注册页面保持重定向到ASP.NET C#中的登录页面 [英] Register page keeps redirecting to Login page in ASP.NET C#

查看:61
本文介绍了注册页面保持重定向到ASP.NET C#中的登录页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只有在我的Web.config文件中配置了身份验证时才会发生这种情况。我需要这个才能登录。但是如何停止此重定向?



Web.config

< pre lang =HTML> < 身份验证 mode = 表格 < span class =code-keyword>>
< 表格 loginUrl = 〜/ Login.aspx

name = .ASPXFORMSAUTH / >
< / authentication >
< 授权 >
< deny 用户 = / >
< / authorization >





这里是我得到的URL:



http:// localhost:49575 /(S(teuci1cr4nob5isksiq5rsf))/ LOGin.aspx?ReturnUrl=%2fRegister.aspx

解决方案

这是因为服务器会尝试让用户从您指定的位置的唯一页面登录。



有两种方法可以最大限度地减少问题。第一种解决方案是在同一页面上提供注册和登录表单。这样,您只需创建一个页面,用户就可以注册或从同一页面登录。如果你想坚持使用这个web.config工作方法,将使用它。



但是,其他方法是使用WebSecurity类并使用其IsAuthenticated属性来确定用户是否登录,然后重定向他。您还可以确定用户所在的页面(注册或登录;如果他正在登录或注册,则不要重定向,否则将其重定向到登录或注册页面)然后让他通过简单的注册登录。像这样,



  if (!WebSecurity.IsAuthenticated){
// 没有用户登录,
Response.Redirect( 〜/ Login.aspx);
}





这样就可以了。我个人希望使用第二种方法来检查代码隐藏中的用户的值和状态。


This only ever happens when I have authentication configured in my Web.config file. I need this for logging in. However how do I stop this redirect?

Web.config

<authentication mode="Forms">
      <forms loginUrl="~/Login.aspx"

        name=".ASPXFORMSAUTH" />
    </authentication>
    <authorization>
      <deny users="?" />
    </authorization>



And here is the URL I get:

http://localhost:49575/(S(teuci1cr4nob5isksiq5rsf))/Login.aspx?ReturnUrl=%2fRegister.aspx

解决方案

This is because the server would try to let the user login from this only page of whose location you've specified.

There are two ways, to minimize the problem. First solution is to provide a register and login form on the same page. This way, you can just create a single page and the user would be able to register, or login from the same page. This will be used if you want to stick to this web.config method of working.

However, other method is using the WebSecurity class and using its IsAuthenticated property to determine whether user is logged in or not and then redirect him. You will also be able to determine which page the user is on (register or login; if he is on login or register then do not redirect, otherwise redirect him to the login or register page) and then just let him login by a simple register. Like this,

if(!WebSecurity.IsAuthenticated) {
   // No user logged in, 
   Response.Redirect("~/Login.aspx");
}



This would do the trick. I would personally like to use the second method of checking the values and state of users in the code-behind.


这篇关于注册页面保持重定向到ASP.NET C#中的登录页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆