asp.net网站上的url安全性 [英] url security in asp.net website

查看:74
本文介绍了asp.net网站上的url安全性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发网站,我希望如果我复制任何其他页面的粘贴网址,它应该被重定向到登录页面。





如何做到这一点,我尝试使用会话对象,但它无法正常工作。



在登录页面上我写道:



btnlogin_clik()

{

if(txtusername.text ==user&& txtpwd.text == pwd)

{

i am developing website in which i want that if i copy pasted url of any other page it should be redirected to login page.


how it can be done ,i tried by using session object but it is not working.

on login page i have written:

btnlogin_clik()
{
if(txtusername.text=="user" && txtpwd.text=="pwd")
{

Session["login"] = "true";
                  Response.Redirect("access.aspx");





}

}

在其他页面上:







}
}
on other pages:


protected void Page_Load(object sender, EventArgs e)
       {
           if (Session["login"].ToString()=="")
           {
               Response.Redirect("login.aspx");
           }
       }





但是当我直接运行其他页面时它会抛出异常

System.NullReferenceException:对象引用未设置为对象的实例。



but when i am running directly other pages it is throwing an exception
System.NullReferenceException: Object reference not set to an instance of an object.

推荐答案

Session [login] 似乎已变为null。当你把它转换为字符串时,你会收到这个错误。

只需尝试

Session["login"] seems to have become null. When you cast it to string, you get this error.
Simply try
if (Session["login"] is null || Session["login"].ToString()=="")
{
//
}


这篇关于asp.net网站上的url安全性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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