Tag: asp.net

如果存在则更新其他插入

我想知道下一段代码是否正确: SqlCommand cmd = new SqlCommand( “IF NOT EXISTS(SELECT count(*) from Raspunsuri where id_intrebare=2)” + “Insert INTO Raspunsuri VALUES(@raspuns,@cnp,@data,2,@ip,@idsesiune)” + “else” + “UPDATE Raspunsuri SET raspuns=@raspuns,cod_numeric_personal=@cnp,data_raspuns=@data,id_intrebare=2,ip_user=@ip,id_sesiune=@idsesiune WHERE id_intrebare=2”, con); 所有参数都是正确的,我想插入,但似乎这段代码不做插入或更新。你有任何建议吗?这是一个结合c#的SQL查询..

Thread.CurrentPrincipal.Identity vs HttpContext.User.Identity

可能重复: http.context.user和thread.currentprincipal之间的区别以及何时使用它们? 这两个在ASP.NET应用程序中有什么区别? 我知道当用户通过FormsAuthentication身份validation时,会设置HttpContext.User.Identity 。 但什么时候设置Thread.CurrentPrincipal.Identity ? 他们总是保持相同的价值吗? 对于无法访问HttpContext的应用程序的其他层,这仍然适用吗?

如何在MVC中创建动态子域?

我已将我的网站托管为www.sample.com,但我需要 -user1.sample.com -user2.sample.com -user3.sample.com 可能吗? 每个用户作为子域名。

如何使用ROW_NUMBER对gridview和SQL自定义查询进行分页

我有一个页面执行自定义查询,它保存在数据库的某个地方。 我需要能够在gridview上启用分页。 例如,查询保存在数据库中,如下所示: select * from requestbases 这将返回10,000行。 使用下面的方法,我返回10行。 public DataTable GetGenericResults(string strsql, int pageIndex) { StringBuilder sb = new StringBuilder(); sb.Append(“WITH MyPagedData as ( “); int indexFrom = strsql.IndexOf(“from”); sb.Append(strsql.Substring(0, indexFrom)); sb.Append(“, “); sb.Append(“ROW_NUMBER() OVER(ORDER BY RequestBaseId DESC) as RowNum “); sb.Append(strsql.Substring(indexFrom)); sb.Append(“) “); sb.Append(“SELECT * from MyPagedData where RowNum between @StartIndex and @StartIndex […]

如何获取DataSet.ReadXml以将DateTime属性解析为类型化DateTime

我有一个XML字符串,其中包含格式为“dd / MM / yyyy hh:mm:ss”的日期。 我正在使用DataSet.ReadXml()将此XML加载到数据集中。 如何确保此Date作为类型化DateTime存储在DataSet中,以便我可以相应地对其进行排序,格式化和RowFilter。 我的测试工具如下: ASPX页面: Test 代码背后: using System; using System.Data; using System.IO; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Xml.Linq; namespace Test { public partial class XmlDateTypeList : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { XDocument xDoc = new XDocument( new XElement(“List”, new […]

ASP.NET Repeater中的ImageButton不会触发OnClick事件处理程序

我在转发器控件中有一个ImageButton。 我已将一个eventhandler附加到ImageButton的OnClick事件。 但是,当我单击ImageButton时,事件不会被触发。 如果我错过了什么,请告诉我。 谢谢 我已经附加了aspx页面和codebehind文件 .add-tag-color-required { color:Red; } .add-tag-float-right { float:right; } function GetRadWindow() { var oWindow = null; if (window.radWindow) oWindow = window.RadWindow; //Will work in Moz in all cases, including classic dialog else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow; //IE (and Moz as well) return oWindow; } function Cancel() { // clean […]

从另一页面后面的代码访问变量

我有一个index.aspx(index.aspx.cs),它将包含使用Server.exectue(“body.aspx”)的body.aspx(body.aspx.cs); using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Data.SqlClient; using System.Configuration; using System.Collections; public partial class index : System.Web.UI.Page { public string text1 = “abc”; protected void Page_Load(object sender, EventArgs e) { } } 在index.asp.cs中,有一个变量text1,我想在body.aspx.cs中使用它,该怎么做? 谢谢

为什么找不到我的BasicAuthenticationModule?

我正在尝试创建自己的基本身份validation实现。 我将BasicAuthenticationModule.cs存储在我的solution\Modules ,其名称空间为: namespace Web_API.Modules { public class BasicAuthenticationModule2 : IHttpModule 我已将它添加到我的web.config中: 运行这个让我: HTTP Error 500.19 – Internal Server Error – Cannot add duplicate collection entry of type ‘add’ with unique key attribute ‘name’ set to ‘BasicAuthenticationModule’ 有人有线索吗?

Asyncfileupload文件预览未显示

我在更新面板中有一个Ajax异步文件上传控件。 我的上传工作正常,但上传完成后,我需要看到我上传的图片。 但它不起作用就是我所做的 function UploadComplete(sender, args) { var filename = args.get_fileName(); var contentType = args.get_contentType(); if (contentType.indexOf(‘image’) == -1) { document.getElementById(”).innerText = “Uploaded file must be an Image!”+ “” + args.get_errorMessage() + “”; document.getElementById(”).text.style.backgroundColor = “Red”; } else { var text = “” + filename + ” | ” + args.get_length() + ” bytes”+”Uploaded Succesfully”; […]

如何在treeview asp.net C#中获取客户端文件系统目录

嗨,我正在开发一个基于Web的ftp客户端应用程序,我想获取客户端文件系统目录并将它们填充到树视图中我尝试此代码,但它将给出我的应用程序运行的系统(服务器)的目录,我希望当任何用户通过浏览器访问我的应用程序我想加载用户文件系统目录。 这是我试过的代码: private void fillTree() { DirectoryInfo directory; string sCurPath = “”; // clear out the old values TreeView2.Nodes.Clear(); // loop through the drive letters and find the available drives. foreach (char c in driveLetters) { sCurPath = c + “:\\”; try { // get the directory informaiton for this path. directory = new DirectoryInfo(sCurPath); […]