URL重写 - 不要重定向到某个页面 [英] URL rewriting - do not redirect to certain page

查看:113
本文介绍了URL重写 - 不要重定向到某个页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



登录时,如果我的一个db值为true,那么我不想显示重定向到某个页面的菜单,我做到了。

但如果有人知道页面名称并直接写到地址栏,那么他/她可以去那个页面。



所以,如果有人将页面名称写入地址栏,但如果我的db值为true,那么我希望他们重定向到主页。



谢谢,

kk

Hi all,

On login if one of my db value is true then i don''t want to show a menu which is redirecting to certain page, i did it.
but if someone knows page name and write direct to address bar then he/she can go to that page.

so how can i do it if someone write page name to address bar but if my db value is true then i want them redirect to home page.

thanks,
kk

推荐答案

在每个页面上检查DB值是否为true,如果为true则重定向到主页。
On every page make a check whether DB value is true, if it is true then redirect to Home Page.


执行此操作的方法之一是使用下面给出的Global.asax BeginRequest事件,或者您可以创建Base Page并派生您想要阻止用户直接进入的所有aspx页面。您验证用户请求并将其重定向到主页的基页的加载方法。



protected void Application_BeginRequest(对象发送者,EventArgs) e)

{

bool dbValue;

//从数据库获取bdValue的价值



if(Path.GetFileName(HttpContext.Current.Request.PhysicalPath)==test.aspx&& dbValue)

{

HttpContext.Current.Response .Redirect( Home.aspx);

}



}
One of the way to do this, is to use Global.asax BeginRequest event as given below or you can create Base Page and derive all the aspx pages on which you want to stop user to come directly.In load method of base page you validate user request and redirect them to home page.

protected void Application_BeginRequest(object sender, EventArgs e)
{
bool dbValue;
//Get Value From DataBase for bdValue

if(Path.GetFileName(HttpContext.Current.Request.PhysicalPath) == "test.aspx" && dbValue)
{
HttpContext.Current.Response.Redirect("Home.aspx");
}

}


大家好,



i找到了解决方案......

i代码在我的母版页中为我担心。

请看下面的代码:



hi all,

i found the solution...
i code this in my master page and it worls for me.
please see below code:

if (System.IO.Path.GetFileName(HttpContext.Current.Request.PhysicalPath) == "test.aspx" && showWebbkg == 1)
{
                HttpContext.Current.Response.Redirect("Home.aspx");
}


这篇关于URL重写 - 不要重定向到某个页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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