请高手帮我把这段VB代码翻译成C#的,谢谢

greenberet007 2012-02-13 08:22:44
原来的代码:
Private Sub _WeiboLogin(ByVal nUID As Integer, ByVal strUserName As String)

Dim _xauthTKValue As String = ""
Dim dddd As DateTime = New DateTime(1970, 1, 1)
Dim d As DateTime = DateTime.Now
Dim expires As DateTime = d.AddDays(1)
Dim strWeiboKey As String = "XWEIBO_KEY_2010_1"
Dim strDoMain As String = ".elseviermed.cn"
_xauthTKValue = "{""uid"":" + nUID.ToString() & ",""uname"":""" + strUserName + """,""time"":" + Convert.ToInt64((d - dddd).TotalSeconds).ToString() + "}"
Dim cookie_TK As HttpCookie = New HttpCookie("_xauthTK", _xauthTKValue)
cookie_TK.Domain = strDoMain
cookie_TK.Path = "/"
cookie_TK.Expires = expires
HttpContext.Current.Response.Cookies.Add(cookie_TK)

Dim _xauthSGValue As String = _xauthTKValue + "###" + strWeiboKey
Dim cookie_SG As HttpCookie = New HttpCookie("_xauthSG", System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(_xauthSGValue, "MD5").ToLower())
cookie_SG.Domain = strDoMain
cookie_SG.Path = "/"
cookie_SG.Expires = expires
HttpContext.Current.Response.Cookies.Add(cookie_SG)

End Sub

我自己翻译的代码:
但是运行后报错,因为服务器端没有把错误明确提示给我,所以请高手协助翻译

private void WeiboLoginPost(int userid,string username)
{
string _xauthTKValue = "";
DateTime dddd= new DateTime(1970, 1, 1);
DateTime d = DateTime.Now;
DateTime expires= d.AddDays(1);
string strWeiboKey = "XWEIBO_KEY_2010_1";
string strDoMain = ".elseviermed.cn";

/////////////////////////////////////// 我总感觉这里翻译的不对,请高手指点,谢谢。

_xauthTKValue = "{\"uid\":" + userid.ToString() + ",\"uname\":" + username + ",\"time\":" + Convert.ToInt64((d - dddd).TotalSeconds).ToString() + "}";

//////////////////////////////

HttpCookie cookie_TK = new HttpCookie("_xauthTK", _xauthTKValue);
cookie_TK.Domain = strDoMain;
cookie_TK.Path = "/";
cookie_TK.Expires = expires;
Response.Cookies.Add(cookie_TK);
string _xauthSGValue = _xauthTKValue + "###" + strWeiboKey;
HttpCookie cookie_SG = new HttpCookie("_xauthSG", System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(_xauthSGValue, "MD5").ToLower());
cookie_SG.Domain = strDoMain;
cookie_SG.Path = "/";
cookie_SG.Expires = expires;

Response.Cookies.Add(cookie_SG);
}
...全文
91 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
greenberet007 2012-02-13
  • 打赏
  • 举报
回复
谢谢楼上解答的朋友
greenberet007 2012-02-13
  • 打赏
  • 举报
回复
找到问题了 键值对username没写对,username没加引号
greenberet007 2012-02-13
  • 打赏
  • 举报
回复
找到问题了 键值对username没写对,username没加引号
孟子E章 2012-02-13
  • 打赏
  • 举报
回复
_xauthTKValue = "{\"uid\":" + userid.ToString() + ",\"uname\":\"" + username + "\",\"time\":" + Convert.ToInt64((d - dddd).TotalSeconds).ToString() + "}";
孟子E章 2012-02-13
  • 打赏
  • 举报
回复
应该可以的,

转换代码工具
http://www.developerfusion.com/tools/convert/vb-to-csharp/

62,041

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧