2

web.configのロールを使用せずに、asp.netのページへの直接アクセスを(完全なURLを入力して)拒否するにはどうすればよいですか? 私は使用しました:

if (Session.IsNewSession)
            Response.Redirect("Default.aspx");

それに関する問題は、最初はすべて問題なくリダイレ​​クトが機能していることですが、同じブラウザで新しいタブを開いてURLを再度入力すると失敗します。どうすれば解決できますか?ありがとう

4

2 に答える 2

3

これを試して:

ページ1

Context.Items.Add("somevar","someval");

ページ2

if ( Context.Items["somevar"] == null )
{
    // the page is not redirected from Page 1
}
于 2012-10-14T12:44:06.483 に答える
0

セッションを使用すると、この問題を解決できます。

HttpModule を構築し、 context_BeginRequest で現在の URL を取得できます。後で条件付きでデフォルト ページにリダイレクトします。

public class RedirectionModule : IHttpModule
{
    void context_BeginRequest(object sender, EventArgs e)
    {

        //this user already already eligible to go inside page ? 
        if (Session["eligible-to-go-inside"] == null)
        {
        //new user
        //check current request url is default.aspx
        //if not forward to  default page
        }

    }
}

default.aspx ページで、ユーザーが内部ページに移動するための要件を完全に満たしている場合 (ログインなど)、設定します。

Session["eligible-to-go-inside"] = "yes";
于 2012-10-14T12:58:41.017 に答える