从ASP迁移到ASP.NET C# [英] Migrating to ASP.NET C# from ASP

查看:100
本文介绍了从ASP迁移到ASP.NET C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

全部,



我已经尝试了几天将下面的代码转换为asp.net c#。



这是一个非常简单的页面。



- 获取当前登录用户并将其存储在名为strFullUserName的变量中,例如domain\johnsonM

- 然后我查询针对名为usp_GetDisplayName的存储过程的用户名示例Mike Johnson。

- 然后它将在strFullUserName中存储用户全名(Mike Johnson)



我之前从未使用过C#,我已经完成了网站的其余部分,现在我需要在网站上显示完整用户名而不查询Active目录。我已经在ASP中多次使用下面的代码完成了这个,没有任何问题,只是不确定如何做到这一点是ASP.net和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.net 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.net 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#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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