2016-10-31 1 views
1

ASP.NET MVC 5を使用してSAPコンテンツサーバーを作成しています。 Sapは、コンテンツサーバー機能にアクセスするために以下のスキームを使用してURIを呼び出します。ASP.NET MVC最初の(名前のない)クエリ文字列パラメータによるルート

http://servername:port/スクリプトコマンド &パラメータ

最初のqueryString値アクションメソッドにマップ[上記例-URIで「コマンド」]、「ザ・スクリプトは、」コントローラをマッピングするべきです。

次ウリ http://MyServer/MyApp/ContentServer?info&pVersion=0045&contRep=K1&docId=361A524A3ECB5459E0000800099245EC

は、コントローラにアクションメソッド「情報」によって処理されなければならない「ContentServerController」

public class ContentServerController : Controller 
{    
    public ActionResult info(string contRep, string docId, string pVersion) 
    { 
     throw new NotImplementedException(); 
    } 

これを行うことができますどのように任意のアイデア?

答えて

0

fabiosilvalimaの答えは、問題

public class ContentServerController : Controller 
{ 
    // one public Action-Method which reads the "command" from query-string 
    // and calls different private methods according to commandName   
    public ActionResult ContentServer(string contRep, string docId, string pVersion) 
    { 
     string commandName = Request.QueryString[0]; 
     switch(commandName) 
     { 
      case "info": 
       return info(contRep, docId, pVersion); 
      case "get": 
       return get(contRep, docId, pVersion); 
      case "create": 
       return create(contRep, docId); 
      default: 
       throw new NotImplementedException(); 
     } 
    } 

    private ActionResult info(string contRep, string docId, string pVersion) 
    { 
     throw new NotImplementedException(); 
    } 
    private ActionResult get(string contRep, string docId, string pVersion) 
    { 
     throw new NotImplementedException(); 
    } 
    private ActionResult create(string contRep, string docId) 
    { 
     throw new NotImplementedException(); 
    } 

} 
を解決するために私を助けました
0

最初のそれはアクションのクエリ文字列ならば、あなたはそれを行うことを試みた:

public class ContentServerController : Controller 
{ 
    public ActionResult Index(string contRep, string docId, string pVersion) 
    { 
     return RedirectToAction(Request.QueryString[0]); 
    } 

    public ActionResult info(string contRep, string docId, string pVersion) 
    { 
     return Content("info action"); 
    } 
} 

PS:あなたはクエリ文字列の長さと悪質な文字列をチェックする必要があります。

0

これは、あなたは非標準のパラメータ値のホールドを得ることができる方法である。

public class ContentServerController : Controller 
{ 
    public ActionResult Index() 
    { 
     var data = new List<string>(); 
     foreach (string key in Request.QueryString.Keys) 
     { 
      data.Add("key=[" + (key ?? "--null--") + "], value=[" + Request.QueryString[key] + "]"); 
     } 
     return View(data); 
    } 
} 

...このIndex見ると組み合わせる:

@model List<string> 
<a href="/ContentServer?info&pVersion=0045&contRep=K1&docId=361A524A3ECB5459E0000800099245EC">Link 1</a><br /> 
<a href="/ContentServer?about&foo=true&bar=false">Link 2</a><br /> 
<a href="/ContentServer?login&secure=yes">Link 3</a><br /> 
<hr size="1" /> 
@if (Model != null) 
{ 
    foreach (var str in Model) 
    { 
     @str<br /> 
    } 
} 

そこからがするのはあなた次第ですswitch()ステートメントをRequest.QueryString[null]、またはRedirectToAction("~/" + Request.QueryString[null]?" + all other parametersに加えて、対応するアクション方法、またはあなたに最も適したソリューションを選択してください。

関連する問題