0

ログインページが 1 つあり、ユーザーはそのページに初めてログインするときに任意のマシンを使用できます。ユーザーが初めてログインしたら、そのユーザーが別のマシンにログインしないように制限する必要があります。そのため、ユーザーは初回ログイン時に使用するマシンを 1 つだけ使用する必要があります。

クライアント側の MAC アドレスを取得しようとしましたが、Web サイトでクライアント側の MAC アドレスを取得できません。マシンを一意に識別する他の方法はありますか?

4

3 に答える 3

1

asp.net の場合、クライアントの MAC アドレスを取得することはできません。そのためには、ユーザーのシステムで実行されるある種の Windows アプリケーションが必要です。

GUID を持つ永続的な Cookie も解決策になる場合があります。

別の解決策は、リクエストを行うときにサーバー変数を検索することです。 Request.ServerVariables["REMOTE_ADDR"]; アプリが内部/イントラネットの場合、これはおそらく内部 IP になります。REMOTE_HOST もあります。これらは、プロキシ/ファイアウォール/nat によってフィルター処理されることがありますが、状況によってはそうでないことを願っています。

それが役に立てば幸い!

于 2013-11-06T09:07:30.807 に答える
0

ユーザーがいつでも 1 つのセッションでのみ Web サイトにログインすることを望んでいると思います。問題は、ユーザーがログアウト ボタンを使用してログアウトしない場合、ユーザーがいつ退出したかを確実に知ることができないことです。これを修正するには、タイムアウトが必要です。アプリケーションでサーバー上のテキスト ファイルを使用しましたが、動作します。

ログインボタン:

    protected void btLogin_Click(object sender, EventArgs e)
    {
        if (check(txtPass.Text) && check(txtUser.Text))
        {
            var user = new UserManager().login(txtUser.Text, txtPass.Text);
            if (user != null)
            {
                // this is the test you're looking for, the rest is only context
                if (!FileManager.alreadyLoggedIn(user.email))
                {
                    FormsAuthentication.SetAuthCookie(user.email, false);
                }
                else
                {
                    //throw error that it is already connected in some other place
                }
            }
            else
            {
                    //throw error that login details are not OK
            }
        }
    }

クラス内の 2 つの静的メソッド:

    //you have to call this function at every request a user makes
    internal static void saveUserSessionID(string email)//email or any unique string to user
    {
        var dir = HostingEnvironment.MapPath("~/temp/UserSession/");// a folder you choose
        if (!Directory.Exists(dir))
        {
            Directory.CreateDirectory(dir);
        }
        string path = dir + email + ".txt";
        File.WriteAllText(path, HttpContext.Current.Session.SessionID);
    }

    // if a request has not been made in tha last 4 minutes, the user left, closed the browser
    // the test checks this only on a real server, localhost is not tested to be easy for the developer
    internal static bool alreadyLoggedIn(string email)
    {
        var file = HostingEnvironment.MapPath("~/temp/UserSession/" + email + ".txt");
        return File.Exists(file) && File.GetLastWriteTime(file).AddMinutes(4) > DateTime.Now && !HttpContext.Current.Request.IsLocal;
    }

明らかに、これは別のアプリケーションからのものです。アイデアを取り入れて、独自のアプリケーションに実装することしかできません。コピペだけではいけません。

于 2013-11-06T09:35:50.197 に答える