login asp.net redirect with parameters
Solution 1
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}¶meter2={1}", param1, param2);
}
}
else
{
//User was not valid, do processing
}
Solution 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 + "¶m1=" + 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.
Related videos on Youtube
Saint
Updated on December 16, 2021Comments
-
Saint over 2 years
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?
-
Grant Thomas about 13 yearsYour question is not properly clear. Please consider revising.
-
Shekhar_Pro about 13 yearswhich file are you talking about.. what is FileUpload.Name.. are you asking about Server.MapPath(filepath);
-
-
Filip Ekberg about 13 yearsI think he wants to redirect with additional parameters on the query string.
-
Saint about 13 yearsI prefere redirecting without public parameters in url. Is there other suitable method?
-
Shekhar_Pro about 13 yearsyou 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
-
Saint about 13 yearsThanks, Session object is great :)