• .net core 服务端302重定向


    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

  • 相关阅读:
    I/O流
    宇宙第一帅的HTML笔记
    宇宙无敌第一帅的Java笔记
    Activity常用的方法
    Spinne
    安卓布局方式
    for循环
    TextView
    开发Activity步骤
    重写
  • 原文地址:https://www.cnblogs.com/liuqiyun/p/15410083.html
Copyright © 2020-2023  润新知