登录检查Asp.net [英] Login Check in Asp.net

查看:66
本文介绍了登录检查Asp.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Everyone。

我是asp.net的新手,我使用C#在asp.net上创建一个网站,在我的网站上有登录页面。当用户登录然后它到达主页,但如果用户在地址栏中编辑我的地址,那么用户不需要登录。我希望用户在没有登录的情况下看不到主页,但是它会在地址栏中进行更改。

例如

这是登录页面的路径

http:// localhost:54515 / mastergridview%20-%20Copy / Login.aspx [< a href =http:// localhost:54515 / mastergridview%20-%20Copy / Login.aspxtarget =_ blanktitle =New Window> ^ ]



但是用户可以在地址栏中访问数据写入Home

Hello Everyone.
i am new in asp.net, i create a website in asp.net using C#, in my site there is login page. when user login then it reached on home page, but if user edit my address in address bar then user not need to login. i want that user cannot seen home page without login, however it make change in address bar.
For example
this is path of login page
http://localhost:54515/mastergridview%20-%20Copy/Login.aspx[^]

but user can access data writing Home in address bar

推荐答案

login.aspx:



if(username ==name&& password ==pwd)

{

Session [username] =name;

}





home.aspx:



onpageload活动:





if(Session [username]!= null)

{

bt1.text = Session [username]。tostring()+已经登录;

}

其他

{

response.redirct(login.aspx);

}
login.aspx:

if(username=="name"&&password=="pwd")
{
Session["username"]="name";
}


home.aspx:

onpageload event:


if(Session["username"]!=null)
{
bt1.text = Session["username"].tostring()+"already logon";
}
else
{
response.redirct("login.aspx");
}


所以只需在web.config文件中使用身份验证和授权:



So just play with authentication and authorization in your web.config file:

<authentication mode="Forms">
  <forms name="TestAuthCookie" loginUrl="login.aspx" timeout="30" defaultUrl="start.aspx">
    <credentials passwordFormat="MD5">
      <user name="admin" password="21232f297a57a5a743894a0e4a801fc3"/>
      <user name="invite" password="f8f9a65ed8c3611b4ae9198b7c8a3702"/>
    </credentials>
  </forms>
</authentication>
<authorization>
  <deny users="?"/>
</authorization>


据我所知,您希望每个人都可以访问登录页面,并且只有在成功登录后才能转到其他页面...

为此,你必须将你的网站分成文件夹



[root]

login.aspx

web.config

\ site

home.aspx

web.config



在外部web.config中写这个...



As I understood you want the login page to be accessible to everyone, and only after successful login be able to go to other pages...
For this you have to separate your site to folders

[root]
login.aspx
web.config
\site
home.aspx
web.config

In the outer web.config write this...

<configuration>
	<system.web>
		<authorization>
			<allow users="*" />
		</authorization>
	</system.web>
</configuration>





在内部web.config中写这个...





In the inner web.config write this...

<configuration>
	<system.web>
		<authorization>
			<deny users="?" />
		</authorization>
	</system.web>
</configuration>





第一个说任何人都允许看到这个文件夹中的页面,第二个是拒绝访问所有未经授权的人。



[如果你允许的话应该添加我认为这样的方式登录有点旧式。我建议你使用其他架构。访问您网站的人总是会看到内容较少的主页。在这个主页的某个地方,你有一个可以登录的角落。登录后,主页显示的内容更具针对刚刚登录的人...]


这篇关于登录检查Asp.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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