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?

2
  • 3
    Your question is not properly clear. Please consider revising. Commented Feb 13, 2011 at 10:32
  • which file are you talking about.. what is FileUpload.Name.. are you asking about Server.MapPath(filepath); Commented Feb 13, 2011 at 10:47

2 Answers 2

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
}
   
Sign up to request clarification or add additional context in comments.

4 Comments

I think he wants to redirect with additional parameters on the query string.
I prefere redirecting without public parameters in url. Is there other suitable method?
you mean you don't want to show parameters in url..well then there are other ways like storing parameters in cookie or Session object.. its totally upto your implementation and requirements
Thanks, Session object is great :)
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.