Click here to Skip to main content
15,312,535 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
I developing one web application where i have three Page
1. login.aspx
2. Default.aspx
3. Default2.aspx
i have used form authentication
and my web.config file setting is like below
<authentication mode="Forms">
			<forms loginUrl="Login.aspx" cookieless="AutoDetect">
			</forms>
		</authentication>
		<authorization>
			<deny users="?" />
		</authorization>

i want request made to any page will take to login page if user is not authenticate.
after authentication it should go to Default1.aspx . This should happen alway if any
unauthenticated request is made to Default2.aspx. but its not happening if unauthenticated request is made to default2.aspx page it first takes to login.aspx and after successful authentication it take to default.aspx page which i don require
login logic is as follows
if ((UserEmail.Text == "jchen@contoso.com") &&
           (UserPass.Text == "37Yj*99Ps"))
            {
                FormsAuthentication.RedirectFromLoginPage
                   (UserEmail.Text, Persist.Checked);
            }
            else
            {
                Msg.Text = "Invalid credentials. Please try again.";
            } 

if any unauthenticated request is made to default2.aspx the url show in address bar is http://localhost:3793/Login.aspx?ReturnUrl=%2fdefault2.aspx.
i want to url come only http://localhost:3793/login.aspx even if any unauthenticated request is made to default2.aspx
Posted
Updated 10-May-11 20:34pm
v2

First of all don't use

VB
FormsAuthentication.RedirectFromLoginPage


Instead u can set Defaulturl in your config file like.

XML
<forms loginUrl="Login.aspx" defaulturl="Login.aspx" cookieless="AutoDetect">
            </forms>



and on Your logout button don't use

C++
FormsAuthentication.RedirectToLoginPage


Instead u can use

MIDL
FormsAuthentication.SetAuthCookie(lblUserName.Text, false);
            Response.Redirect("Login.aspx", false);

Which solves ur url problem.

Hope it helps......
   
Comments
spydeehunk 11-May-11 3:49am
   
not working accordingly what i need
and else part (if any unauthenticated ) again you redirect to login.aspx instead of default2.aspx
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900