2

I'm writing login page where login is default "Admin" and password is reading from xml file (FileUpload control).

How to redirect to main page, and to know what is path to this file("FileUpload.Name")? Which method of redirecting is appropiate? (sth like redirecting with parameters...but how?

Saint
  • 5,397
  • 22
  • 63
  • 107

2 Answers2

4

You question is not clear but to redirect the user back to man page after successful login do this:

//I assume a bool variable UserIsValid which you set after validating the user
if (UserIsValid)
{
    //If user was redirected back to login page then go back to requested page
    if (Request.QueryString["ReturnUrl"] != null)
    {
        FormsAuthentication.RedirectFromLoginPage("User_name", false);
    }
    else
    {
        //Set an Auth cookie
        FormsAuthentication.SetAuthCookie("User_name", false);
        //And then redirect to main page with you parameters if any
        Response.Redirect("mainPage.aspx?parameter1={0}&parameter2={1}", param1, param2);
    }
}    
else
{
    //User was not valid, do processing
}
   
radbyx
  • 9,352
  • 21
  • 84
  • 127
Shekhar_Pro
  • 18,056
  • 9
  • 55
  • 79
2

You can get the physical path of a file placed inside your application folder by Server.MapPath

Lets have some examples

[Root_Folder]/FileName.ext

string physicalPath = Server.MapPath("~/FileName.ext");

if file is inside a folder like [Root_Folder]/App_Data/FileName.ext

string physicalPath = Server.MapPath("~/App_Data/FileName.ext");

physical path will contains like the following string

C:\Websites\MyXYZ\FileName.ext

Now you want to redirect to Home.aspx

Response.Redirect("~/Home.aspx");

if you want to send any querystring parameter, just append as string preceding ? and separated by &

// append as many as required

Response.Redirect("~/Home.aspx?myParam1=" + param1Variable + "&param1=" + param2Variable);

Why don't you try asp.net built in controls i.e. ASP.NET Login Controls Overview

How to: Create an ASP.NET Login Page

Configuring an ASP.NET Application to Use Membership

Suggestion; don't get weird with asp.net login controls if you find your simple solution for accessing file and redirecting.

Waqas Raja
  • 10,802
  • 4
  • 33
  • 38