在Asp.net C登录之前无法访问我网站中的任何网页# [英] Can not access Any Web Page in my website before Login in Asp.net C#

查看:72
本文介绍了在Asp.net C登录之前无法访问我网站中的任何网页#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是Asp.net C#。我的网站上有很多页面但是例如我有两个页面:



http://www.codeproject.com/Login.aspx



第二页



http://www.codeproject.com/Welcome.aspx



现在的问题是,当我在浏览器http://www.codeproject.com/Welcome.aspx上写时,它会直接打开欢迎页面。我想要的是,如果有人试图直接打开WELCOME页面,它会重定向到lOGIN页面



简称我的意思是首先登录然后欢迎页面。



请帮帮我................

I am using Asp.net C# . I have many pages in my website but for example i have two page like :

http://www.codeproject.com/Login.aspx

second page

http://www.codeproject.com/Welcome.aspx

now problem is that when i write on browser http://www.codeproject.com/Welcome.aspx it directly open welcome page . what i want is if somebody try to open directly WELCOME page it redirect to lOGIN page

is short what i mean is First Login then welcome Page.

Please help me ................

推荐答案

阅读并查看这个例子。你有这里的样本下载。



http: //aspsnippets.com/Articles/Simple-User-Login-Form-example-in-ASPNet.aspx [ ^ ]



此链接有一个小Example.Very简单的一个



http://vsc.edu.in / blog /?p = 237 [ ^ ]
Read and see this example. You have sample download here.

http://aspsnippets.com/Articles/Simple-User-Login-Form-example-in-ASPNet.aspx[^]

This Link has small Example.Very simple one

http://vsc.edu.in/blog/?p=237[^]


首先登录页面



成功登录按钮后,在会话中单击存储用户ID或用户名。和chk在欢迎页面加载的会话。如果会话存在,则欢迎页面加载,否则它将重定向到登录页面。

并尝试使用母版页和主页chk会话制作所有Web表单。它适用于从母版页继承的所有网页..

去吧..

你会获得成功。



Thanx

Md Tarique zafar
First make a Login Page

After successful login on button click store user id or user name in session . and chk that session at welcome Page load. If session exist then welcome page load otherwise it will redirect to login page..
And try to make your all web form using master page and on master page chk session. it will work for all web page inherit from master page..
Go for it..
you will get success.

Thanx
Md Tarique zafar


您想要使用的是FormsAuthentication。 http://msdn.microsoft.com/en -us / library / system.web.security.formsauthentication(v = vs.110).aspx [ ^ ]



很少的代码,你可以做到这一点。基本上更改web.config以使用FormsAuthentication。这将告诉ASP.Net将任何未经身份验证的请求重定向到您的LoginPage。然后在你的LoginPage中验证了用户后,你编写了几行代码,以便ASP.Net知道它们已经过身份验证,然后让它们通过。



那里如果您只是搜索FormsAuthentication和C#。
What you want to use is called FormsAuthentication. http://msdn.microsoft.com/en-us/library/system.web.security.formsauthentication(v=vs.110).aspx[^]

With very little code you can make this happen. Essentially change web.config to use FormsAuthentication. This will tell ASP.Net to redirect any unauthenticated requests to your LoginPage. Then in your LoginPage after you have validated the user you write a few lines of code so that ASP.Net knows they are authenticated and then will let them through.

There are many samples online if you just search for FormsAuthentication and C#.


这篇关于在Asp.net C登录之前无法访问我网站中的任何网页#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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