重定向到另一个网页,而不是ASP.NET中的默认网址 [英] Redirecting to another web page instead of default Url in ASP.NET

查看:83
本文介绍了重定向到另一个网页,而不是ASP.NET中的默认网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试重定向到默认URL以外的其他网页.这是我的代码.但是当我使用SetAuthCookie时出现错误.当我使用RedirectToLoginPage时,它可以正常工作,但问题是其重定向到defaultUrl.我需要重定向到"WelcomeStaff.aspx"

I am trying to redirect to another Web Page other than DEFAULT URL.This is my code.But I am getting error when I use SetAuthCookie.Its working fine when I use RedirectToLoginPage but the problem is Its Redirecting to defaultUrl. I need to redirect to "WelcomeStaff.aspx"

        protected void Buttontbl1_Click(object sender, EventArgs e)
        {

        if (AuthenticateUser(Textusertbl1.Text,textpastbl1.Text))
        {
            FormsAuthentication.SetAuthCookie(Textusertbl1.Text, CheckBoxtbl1.Checked);
            Response.Redirect("WelcomeStudent.aspx", true);

        }
        else
        {
           errorlbl.Text="Invalid Username or Password";
        }
        }

这是我的web.config文件.在此处指定了defaultUrl.

This is my web.config file.Have specified defaultUrl here.

       <authentication mode="Forms">
       <forms loginUrl="SelectUser.aspx" defaultUrl="WelcomeStaff.aspx"/>
      </authentication>
      <authorization>
       <deny users="?"/>
      </authorization>

请帮忙!!我是.Net.的新手,谢谢!这是错误

Please Help.!! I am new to .Net.Thanks in advance !! This is the error

  Server Error in '/' Application.

  The resource cannot be found.

  Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have        been removed, had its name changed, or is temporarily unavailable.  Please review the following URL and make sure that it is spelled correctly. 

  Requested URL: /Register/WelcomeStudent.aspx

推荐答案

在您的代码(aspx.cs)中

In your code (aspx.cs)

Response.Redirect( FormsAuthentication.DefaultUrl );

在您的网络配置中,请使用〜/path_to_default_page/default_page.aspx

In your webconfig please use ~/path_to_default_page/default_page.aspx

<authentication mode="Forms">
  <forms loginUrl="~/member_login.aspx"
    defaultUrl="~/path_to_default_page/default_page.aspx" />
</authentication>

这篇关于重定向到另一个网页,而不是ASP.NET中的默认网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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