Tag: asp.net

如何在asp.net中显示警告框

我有一个提交按钮的注册页面。 我希望在“用户点击提交按钮”之后显示一个警告框,之后“用户输入的数据将插入数据库中”。 int i = obj.IU_SubscriberMaster(0, txtFirstname.Text, txtLastname.Text, txtEmail.Text, txtPassword.Text); if (i > 0) { Call ErrorTrap(“errormsg”); } 这是我想要显示警报的地方。 我用了 function alerts(str) { return false; } 而不是通过创建一个函数errortrap public void ErrorTrap(string str) { if (!ClientScript.IsStartupScriptRegistered(“alert”)) { Page.ClientScript.RegisterStartupScript(this.GetType(), “alert”, “alerts(‘” + str + “‘);”, true); } } 但它不起作用 有人可以帮忙吗?

使用带有LinqDataSource的通配符

我目前在ASP.NET页面上有一个LinqDataSource,它用作FormView的数据源。 我需要根据通过查询字符串传递的参数动态更改where子句。 我有这个工作正常,除了我希望最终用户能够使用通配符: 一个 ”?” 用于表示单个字符。 “*”表示多个字符。 看起来很简单,我需要做的就是使用LIKE运算符并替换? with _ (匹配单个字符), * with % (匹配所有字符)。 下面是执行花式步法(在PageLoad上调用)的方法,除了我的通配符被转义外它工作得很好。 private void ApplyFilter(ref LinqDataSource lds) { if (Request.QueryString.Keys.Count > 0) { string where = “”; int counter = 0; foreach (string key in Request.QueryString.Keys) { if (Request.QueryString[key] != “”) { if (counter == 0) { where += key + […]

从MySql返回最后插入的id

我在使用以下查询时遇到了一些麻烦: START TRANSACTION; SET @LASTID = 0; INSERT INTO `Accounts` (`Col1`,`col2`,`col3`,`col4`) VALUES (@param1,@param2,@param3,@param4); SET @LASTID = last_insert_id(); — This is what I need INSERT INTO `Users` (`usr1`,`usr2`,`usr3`,`usr4`) VALUES (@usr1,@usr2,@usr3,@usr4); SELECT @LASTID; COMMIT; 基本上,我需要从accounts表中返回最后插入的ID,但是当运行SELECT @LASTID时,MySql返回一个blob而不是一个值,我在C#asp.net中访问时遇到了问题。 有没有简单的方法将此值作为int / varchar? 从代码中的blob转换我感觉有点矫枉过正,我想把它提升到Mysql服务器。 提前致谢。

DropDownList中的System.Data.DataRowView

我正在尝试使用列中的值填充下拉列表。 现在问题是:我没有在下拉列表中获得实际值(像印度(+61)这样的国家代码)。 相反,我在下拉列表中获得“System.Data.DataRowView”(多次)。 public void bind() { DataSet ds1 = new DataSet(); SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings[“ConnectionString”]); con.Open(); string strQuery = “select CountryCode from AUser”; SqlCommand cmd = new SqlCommand(strQuery, con); using (SqlDataAdapter da = new SqlDataAdapter(cmd)) da.Fill(ds1, “AUser”); ddlMobile.DataSource = ds1.Tables[“AUser”]; ddlMobile.DataBind(); con.Close(); } 我在page_load上调用bind方法。 CountryCode数据类型是varchar(50) ,值类似于India(+91) , Australia(+61)等…

如何从CLR线程池而不是ASP.NET池创建ASP.NET页面中的线程?

如果我在ASP.NET页面上创建一个新线程,则IsThreadPoolThread属性为true。 第一个问题是,它来自ASP.NET池还是CLR池? 第二个问题是,如果它是从ASP.NET池那么如何从CLR创建一个线程而不使用ASP.NET池? 我需要一个长期运行请求的同步解决方案( 全文 )。

ASP.NET中嵌套的SqlDataReader“已经是一个开放的DataReader”exception

我想在下面的代码中使用嵌套的SqlDataReader,但是我无法实现它。我得到“System.InvalidOperationException:已经有一个与此命令关联的打开的DataReader,必须先用代码关闭”。 有什么建议 c = “select user_Reps.rep_key,Officers.Officer_Name from user_Reps left join Officers on user_Reps.rep_key = Officers.Officer_code where [user_key]=”+userCode; if (c == null) c = sr.ReadToEnd(); try { SqlCommand cmd = new SqlCommand(c, cn); cn.Open(); SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection); List<Dictionary> list = new List<Dictionary>(); SqlDataReader rdr2; while (rdr.Read()) { string c2 = “select Active_Clients.Clients_code,Active_Clients.Clients_Name,Active_Clients.Geo_code from Active_Clients where […]

使用WebClient获取远程图像会产生粒状GIF,无法处理PNG + BMP

问候! 我正在创建一个Web表单原型(ImageLaoder.aspx),它将返回一个图像,以便它可以像其他Web表单/网页这样的简单示例一样使用: 到目前为止,它加载JPG没有问题,但是与原始数据相比,GIF看起来“颗粒状”,而BMP和PNG导致以下exception: System.Runtime.InteropServices.ExternalException:GDI +中发生一般错误 到目前为止我的代码看起来像这样: protected void Page_Load(object sender, EventArgs e) { string l_filePath = Request.QueryString[“i”]; System.Drawing.Image l_image = GetImage(l_filePath); if (l_image != null) { System.Drawing.Imaging.ImageFormat l_imageFormat = DetermineImageFormat(l_filePath); WriteImageAsReponse(l_image, l_imageFormat); } } private System.Drawing.Image GetImage(string filePath) { WebClient l_WebClient = new WebClient(); byte[] l_imageBytes = l_WebClient.DownloadData(filePath); System.Drawing.Image l_image = null; using (MemoryStream l_MemStream […]

使用表单身份validation获取Windows用户名的更好方法是什么?

我inheritance了一个使用表单身份validation的项目,但最近的function请求要求我获取某些用户的Windows用户名。 这是一个使用Forms身份validation的网站(我不想改变它,此时会有太多工作)但我有一个function请求,允许我们的内部用户更容易登录(通常无需放入他们的密码或用户名)。 我当前的方法是可怕的,它涉及检查IP地址,看看他们是否从我们的一个IP连接,如果是,将它们重定向到使用Windows身份validation的单独项目,然后将其重定向回原始页面包含其用户名的查询字符串(如果我被迫继续使用此方法,我可能需要加密它,尽管它仍然不如我想的那样安全)。 我可以在我的应用程序中相对容易地执行Windows身份validation,但是困难的部分是获取Windows用户名。 我无法弄清楚如何做到这一点,因此我非常难看的方法。 任何帮助将不胜感激。 编辑:我的辅助应用程序只是这样做: string username = HttpContext.Current.User.Identity.Name; string retpath = Request.QueryString[“retpath”]; Response.Redirect(“http://” + retpath + “?id=” + username);

禁止NTLM身份validation对话框

码 我创建了一个将表单身份validation与集成Windows身份validation相结合的登录页面。 public partial class Login : System.Web.UI.Page { // http://www.innovation.ch/personal/ronald/ntlm.html // http://curl.cofman.dk/rfc/ntlm.html // http://blogs.msdn.com/b/chiranth/archive/2013/09/21/ntlm-want-to-know-how-it-works.aspx protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (Request.Headers[“Authorization”].IsNullOrEmpty()) { Response.StatusCode = 401; Response.AddHeader(“WWW-Authenticate”, “NTLM”); Email.SendMailToDebugger(“Auth”, “No Auth”); //Response.End(); } else if (Request.Headers[“Authorization”].StartsWith(“Negotiate”)) { Response.StatusCode = 401; Response.AddHeader(“WWW-Authenticate”, “NTLM”); Email.SendMailToDebugger(“Auth”, “Negotiate Auth”); Response.End(); } else if (Request.Headers[“Authorization”].StartsWith(“NTLM”)) […]

ASP.NET Fire和忘记(单向)Web服务

我在ASP.NET中创建了一个常规的旧ASMX Web服务,并将SoapDocumentMethod(OneWay = true)]添加到函数调用中,因为我已经读过这应该调用Asynchronous。 但是我在我的代码中调用它,它肯定不会使调用异步,我的页面只是坐在那里等待函数完成工作。 是什么赋予了? [SoapDocumentMethod(OneWay = true)] [WebMethod(EnableSession = true)] public void UpdateAccounts() { //do work } //call the function GlobalServices service = new GlobalServices(); service .UpdateAccounts()