登录界面为http://localhost/xxx/loss.aspx
如果直接在地址栏中访问非登录界面,如:http://localhost/xxx/loss.aspx
将出现系统出错信息。
这种情况下怎样做成能自动转到登录界面?谢谢!
如果直接在地址栏中访问非登录界面,如:http://localhost/xxx/loss.aspx
将出现系统出错信息。
这种情况下怎样做成能自动转到登录界面?谢谢!
解决方案 »
- 关于Asp.net Web应用程序不能获取url字符型参数的问题,百思不得其解
- validateRequest="false " enableEventValidation="false"对页面有什么影响吗?
- 用户控件 radiobutton panel 求救!!!!!
- 今天俺做个不要脸的人
- 方法没有采用0个参数的重载
- 本地测试没问题,传到万网就KO了,大家帮看看,愁愁愁死我了!(命名空间问题)
- DropDownList去掉重复的记录
- ##--如何用Javascitp向MediaPlay 传值
- jmail的初级问题:组件传到bin目录,类库文件怎么才能调用它?
- DataGrid中修改HeadText和Foot的问题
- gridview选择删除的一个问题
- 从字符串 到类型 Double 的转换无效
描述:
document对象的referrer属性,返回导航到当前网页的超链接所在网页的URL。举例:
1. a.html文件内容如下:
<a href="b.html">浏览b.html </a>
2. b.html文件中的内容如下:
<body>
<script type="text/javascript">
document.write(document.referrer);
</script>
</body> 3. 则在通过a.html中的超链接访问b.html的时候,显示的结果是:
http://127.0.0.1:8180/a.html说明:经过测试,需要将两个文件放在服务器中才能得到想要的结果,若直接在本地文件夹中则得到空字符串,若直接在浏览器地址栏中输入b.html的URL地址或使用打开菜单访问b.html,则document.referrer的值为空字符串。然后看看这个的用法。
在不允许访问的界面上写入if(session[""]==null)
{
response.redirect(.....);
}
/// <summary>
/// Web页面的基类,所有页面都继承此类(母板页除外)。
/// </summary>
public class PageBase : Page
{
private const string HEADER_PREFIX = "测试平台 :: {0}"; protected override void OnInit(EventArgs e)
{
base.OnInit(e); //User u = new User("admin");
////User u = Users
//HttpContext.Current.User = u; // 不要求RBAC管理,不跳转到Logic.aspx页
if (!Convert.ToBoolean(ConfigurationManager.AppSettings["EnableRBAC"]))
{
return;
}
// 当前正处于登录页,不跳转Logic.aspx页
if (HttpContext.Current.Request.AppRelativeCurrentExecutionFilePath.CompareTo("~/Login.aspx") == 0)
{
return;
}
// 登录验证
bool isLogin = false;
if (HttpContext.Current.Session["UserID"] != null &&
HttpContext.Current.Session["UserName"] != null )
{
long userId = long.Parse(HttpContext.Current.Session["UserID"].ToString());
string userName = HttpContext.Current.Session["UserName"].ToString().Trim();
UserLogic userLogic = new UserLogic();
TS_USER user = userLogic.SelectEntity(userId);
if (user.USERNAME.CompareTo(userName) == 0)
{
isLogin = true;
}
}
if (!isLogin)
ShowMessage("当前用户尚未登录", "Login.aspx");
}
其他的页面:
ublic partial class admin_CodeManage : PageBase
<forms name="MyAppFormAuth" loginUrl="login.aspx" protection="All" timeout="20" path="/">
</forms>
</authentication>
<authorization>
<deny users="?"/>
</authorization>
<!--
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
-->
</customErrors>
或Application_Error里处理
或
public class BasePage : System.Web.UI.Page
{
public BasePage()
{
}
protected override void OnInit(EventArgs O)
{
if (base.Session["UserId"] == null || base.Session["UserId"].ToString().Equals(""))
{
Response.Redirect("~/Error.aspx");
}
}
} public partial class Error : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Write(" <script>top.location.href='login.aspx'; </script>");
}
}