通过URL修改限制直接URL访问。 [英] Restrict Direct URL Access by URL Modification.

查看:246
本文介绍了通过URL修改限制直接URL访问。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



需要你的帮助,问题如下。



我想要限制直接网址访问当任何人试图通过在浏览器的地址栏中输入直接网址来访问页面



谢谢....

Hi Guys,

Need your help, the problem is as follows.

I want to restrict the direct url access when anybody tries to

access the pages by typing the direct url in the address bar of the browser

Thanks....

推荐答案



//Global.asax

Hi,
//Global.asax
public class Global : System.Web.HttpApplication
{
        public static int value = 0;
       // all other functions....
}



假设您在Menu.aspx页面中有链接。


Suppose you have your links in Menu.aspx page.

<form id="form1" runat="server">
    <div>
        <asp:hyperlink id="hyp" runat="server" navigateurl="~/Check.aspx" text="Clickme" onclick="redirect(event,this)" xmlns:asp="#unknown"></asp:hyperlink>
        <asp:hyperlink id="hyp1" runat="server" navigateurl="~/Check1.aspx" text="Clickme1" onclick="redirect(event,this)" xmlns:asp="#unknown"></asp:hyperlink>
        <asp:hyperlink id="hyp2" runat="server" navigateurl="~/Check2.aspx" text="Clickme2" onclick="redirect(event,this)" xmlns:asp="#unknown"></asp:hyperlink>
    </div>
    <script type="text/javascript">
        function redirect(e,a) {
            e.preventDefault();
            var url = a.href;


.ajax({
type: POST
url: < span class =code-string> Menu.aspx / SetValue,
data: {'网址':' +网址+ '}
contentType: application / json; charset = utf-8
dataType: json
成功: function (data){
window location .assign(url);
},
失败:功能(数据){
}
});
}
< / 脚本 >
< / form >
.ajax({ type: "POST", url: "Menu.aspx/SetValue", data: "{ 'URL': '" + url + "' }", contentType: "application/json; charset=utf-8", dataType: "json", success: function (data) { window.location.assign(url); }, failure: function (data) { } }); } </script> </form>



//现在你的代码落后


// now your code behind

[WebMethod]
        public static void SetValue(string URL)
        {
            string path = new Uri(URL).AbsolutePath;
            // set global value according to redirect url
            switch (path)
            { 
                case "/Check.aspx":
                    Global.value = 1;
                    break;
                case "/Check1.aspx":
                    Global.value = 2;
                    break;
                case "/Check2.aspx":
                    Global.value = 3;
                    break;
            }
        }



//在此示例中您重定向到页面之一假设Check.aspx


// one of your redirect to page in this example suppose Check.aspx

protected void Page_Load(object sender, EventArgs e)
       {
           if (!IsPostBack)
           {
               if (Global.value != 1)
               {
                   Response.Redirect("Menu.aspx");
               }
               else
               {
                   //if you strictly about this rule then make global value again 0.
                   //Global.value = 0;
               }
           }
       }



希望它可以帮到你。

谢谢。


Hope it helps you.
Thanks.


这篇关于通过URL修改限制直接URL访问。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆