Click here to Skip to main content
15,938,448 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
there is a downloadable link one of my website page which is in "test.html". i want to give them permission who are only registered with my website. i m creating a copy of test.html and that is "test.aspx". when someone clicked any of the downloadable link in "test.html" it redirects user to the "test.aspx" page. here i do some trick; on its page load event i hv checked whether the user is registered or not using session. if registered redirect the user to test.aspx page and when the user click any of the downloadable link they can download automatically. but those who are not registered redirect to the "register.aspx" page. now here i want to show that user a message and then redirect to the "register.aspx" page.
when i am writing this following code
Response.Redirect("register.aspx");
message box is not shown...

hope i may explain my problem properly. can anyone suggest me how to overcome this situation
Posted
Comments
sahabiswarup 1-Nov-11 7:29am    
i have found a link where session is passed through javascript.
http://bytes.com/topic/asp-net/answers/327477-can-you-access-session-variables-client-side-script
is it helpful?

Do not use Response.Redirect if you want the user to see anything. Response.Redirect sends a HTTP 303 (I think, maybe a 302) header which causes the browser to immediately request the redirection target – anything you run in the page content will not even be parsed. (Though it's valid to put content in a 30x response, it will only be read by very primitive HTTP clients or people using a telnet type connection to test things.)

You should have a startup script in the page that sets a timer, and some text that explains what's going to happen ... something like
<h2>Not Logged In</h2>
<p>You are not logged in, and will shortly be redirected to a login page. <a href="login.aspx">Click here to log in<a> or <a href="register.aspx">here to register a new account>.</p>

<script>setTimeout(5000, 'window.location = "login.aspx"');</script>


However, remember that the standard ASP.net roles and access masks in web.config will handle this quite gracefully for you already (for example I believe it automatically redirects back to the page you were looking at if you log in). The default approach should be to set up the roles in your web.config file correctly.
 
Share this answer
 
You can use query string from test.html and on preinit event of test.aspx page you can check whether the user is registered or not.

If user is registered then go ahead otherwise display message on test.aspx that you are not registered user and will be redirected for registration. Then redirect user to register.aspx after 5-10 secs.
 
Share this answer
 
Comments
sahabiswarup 1-Nov-11 7:34am    
i did that u told;

if (Session["SessionId"] == null)
{
cls.MsgBox("please login", this.Page);
Response.Redirect("register.aspx");
}
public void MsgBox(string msg, Page form)
{
form.Controls.Add(new LiteralControl("<script language='javascript'> window.alert('" + msg.Replace("'", "\\'") + "')</script>"));
}

but without displaying message it redirects to "register.aspx"
user ClientScript.RegisterStartupScript() method to add javascript functions to your page, you can also add alert message text inside this method.
 
Share this answer
 
Comments
sahabiswarup 1-Nov-11 7:34am    
can you please explain.

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