2017-02-07 3 views
1

私はC#(ASP WinForm)で2つのアプリケーションを開発していますC#uriプロトコル

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"); 
    } 

私は関数を呼び出すためのコードのこの平和を使用します。私は、送信ASPプロジェクトで

  RegisterURLProtocol("mAPP", Application.ExecutablePath, "mAPP Uri Protocol"); 

このような私のアプリへのパラメータ:

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

しかし、私はこのように私のASPページを開こうとすると何も起こりません:

http://mydomain/BlankPage.aspx

どうすればこの問題を解決できますか? Windos 8から

+0

? – Dawnkeeper

+0

windows 10周年の更新 – DevELopE

+0

私はあなたがアプリケーションにカスタムUriスキームを登録することを意味すると思います... Uriプロトコルのようなものはありません。 MSDNを見よう:https://msdn.microsoft.com/en-us/library/aa767914.aspx –

答えて

1

以降、あなたはいくつかのより多くのレジストリキーを追加する必要があります:あなたが実行しているどのような窓のバージョン

Registry.SetValue(
       [email protected]"HKEY_CLASSES_ROOT\{protocolName}", 
       string.Empty, 
       protocolValue, 
       RegistryValueKind.String); 

Registry.SetValue(
       [email protected]"HKEY_CLASSES_ROOT\{protocolName}", 
       "URL Protocol", 
       String.Empty, 
       RegistryValueKind.String); 

Registry.SetValue([email protected]"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(
        [email protected]"HKEY_LOCAL_MACHINE\SOFTWARE\Classes\{protocolName}", 
        string.Empty, 
        protocolValue, 
        RegistryValueKind.String); 

    Registry.SetValue(
     [email protected]"HKEY_LOCAL_MACHINE\SOFTWARE\Classes\{protocolName}\shell\open\command", 
     string.Empty, 
     command, 
     RegistryValueKind.String); 

    Registry.SetValue(
     [email protected]"HKEY_LOCAL_MACHINE\SOFTWARE\{protocolName}\Capabilities\URLAssociations", 
     protocolName, 
     protocolName, 
     RegistryValueKind.String); 

    Registry.SetValue(
     @"HKEY_LOCAL_MACHINE\SOFTWARE\RegisteredApplications", 
     protocolName, 
     [email protected]"SOFTWARE\{protocolName}\Capabilities", 
     RegistryValueKind.String); 
} 
関連する問題