页面重定向到登录页面 [英] page redirects to login page

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

问题描述

hi


i有一个网络应用程序当我们第一次点击它重定向到登录页面的任何页面时,

当我再次登录时可以访问该页面,它工作正常它只是在我在IIS上托管时给出错误



我正在使用

iis 8

asp.net 4.0

os:sql server 2012

浏览器:IE 10



我使用表单身份验证,用户可以在登录前看到登录页面,一旦他登录并尝试进入下一页,他再次被重定向到登录页面他输入凭据页面工作正常但是当我重新启动时服务器错误锥体再次



网页密钥

hi
i have a web application when we click first time on any page it redirect to the log in page,
when i log in again i can access the page and it works fine it is only giving error when i'm hosting it on IIS

i'm using
iis 8
asp.net 4.0
os: sql server 2012
browser: IE 10

im using form authentication the user can see the login page before login and once he logs in and tries to go the next page he is redirected to the login page again again he enter the credentials the page works fine but when i restart the server the error cones again

web key

<identity impersonate="true" />
<authentication mode="Forms">
<sessionState timeout="180" />

推荐答案

使用Generic Handler [Global.asax]文件



C#代码



use Generic Handler[Global.asax] file

C# code

<%@ Application Language="C#" %>

<script runat="server">

    void Application_Start(object sender, EventArgs e)
    {
        // Code that runs on application startup

    }

    void Application_End(object sender, EventArgs e)
    {
        //  Code that runs on application shutdown

    }

    void Application_Error(object sender, EventArgs e)
    {
        // Code that runs when an unhandled error occurs

    }

    void Session_Start(object sender, EventArgs e)
    {
        // Code that runs when a new session is started
        Session["Authenticate"] = "";
        CheckLogin();
    }

    void Session_End(object sender, EventArgs e)
    {
       CheckLogin();

    }
    void Application_OnPostRequestHandlerExecute()
    {
       //CheckLogin();
    }

    void CheckLogin()
    {
        string Url = Request.RawUrl;
        int count = Url.Length - 10;
        string TestUrl = Url.Substring(count);
        string SessionData = Session["Authenticate"].ToString();
        if (SessionData == "" && TestUrl != "Login.aspx")
        {
            Response.Redirect("~/Login.aspx");
        }
    }
</script>







将代码放入登录页面。 cs



会话[认证] =是;




put the code in login page.cs

Session["Authenticate"] = "Yes";


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

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