C#uri协议

C#uri协议,c#,winforms,C#,Winforms,我正在用c#(ASP WinForm)开发两个应用程序 我需要将一些参数从web发送到WinForm应用程序。为此,我编写了一个函数,允许我的应用程序为此连接创建URI协议: public static void RegisterURLProtocol(string protocolName, string applicationPath, string description) { RegistryKey myKey = Registry.ClassesRoot

我正在用c#(ASP WinForm)开发两个应用程序

我需要将一些参数从web发送到WinForm应用程序。为此,我编写了一个函数,允许我的应用程序为此连接创建URI协议:

    public static void RegisterURLProtocol(string protocolName, string applicationPath, string description)
    {
        RegistryKey myKey = Registry.ClassesRoot.CreateSubKey(protocolName);
        myKey.SetValue(null, description);
        myKey.SetValue("URL Protocol", string.Empty);
        Registry.ClassesRoot.CreateSubKey(protocolName + "\\Shell");
        Registry.ClassesRoot.CreateSubKey(protocolName + "\\Shell\\open");
        myKey = Registry.ClassesRoot.CreateSubKey(protocolName + "\\Shell\\open\\command");
        myKey.SetValue(null, "\"" + applicationPath+ "\" %1");
    }
我使用这段代码调用函数:

            RegisterURLProtocol("mAPP", Application.ExecutablePath, "mAPP Uri Protocol");
在ASP项目中,我向我的应用程序发送如下参数:

protected void Page_Load(object sender, EventArgs e)
{
    Response.Redirect("mAPP://MYPARAMETERS");
}
但当我尝试像这样打开我的ASP页面时,什么也没有发生:

protected void Page_Load(object sender, EventArgs e)
{
    Response.Redirect("mAPP://MYPARAMETERS");
}


如何修复此问题?

从Windos 8开始,您必须添加更多注册表项:

Registry.SetValue(
                $@"HKEY_CLASSES_ROOT\{protocolName}",
                string.Empty,
                protocolValue,
                RegistryValueKind.String);

Registry.SetValue(
                $@"HKEY_CLASSES_ROOT\{protocolName}",
                "URL Protocol",
                String.Empty,
                RegistryValueKind.String);

Registry.SetValue($@"HKEY_CLASSES_ROOT\{protocolName}\shell\open\command", string.Empty, command, RegistryValueKind.String);


// detect win 8 and register as choosable protocol handler
Version win8Version = new Version(6, 2, 9200, 0);
if (Environment.OSVersion.Platform == PlatformID.Win32NT &&
    Environment.OSVersion.Version >= win8Version)
{
     Registry.SetValue(
                    $@"HKEY_LOCAL_MACHINE\SOFTWARE\Classes\{protocolName}",
                    string.Empty,
                    protocolValue,
                    RegistryValueKind.String);

    Registry.SetValue(
       $@"HKEY_LOCAL_MACHINE\SOFTWARE\Classes\{protocolName}\shell\open\command",
        string.Empty,
        command,
        RegistryValueKind.String);

    Registry.SetValue(
       $@"HKEY_LOCAL_MACHINE\SOFTWARE\{protocolName}\Capabilities\URLAssociations",
        protocolName,
        protocolName,
        RegistryValueKind.String);

    Registry.SetValue(
        @"HKEY_LOCAL_MACHINE\SOFTWARE\RegisteredApplications",
        protocolName,
        $@"SOFTWARE\{protocolName}\Capabilities",
        RegistryValueKind.String);
}

您正在运行什么windows版本?windows 10周年更新我想您的意思是向应用程序注册自定义Uri方案。。。没有Uri协议这样的东西。MSDN中值得一看的内容: