简体   繁体   English

使用参数登录asp.net重定向

[英]login asp.net redirect with parameters

I'm writing login page where login is default "Admin" and password is reading from xml file (FileUpload control).我正在编写登录页面,其中登录是默认的“管理员”,密码是从 xml 文件(FileUpload 控件)中读取的。

How to redirect to main page, and to know what is path to this file("FileUpload.Name")?如何重定向到主页,并知道这个文件的路径是什么(“FileUpload.Name”)? Which method of redirecting is appropiate?哪种重定向方法合适? (sth like redirecting with parameters...but how? (比如用参数重定向……但是怎么做?

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
}
   

You can get the physical path of a file placed inside your application folder by Server.MapPath您可以通过 Server.MapPath 获取放置在应用程序文件夹中的文件的物理路径

Lets have some examples让我们举一些例子

[Root_Folder]/FileName.ext [Root_Folder]/FileName.ext

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

if file is inside a folder like [Root_Folder]/App_Data/FileName.ext如果文件位于 [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 C:\\Websites\\MyXYZ\\FileName.ext

Now you want to redirect to Home.aspx现在你想重定向到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 ie ASP.NET Login Controls Overview你为什么不尝试 ASP.NET 内置控件,即ASP.NET 登录控件概述

How to: Create an ASP.NET Login Page如何:创建 ASP.NET 登录页面

Configuring an ASP.NET Application to Use Membership配置 ASP.NET 应用程序以使用成员身份

Suggestion;建议; don't get weird with asp.net login controls if you find your simple solution for accessing file and redirecting.如果您找到访问文件和重定向的简单解决方案,请不要对 asp.net 登录控件感到奇怪。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM