anusha
anusha

Reputation: 55

Redirecting to another web page instead of default Url in ASP.NET

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";
        }
        }

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>

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

Upvotes: 1

Views: 1027

Answers (2)

Ho&#224;ng Trần
Ho&#224;ng Trần

Reputation: 103

In your code (aspx.cs)

Response.Redirect( FormsAuthentication.DefaultUrl );

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>

Upvotes: 2

Jon P
Jon P

Reputation: 19797

Change

Response.Redirect("WelcomeStudent.aspx", true);

to

Response.Redirect("~/WelcomeStudent.aspx", true);

assuming "WelcomeStudent.aspx" is at the root level of the website.

Upvotes: 1

Related Questions