我有这个网站(C#/ ASP.NET),其中一个表单,用户可以注册一个帐户(它是VS11的默认模板),在填写完所有内容并且用户点击注册后,它会创建帐户和日志在用户(这很棒).
在这一步之后,我想获得他被分配的UserID,但它不起作用.我在那里放了一个断点来查看"currentuserid"和"WebSecurity.CurrentUserId"的值,但它们只有一个-1值.下一步是用户被重定向到下一页,在该页面上这些功能起作用.我以为我能够获得UserID,因为用户已经在我提供的代码的第一行登录了.
所以我的问题是,为什么它不起作用?我对此非常不感兴趣,所以我显然错过了一些东西.
WebSecurity.Login(username, password);
int currentuserid = WebSecurity.CurrentUserId; // This doesn't work, only returns -1
<here I wish to update other tables but I need the user ID>
Response.Redirect("~/Welcome.cshtml");
Run Code Online (Sandbox Code Playgroud)
谢谢!
我试图通过Windows身份验证与我公司的MSSQL服务器建立连接,但它失败了,因为它试图使用我的计算机名作为登录而不是我的登录ID.使用MS SQL Server Management登录时,Windows身份验证工作正常,但不能使用此PHP代码:
<?php
// Server in the this format: <computer>\<instance name> or
// <server>,<port> when using a non default port number
$serverName = "xxx";
$connectionInfo = array( "Database"=>"xxx");
/* Connect using Windows Authentication. */
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn ) {
echo "Connection established.<br />";
}else{
echo "Connection could not be established.<br />";
die( print_r( sqlsrv_errors(), true));
}
//
?>
Run Code Online (Sandbox Code Playgroud)
我得到的打印输出如下:
[Microsoft] [SQL Server Native Client 11.0] [SQL Server]用户'xxx\T2002197 $'登录失败.))
T2002197是我的计算机名,不是我的登录ID,所以它当然失败了.我怎么解决这个问题?我正在使用WAMP.编辑了一些信息,替换为'xxx'
我对C#很新,所以请多加耐心.我要做的是读取文件夹中的所有文件,找到一个特定的行(可以在同一个文件中多次出现),并将该输出显示在屏幕上.
如果有人能指出我需要使用哪种方法,那就太棒了.谢谢!