如何在注册后将新用户重定向到主页 [英] how to redirect a new user after registration to the home page

查看:95
本文介绍了如何在注册后将新用户重定向到主页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在表单身份验证中如何在创建用户后转到主页。在用户填写表单进行注册并点击确定后,不应将用户重定向到登录页面,保存值并将用户重定向到主页。

解决方案

< blockquote>

 <   authentication     mode   = 表格 >  

< 表格 名称 = 检查 defaultUrl = default.aspx loginUrl = login.aspx > < / forms >
< / authentication >





用户输入有效数据并存储在数据库中后。

在你的代码隐藏中使用这个



 FormsAuthentication.RedirectFromLoginPage( 发送您的用户名 false ); 





一般来说,它会从登录页面重定向,如果没有,你可以在你的注册页面中使用它。



试试这个有效。


用户单击确定按钮后,验证用户输入的值。



然后在数据库中插入用户条目。

如果用户条目已成功插入

将用户重定向到主页
其他
重定向到注册页面





代码可能像下面...

 int rowaffected =INSERT INTO Users Values(''UserName'',''Password''); 

//此处执行查询的代码

if(rowaffected> = 1)
{
Responce.Redirect(Home.aspx) ;
}
其他
{
Responce.Redirect(Register.aspx);
}


 response.redirect(  HomePage.aspx); 


In Form Authentication how to go to home page after creating a user. it should not redirect the user to login page after the a user fills in the form for registration and clicks on ok the values are saved and the user is redirected to homepage.

解决方案

<authentication mode="Forms">

      <forms name="Check" defaultUrl="default.aspx" loginUrl="login.aspx"></forms>
    </authentication>



After user enters valid data and stored in database.
in your codebehind use this

FormsAuthentication.RedirectFromLoginPage("Send Your UserName", false);



Generally, it redirects from login page if not you can use it in your registration page.

try this it works.


Once the user click on OK button, then validate user entered value.

Then insert the user entry in database.

if the user entry is successfully inserted, 
then 
    redirect user to Home page, 
else 
    redirect to Register page



Code may be like below...

int rowaffected = "INSERT INTO Users Values (''UserName'', ''Password'')";

//code here to execute query

if(rowaffected >= 1)
{
    Responce.Redirect("Home.aspx");
}
else
{
    Responce.Redirect("Register.aspx");
}


response.redirect("HomePage.aspx");


这篇关于如何在注册后将新用户重定向到主页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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