在asp.net核心中解析查询字符串时出错

问题描述 投票:0回答:1

我尝试了以下代码

var webAddr =“ http://localhost:4508?Name=partha&[email protected]”;

        ProcessStartInfo psi = new ProcessStartInfo
        {
            FileName = webAddr,
            UseShellExecute = true
        };
        Process.Start(psi);

//这将启动浏览器//现在我想解析查询字符串

var request = HttpContext.Request;var query = request.Query;foreach(查询中的可变项){Debug.WriteLine(item);}但是当它记录HttpContext时会给出错误Systen.Nullreferenceexception

为什么给url时HttpContext为什么返回null?

c# browser .net-core
1个回答
0
投票

。Net Core GitHub存储库here中引发了关于此问题的一些讨论。建议的解决方法是运行以下代码:

ProcessStartInfo psi = new ProcessStartInfo
{
    FileName = "http://www.google.com",
    UseShellExecute = true
};
Process.Start(psi);

GitHub链接包含一些很好的信息,说明为什么会这样,以及必须使用UseShellExecute = true标志集显式启动该过程的原因。

© www.soinside.com 2019 - 2024. All rights reserved.