从ASP迁移到ASP.NET C#

编程入门 行业动态 更新时间:2024-10-27 00:26:46
本文介绍了从ASP迁移到ASP.NET C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

全部, 我已经尝试了几天将下面的代码转换为asp c#。 这是一个非常简单的页面。 - 获取当前登录用户并将其存储在名为strFullUserName的变量中,例如domain\johnsonM - 然后我查询针对名为usp_GetDisplayName的存储过程的用户名示例Mike Johnson。 - 然后它将在strFullUserName中存储用户全名(Mike Johnson) 我之前从未使用过C#,我已经完成了网站的其余部分,现在我需要在网站上显示完整用户名而不查询Active目录。我已经在ASP中多次使用下面的代码完成了这个,没有任何问题,只是不确定如何做到这一点是ASP和C#。 谢谢!

< < blockquote class = quote > < div class = op > 引用:< / div > html> < body > <% Dim strFullUserName strFullUserName = Request.ServerVariables( AUTH_USER) 设置 rs = CreateObject( ADODB.Recordset) rs.Open EXECUTE usp_GetDisplayName'& Request.ServerVariables( AUTH_USER)& ', Provider = SQLOLEDB.1; Password = PASSWORD !; Persist Security Info = True; User ID = USERNAME; Initial Catalog = UserCatalog; Data Source = SERVERNAME, 3 , 3 如果rs.bof和rs.eof那么 Else strFullUserName = rs.Fields( displayName)。值结束如果 Set rs = Nothing Response.Write(strFullUserName)%> < / body > < / html< / blockquote > >

我的尝试: - 我试图使用下面的代码连接到sql server } SqlConnection sqlConnection1 = new SqlConnection(Data Source = SERVERNAME; user id = USER NAME; password = PASSWORD !; Initial Catalog = USERCATALOG; ); SqlCommand cmd = new SqlCommand(); SqlDataReader reader;

解决方案

按照更改值你的要求

使用(SqlConnection conn = new SqlConnection()) { conn.ConnectionString = 数据源=< server> ;;初始目录= TDE_Test;集成安全性= True;连接超时= 15;加密= FALSE; TrustServerCertificate = FALSE;; conn.Open(); SqlCommand cmd = new SqlCommand( StoreProcName ,conn); cmd.CommandType = CommandType.StoredProcedure; SqlParameter parm = new SqlParameter( @ return_value,SqlDbType.Int); parm.Direction = ParameterDirection.ReturnValue; cmd.Parameters.Add(parm); cmd.ExecuteNonQuery(); Label2.Text = parm.Value.ToString(); } < / 服务器 >

All, I have been trying for a few days to Convert the code below to asp c#. It's a pretty simple page. - Get the current logged on user and store it in a variable called strFullUserName for example domain\johnsonM - I then Query the user name against a stored procedure called usp_GetDisplayName example Mike Johnson. - It will then store the users full name (Mike Johnson) in strFullUserName I have never used C# before and I have the rest of the site already completed and now I need to display the Full Users name on the website without querying Active directory. I have done this many times in ASP using the code below without any issues just not sure how to do this is ASP and C#. Thanks!

<<blockquote class="quote"><div class="op">Quote:</div>html> <body> <% Dim strFullUserName strFullUserName = Request.ServerVariables("AUTH_USER") Set rs = CreateObject("ADODB.Recordset") rs.Open "EXECUTE usp_GetDisplayName '" & Request.ServerVariables("AUTH_USER") & "'", "Provider=SQLOLEDB.1;Password=PASSWORD!;Persist Security Info=True;User ID=USERNAME;Initial Catalog=UserCatalog;Data Source=SERVERNAME", 3, 3 If rs.bof and rs.eof Then Else strFullUserName = rs.Fields("displayName").Value End If Set rs = Nothing Response.Write(strFullUserName) %> </body> </html</blockquote>>

What I have tried: - I have attempted to make a connection to the sql server using the code below } SqlConnection sqlConnection1 = new SqlConnection("Data Source = SERVERNAME; user id = USER NAME; password = PASSWORD!; Initial Catalog = USERCATALOG;"); SqlCommand cmd = new SqlCommand(); SqlDataReader reader;

解决方案

Change values as per your requirement

using (SqlConnection conn = new SqlConnection()) { conn.ConnectionString = "Data Source=<server>;Initial Catalog=TDE_Test;Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False;"; conn.Open(); SqlCommand cmd = new SqlCommand("StoreProcName", conn); cmd.CommandType = CommandType.StoredProcedure; SqlParameter parm = new SqlParameter("@return_value", SqlDbType.Int); parm.Direction = ParameterDirection.ReturnValue; cmd.Parameters.Add(parm); cmd.ExecuteNonQuery(); Label2.Text = parm.Value.ToString(); }</server>

更多推荐

从ASP迁移到ASP.NET C#

本文发布于:2023-11-16 22:21:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1607708.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:ASP   NET

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!