Response.Write("你无权访问!");Response.Redirect("login.aspx");
本帖最后由 hutao1101175783 于 2012-12-02 00:28:50 编辑 Response.Write("<script type='text/javascript'>alert('你无权访问')</script>");Response.Redirect("login.aspx");
这两句在一起,为什么第一句执行不了,。。。。有什么办法让两句都执行。。。
[最优解释]
要了解原因,因为执行Reponse.Redirect的时候,其实内部会做一步Response.Clear的操作,所以你原来的Response.Write中的信息将会被清空,然后再输出一个响应码301,浏览器看到是301就做了重定向了
[其他解释]
up+
[其他解释]
Response.Write("<script language=javascript>alert('你无权访问!')</script>");
Response.Write("<script language=javascript>window.location.href='login.aspx'</script>");
[其他解释]
顺便说一句,如果是你在Page中的话,最好不要用Respnse.Write来操作,因为它会将信息输出到最前面,也就是在<html>标签的前面,而这时不符合标准的html规范的,还是用Page自带的注册脚本的比较好
[其他解释]
第二句是服务端语言
服务端语言执行完才返回给客户端执行js
[其他解释]
Response.Redirect("login.aspx")是告诉浏览器直接跳转,所以不会再生成html页面了
[其他解释]
该回复于2012-12-08 14:12:25被管理员删除
[其他解释]
Response.Write("<script language=javascript>alert('你无权访问!');location.href='login.aspx'</script>");
[其他解释]
第一句是执行了,执行了,然后你又跳转第二个页面了,在第一个页面是输出显示的,
你把那句写在第二个页面就可以了,不用后台输出就OK了
[其他解释]
你这个不对,第一句根本不会执行,因为Response.Redirect里面做了一步Clear的操作,之前所有的write都被清除
[其他解释]
执行的,你自己下代码去,试一下吧,断点就清楚了
[其他解释]
或者,你试一下,这一句也是
Response.Write("<script language=javascript>alert('你无权访问!')</script>");
Response.Write("<script language=javascript>window.location.href='login.aspx'</script>");
这个是浏览用JS跳转,你会看到执行的输入的,弹出窗“没权操作”
[其他解释]
哥,你这是不同概念啊,你没有用Redirect当然会输出了,如果你加了Redirect就不会输出了,
Redirect和window.location不是同一个概念,do you understand?,不了解的话用fiddler跟踪下
[其他解释]
//@CSMSDN,下面是跳转的源代码,你应该去了解下,
internal void Redirect(string url, bool endResponse, bool permanent)
{
if (url == null)
{
throw new ArgumentNullException("url");
}
if (url.IndexOf('\n') >= 0)
{
throw new ArgumentException(SR.GetString("Cannot_redirect_to_newline"));
}
if (this._headersWritten)
{
throw new HttpException(SR.GetString("Cannot_redirect_after_headers_sent"));
}
Page page = this._context.Handler as Page;
if ((page != null) && page.IsCallback)
{
throw new ApplicationException(SR.GetString("Redirect_not_allowed_in_callback"));
}
url = this.ApplyRedirectQueryStringIfRequired(url);
url = this.ApplyAppPathModifier(url);
url = this.ConvertToFullyQualifiedRedirectUrlIfRequired(url);
url = this.UrlEncodeRedirect(url);
this.Clear();
if (((page != null) && page.IsPostBack) && (page.SmartNavigation && (this.Request["__smartNavPostBack"] == "true")))
{
this.Write("<BODY><ASP_SMARTNAV_RDIR url=\"");
this.Write(HttpUtility.HtmlEncode(url));
this.Write("\"></ASP_SMARTNAV_RDIR>");
this.Write("</BODY>");
}
else
{
this.StatusCode = permanent ? 0x12d : 0x12e;
this.RedirectLocation = url;
if ((((url.IndexOf(":", StringComparison.Ordinal) == -1)
[其他解释]
url.StartsWith("http:", StringComparison.OrdinalIgnoreCase))
[其他解释]
(url.StartsWith("https:", StringComparison.OrdinalIgnoreCase)
[其他解释]
url.StartsWith("ftp:", StringComparison.OrdinalIgnoreCase)))
[其他解释]
url.StartsWith("news:", StringComparison.OrdinalIgnoreCase)))
{
url = HttpUtility.HtmlAttributeEncode(url);
}
else
{
url = HttpUtility.HtmlAttributeEncode(HttpUtility.UrlEncode(url));
}
this.Write("<html><head><title>Object moved</title></head><body>\r\n");
this.Write("<h2>Object moved to <a href=\"" + url + "\">here</a>.</h2>\r\n");
this.Write("</body></html>\r\n");
}
this._isRequestBeingRedirected = true;
EventHandler redirecting = Redirecting;
if (redirecting != null)
{
redirecting(this, EventArgs.Empty);
}
if (endResponse)
{
this.End();
}
}
[其他解释]
(url.StartsWith("file:", StringComparison.OrdinalIgnoreCase)
[其他解释]
同意~!
[其他解释]
页面提示定时跳转
直接拷贝以下一句,替换你原先的那2句即可
ClientScript.RegisterClientScriptBlock(GetType(), "", "<script>alert(/'你无权访问!/');setTimeout(function(){location.href='login.aspx'},1000); </script>");
[其他解释]
alert不爽,直接用js输出文本,然后定个时跳转过去
[其他解释]
Response.Write("<script language=javascript>alert('无权访问!');location.href='xxx.aspx';</script>");
[其他解释]
我建议楼主用这位同学的这句。 在alert后,setTimeout执行一个function.
[其他解释]
Response.Write("<script>alert('你无权访问!')</script>");
[其他解释]
Response.Write("<script language=javascript>alert('你无权访问!');window.location.href='login.aspx'</script>");
[其他解释]
C# 代码的执行顺序是点服务器端代码而后才会执行客户端代码的
你的第一句代码 是输出一段 客户端的javascript脚本 而第二句是服务器端的跳转 而第二句的时候 就跳走了,当然看不到执行效果
Response.Write("<script language=javascript>alert('你无权访问!');window.location.href='login.aspx'</script>");
把跳转连接加到alert之后就可以了
[其他解释]
+1
[其他解释]
[其他解释]
Page.ClientScript.RegisterStartupScript(GetType(), "alertMsg", "window.alert('成功。');location.href='WebTop.aspx'", true);