Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何将参数从MVC传递到Silverlight_C#_Asp.net_Asp.net Mvc_Silverlight - Fatal编程技术网

C# 如何将参数从MVC传递到Silverlight

C# 如何将参数从MVC传递到Silverlight,c#,asp.net,asp.net-mvc,silverlight,C#,Asp.net,Asp.net Mvc,Silverlight,在MVC项目认证之后,我需要一个关于如何在单击按钮后安全地传递参数的解决方案 我是按密码做的 <form action="http://localhost:53988/Default.aspx" method="post" -- this is where is hosted SilverlightApp> <input type="hidden" name="session" value="@(Helpers.Context.CurrentSession.ID)"/&

在MVC项目认证之后,我需要一个关于如何在单击按钮后安全地传递参数的解决方案

我是按密码做的

<form action="http://localhost:53988/Default.aspx" method="post" -- this is where is hosted SilverlightApp>
    <input type="hidden" name="session" value="@(Helpers.Context.CurrentSession.ID)"/>
    <input type="submit" value="RedirectToSilver" />
</form>
一切正常,但问题是客户端可以看到sessionID,我认为这是不安全的


我的目标是在silverlight中安全地获取这个sessionID,而不向客户机显示它?如何操作?

创建一个操作以返回会话id,并让silverlight客户端调用该端点以获取当前会话id

控制器

客户

您可以硬编码端点,也可以使其可发现,这取决于您。我展示的示例还假设您没有使用WebApi。如果您愿意的话,这应该很容易实现。
我个人认为,所有这些试图隐藏会话id的做法都是毫无意义的,但我也不知道您的情况。

为什么不安全?不管怎样,您都是通过明文HTTP从MVC传递它,并且它确实需要在Silverlight中结束。客户端无论如何都可以检查会话id。您可以看到我发布的图像,我不知道客户端可以查看会话或某些安全信息是否安全?客户端仍然可以使用浏览器中的cookie编辑器查看其会话id。此会话id是SQL Server中表中的IdGuid,而不是HttpContext.Current.session的值(如果解释正确的话)Look;我的意思是Silverlight应用程序将再次使用该会话id发出请求,因此隐藏它几乎没有什么用处。你需要将它从网页传递到Silverlight应用程序,所以你不能隐藏它。例如,您可以使用加密对其进行模糊处理,但随后您的Silverlight应用程序必须对其进行解密才能使用它,使用调试器的用户可以再次从内存中读取值。
<div id="silverlightControlHost">
    <object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
          <param name="source" value="ClientBin/Client.xap?<%=AssemblyInfo.GetVersionNumber()%>" />
          <param name="minRuntimeVersion" value="4.0.50826.0" />
          <param name="initParams" value="sessionId = '<%=HttpContext.Current.Request["session"] %>'" />
          <param name="autoUpgrade" value="true" />
    </object>
</div>
private void Application_Startup(object sender, StartupEventArgs e)
{
    var sessionID= string.Empty;
    if (e.InitParams.ContainsKey("sessionId"))
        sessionID= e.InitParams["sessionId"];
}
[Authorize]
public class SessionController : Controller {

    [HttpGet]
    public JsonResult Get() {
        return Json(Helpers.Context.CurrentSession.ID);
    }

}
private async void Application_Startup(object sender, StartupEventArgs e) {
    var sessionID = string.Empty;
    var httpClient = new HttpClient();
    var url = "http://localhost:53988/Session";
    var response = await httpClient.GetAsync(url);
    if(response.IsSuccessStatusCode 
       && response.Content.Headers.ContentLength.GetValueOrDefault() > 0) {
        sessionID = await response.Content.ReadAsStringAsync();
    }
}