我尝试了以下代码
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?
。Net Core GitHub存储库here中引发了关于此问题的一些讨论。建议的解决方法是运行以下代码:
ProcessStartInfo psi = new ProcessStartInfo
{
FileName = "http://www.google.com",
UseShellExecute = true
};
Process.Start(psi);
GitHub链接包含一些很好的信息,说明为什么会这样,以及必须使用UseShellExecute = true
标志集显式启动该过程的原因。