• 當前位置:首頁 > IT技術 > Web編程 > 正文

    .net core 服務端302重定向
    2021-10-18 17:48:14


    1.新建控制器 :

    RedirectUrlController

    ?



    [HttpGet]
    public void Get(string enterpriseId,string agentId)
    {
    var redirect_uri = "";

    var osPat = "Mobile|Android|webOS|SymbianOS|iPhone|iPod|BlackBerry";var agent = Request.Headers["User-Agent"];

    Regex reg = new Regex(osPat);
    if (reg.IsMatch(agent))//pc302端跳轉地址
    {
    redirect_uri += "/pc/index.html#/Home";
    }
    else
    {
    redirect_uri += "/h5/index.html#/begin";//手機端302跳轉地址
    }

    var url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + appid +
    "&redirect_uri=" +
    HttpUtility.UrlEncode(redirect_uri) +
    "&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect";

    Response.Redirect(url); //注意:沒有http跳轉到本域名下的對應地址,加上http跳轉到別的域名
    }


    2.訪問路徑:

    http://localhost:55733/api/RedirectUrl?enterpriseId=1&agentId=2

    自動跳轉到:

    https://open.weixin.qq.com/connect/oauth2/authorize?appid=&redirect_uri=https%3a%2f%2fwgc-pc-test.zhijiaxing.net%2fpc%2findex.html%23%2fHome&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect

    .net core 服務端302重定向_html

    ?


    本文摘自 :https://blog.51cto.com/u

    開通會員,享受整站包年服務
    国产呦精品一区二区三区网站|久久www免费人咸|精品无码人妻一区二区|久99久热只有精品国产15|中文字幕亚洲无线码