在ASP页面中显示消息框 [英] Display message box in an asp page

查看:42
本文介绍了在ASP页面中显示消息框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站页面之一"test.html"中有一个可下载的链接.我想给他们只在我的网站上注册的权限.我正在创建一个test.html的副本,即"test.aspx".当有人单击"test.html"中的任何可下载链接时,它将用户重定向到"test.aspx"页面.在这里,我做一些把戏;在其页面加载事件中,我会检查用户是否已使用会话注册.如果注册,则将用户重定向到test.aspx页,并且当用户单击任何可下载的链接时,他们都可以自动下载.但是未注册的用户将重定向到"register.aspx"页面.现在在这里,我想向该用户显示一条消息,然后重定向到"register.aspx"页面.
当我编写以下代码时
Response.Redirect("register.aspx");
消息框未显示...

希望我能正确解释我的问题.谁能建议我如何克服这种情况?

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

推荐答案

不要使用Response.Redirect,如果您希望用户看到任何东西. Response.Redirect发送HTTP 303(我认为,也许是302)标头,该标头使浏览器立即请求重定向目标-您在页面内容中运行的任何内容都将不会被解析. (尽管将内容放入30倍的响应中是有效的,但只有非常原始的HTTP客户端或使用telnet类型的连接来测试内容的人才能读取内容.)

您应该在页面中有一个设置计时器的启动脚本,以及一些解释将要发生的事情的文本...类似
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>



但是,请记住,web.config中的标准ASP.net角色和访问掩码将为您已经很好地处理此问题(例如,我相信它会在您登录时自动重定向回您正在查看的页面).默认方法应该是正确设置web.config文件中的角色.



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.


您可以使用来自test.html的查询字符串,并且可以在test.aspx页面的preinit事件中检查用户是否已注册.

如果已注册用户,请继续进行操作,否则在test.aspx上显示消息,您不是注册用户,将被重定向以进行注册.然后在5-10秒后将用户重定向到register.aspx.
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.


user ClientScript.RegisterStartupScript()方法可向页面添加javascript函数,您也可以在此方法内添加警报消息文本.
user ClientScript.RegisterStartupScript() method to add javascript functions to your page, you can also add alert message text inside this method.


这篇关于在ASP页面中显示消息框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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