方法中不使用该方法时如何退出方法

发布于 2024-08-04 00:36:38 字数 709 浏览 1 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

娜些时光,永不杰束 2024-08-11 00:36:38

LoginCheck 返回一个指示成功或失败的布尔值,如下所示:

protected Boolean LoginCheck()
{
    if (Session["Login_Status"] == null || Session["Login_Status"] == "false")
    {
        MessageBoxShow("Please Login!");
        return false;
    }
    return true;
}

然后您可以使用该值来确定是否执行其他操作,如下所示:

protected void Button1_Click(object sender, EventArgs e)
{
    if (LoginCheck()) 
    {
        Session.RemoveAll();
        Button1.PostBackUrl = "~/Default.aspx";
        Response.Redirect("~/Default.aspx");
    }
}

Have LoginCheck return a boolean value indicating success or failure like this:

protected Boolean LoginCheck()
{
    if (Session["Login_Status"] == null || Session["Login_Status"] == "false")
    {
        MessageBoxShow("Please Login!");
        return false;
    }
    return true;
}

Then you can use that value to determine whether or not to do anything else like this:

protected void Button1_Click(object sender, EventArgs e)
{
    if (LoginCheck()) 
    {
        Session.RemoveAll();
        Button1.PostBackUrl = "~/Default.aspx";
        Response.Redirect("~/Default.aspx");
    }
}
蓝眸 2024-08-11 00:36:38

我认为这就是你想要的(但这不是一个好主意):

protected void LoginCheck()
{
    if (Session["Login_Status"] == null || Session["Login_Status"] == "false")
    {
        MessageBoxShow("Please Login!");
        Response.End();
    }
}

I think this is what you want (but it's not that good of an idea):

protected void LoginCheck()
{
    if (Session["Login_Status"] == null || Session["Login_Status"] == "false")
    {
        MessageBoxShow("Please Login!");
        Response.End();
    }
}
如痴如狂 2024-08-11 00:36:38

这是一个坏主意

如果有人正在阅读您的代码,他们会假设在 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(...)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文