方法中不使用该方法时如何退出方法
protected void LoginCheck()
{
if (Session["Login_Status"] == null || Session["Login_Status"] == "false")
{
MessageBoxShow("Please Login!");
}
}
protected void Button1_Click(object sender, EventArgs e)
{
LoginCheck();
Session.RemoveAll();
Button1.PostBackUrl = "~/Default.aspx";
Response.Redirect("~/Default.aspx");
}
如何不处理
Session.RemoveAll();
Button1.PostBackUrl = "~/Default.aspx";
Response.Redirect("~/Default.aspx");
Login false时
我如何编写这个程序以不使用 条件 if (LoginCheck()) { }。我希望它像这样工作 php: php 退出;功能?
protected void LoginCheck()
{
if (Session["Login_Status"] == null || Session["Login_Status"] == "false")
{
MessageBoxShow("Please Login!");
}
}
protected void Button1_Click(object sender, EventArgs e)
{
LoginCheck();
Session.RemoveAll();
Button1.PostBackUrl = "~/Default.aspx";
Response.Redirect("~/Default.aspx");
}
how to not process
Session.RemoveAll();
Button1.PostBackUrl = "~/Default.aspx";
Response.Redirect("~/Default.aspx");
when Login false
how do I code this program not to use a
condition if (LoginCheck()) { }. I'd like it to work like
php:
php exit; function ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
让
LoginCheck
返回一个指示成功或失败的布尔值,如下所示:然后您可以使用该值来确定是否执行其他操作,如下所示:
Have
LoginCheck
return a boolean value indicating success or failure like this:Then you can use that value to determine whether or not to do anything else like this:
我认为这就是你想要的(但这不是一个好主意):
I think this is what you want (but it's not that good of an idea):
这是一个坏主意
如果有人正在阅读您的代码,他们会假设在 Logincheck() 之后将调用 Session.RemoveAll() ...。如果您在 LoginCheck 中做了一些改变,那么阅读 Button_Click1(...) 将会非常令人困惑
This is a bad idea
If some one is reading your code, they are going to assume that after Logincheck() that Session.RemoveAll() ... will be called. If you do some trick in LoginCheck that changes that it will be very confusing reading Button_Click1(...)