asp.net网页重定向

重定向示例:

http://118.25.40.47/Redirect.aspx?https://www.baidu.com


Redirect.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplicationTest
{
    /// <summary>
    /// url网页重定向示例: http://localhost:5516/Redirect.aspx?https://www.baidu.com
    /// </summary>
    public partial class Redirect : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            String redictUrl = getParam();                                  // 获取重定向Url
            if(!redictUrl.Equals("")) Response.Redirect(redictUrl, true);   // 页面重定向跳转
            //Server.Transfer(param, false);    // Server不可跳转其它站点
        }

        /// <summary>
        /// 获取请求参数信息
        /// </summary>
        private String getParam(String LogName = "")
        {
            String Url = Request.Url.ToString();
            String param = "";
            if (Url.Contains("?"))
            {
                param = Url.Substring(Url.IndexOf("?") + 1);                // 获取参数信息

                if (LogName.Equals("")) LogName = this.GetType().Name;
                LogTool log = new LogTool(LogName);                         // 记录至log中
                log.WriteLine(param);
            }
            return param;
        }
    }
}


Redirect.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Redirect.aspx.cs" Inherits="WebApplicationTest.Redirect" %>

<%--<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
    </div>
    </form>
</body>
</html>--%>


猜你喜欢

转载自blog.csdn.net/scimence/article/details/79307282
今日推荐