在ASP.NET MVC中生成自己的会话ID [英] Generate it's Own Session Id in ASP.NET MVC#

查看:87
本文介绍了在ASP.NET MVC中生成自己的会话ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助,我正在asp.net MVC3中创建一个应用程序,我想设置生成的自定义会话ID

i need a help, I'm creating an application in asp.net MVC3 and i want to set my custom session id which is generated

var str = Math.floor(Math.random() * (2000 - 1000 + 1)) + 1000;

 document.write("Session ID::" + str);

上面用Java脚本功能编写的代码,现在我想在ASP.NET MVC3的会话ID中设置该数字.

that above code written in java script function and now i want to set that number in my session id in ASP.NET MVC3.

推荐答案

快速的Google搜索显示了此博客条目,该条目说明了如何覆盖asp.net中的会话ID:

A quick google search shows this blog entry which explains how to overwrite the session id in asp.net:

http://weblogs.asp.net/anasghanem/archive/2008/12/16/programmatically-changing-the-session-id.aspx

简而言之:使用类 SessionIDManager 并调用方法 SaveSessionId 来设置自己的会话ID:

In short: Use the class SessionIDManager and call the method SaveSessionId to set your own session id:

SessionIDManager manager = new SessionIDManager();
string mySessionId = ...calculateYourOwnSessionId...;
bool redirected = false;
bool IsAdded = false;
manager.SaveSessionID(Context, mySessionId, out redirected, out IsAdded);

这篇关于在ASP.NET MVC中生成自己的会话ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆