Tag: asp.net

你能阻止你的ASP.NET应用程序关闭吗?

我想我听说ASP.NET应用程序会在闲置一段时间后关闭(即没有访问者)。 有没有办法防止这种行为发生? 我有一个计时器,它运行来自global.asax.cs application_start事件的一些代码,并希望确保它继续运行,即使没有访问者访问该站点。 提前致谢!

如何在MVC5项目中使用Json.NET进行JSON模型绑定?

我一直在网上寻找答案或例子,但还找不到一个。 我只想更改默认的JSON序列化程序,用于在模型绑定到JSON.NET库时反序列化JSON。 我发现这个 SOpost,但到目前为止无法实现它,我甚至看不到System.Net.Http.Formatters命名空间,也看不到GlobalConfiguration 。 我错过了什么? UPDATE 我有一个ASP.NET MVC项目,它基本上是一个MVC3项目。 目前我的目标是.NET 4.5并使用ASP.NET MVC 5和相关的NuGet包。 我没有看到System.Web.Http程序集,也没有看到任何类似的命名空间。 在这种情况下,我想注入JSON.NET作为JSON类型请求的默认模型绑定器。

方括号在下面的代码中是什么意思?

我从http://msdn.microsoft.com/en-us/library/dd584174(office.11​​).aspx获取以下代码,用于在webpart工具窗格中添加自定义属性。 方括号( [] )在下面的代码中的含义是什么? [Category(“Custom Properties”)] [WebPartStorage(Storage.Personal)] [FriendlyNameAttribute(“Custom Color”)] [Description(“Select a color from the dropdown list.”)] [Browsable(true)] [XmlElement(typeof(System.Drawing.KnownColor))] public System.Drawing.KnownColor MyColor { get { return _myColor; } set { _myColor = value; } }

我是否可以为ASP.NET SOAP Web服务提供可选参数

我想用这个签名构建一个web服务,如果param2留空,它不会抛出exception。 这可能吗? [WebMethod] public string HelloWorld(string param1, bool param2) { } exception是在尝试将空字符串转换为布尔值时抛出的System.ArgumentException。 到目前为止没有奏效的想法: Web服务不允许使用方法重载,例如 public string HelloWorld(string param1) { return HelloWorld(param1, false); } 如下所示: 让bool自杀的bool? 。 同样的例外。 操纵WSDL,看到这个答案 我的问题与这个问题有关 ,但唯一的答案是WCF合同,我还没有使用过。

如何在动态创建的ASP.net控件中动态创建ASP.net控件

我正在使用ASP.net进行申请。 我有一个按钮,点击时会生成一些html,一些asp文本框和一个asp按钮(第二个按钮)。 据我所知,这很好用。 现在我想要的是,当我点击第二个新创建的按钮时,我希望它创建一些html + asp.net文本框。 这对我来说似乎有点困惑,有没有更简单的方法呢? 我似乎无法弄清楚,我在按钮2的onclick事件上创建,但它还不存在。 非常感谢。 认为可能会更容易看到代码,以防万一你想知道发生了什么。 namespace ConnorMackayWebForm { public partial class InspectionCreate : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { //Set the initial amount of areas and hazards int areaCount = 0; int hazardCount = 0; //Check if the viewstate with the area count already exists if (ViewState[“areaCount”] […]

下载function在asp.net的更新面板中不起作用

我有一个包含FormView的Web用户控件。 formview显示求职者的详细信息。 我已经为“下载简历”链接提供了一个按钮,以便admin / HR可以下载简历。 我已将此控件放在包含UpdatePanel的aspx页面中。 除下载链接外,一切正常。 我在donwload链接按钮上给出了一个命令,并且一个函数与该命令相关联以开始下载。 以下是我实施的代码 – //Command on ‘Download’ link button within FormView protected void lnkDownload_Command(object sender, CommandEventArgs e) { if (e.CommandName.Equals(“Download”)) { StartDownload(e.CommandArgument.ToString()); } } //My routine to download document //sFileInfo contains filepath$==$mimetype protected void StartDownload(string sFileInfo) { string[] d = sFileInfo.ToString().Split((new string[] { “$==$” }), StringSplitOptions.None); string filename = […]

ASP.NET使用SqlConnection连接MySQL

这是web.config保存的连接字符串: 这是连接数据库的代码: protected bool CheckPasswordBySqlServer(string strEmail, string strPsw) { if (strEmail.ToLower() == “admin”) { return false; } string str = “select id,Rank,RankEnc,ParentUser,Company from tbl_User where userName=@UserName and password1=@password”; private string strConn = ConfigurationManager.AppSettings[“conn”].ToString(); SqlConnection sqlConnection = new SqlConnection(strConn); bool flag = false; try { try { sqlConnection.Open(); SqlCommand sqlCommand = new SqlCommand(str, sqlConnection); sqlCommand.Parameters.AddWithValue(“UserName”, strEmail); […]

使用iTextsharp为PDF添加页眉和页脚

如何在pdf中为每个页面添加页眉和页脚。 Headed将只包含一个文本页脚将包含pdf的文本和分页(页:1/4) 这怎么可能 ? 我尝试添加以下行,但标题不会显示在pdf中。 document.AddHeader(“Header”, “Header Text”); 这是我用于生成PDF的代码: protected void GeneratePDF_Click(object sender, EventArgs e) { DataTable dt = getData(); Response.ContentType = “application/pdf”; Response.AddHeader(“content-disposition”, “attachment;filename=Locations.pdf”); Response.Cache.SetCacheability(HttpCacheability.NoCache); Document document = new Document(); PdfWriter.GetInstance(document, Response.OutputStream); document.Open(); iTextSharp.text.Font font5 = iTextSharp.text.FontFactory.GetFont(FontFactory.COURIER , 8); PdfPTable table = new PdfPTable(dt.Columns.Count); PdfPRow row = null; float[] widths = new float[] { […]

SQL注入攻击防范:我从哪里开始

我希望使我的网站安全抵御SQL注入攻击。 有没有人有任何良好的链接,以使网站在ASP.NET站点(c#,Web表单)中抵御这些类型的攻击? 编辑: 我应该指出我正在使用entity framework

写入CSV文件并导出?

在C#ASP.net中,有人可以告诉我如何将数组/列表中的条目写入服务器上的CSV文件,然后打开文件吗? 我认为第二部分可能是 – Response.Redirect(“ http://myserver.com/file.csv ”),但不确定如何在服务器上写入文件。 此外,如果许多用户访问此页面,是否每次生成新的CSV文件或覆盖同一文件更好? 如果两个用户都尝试访问相同的CSV文件等,是否会出现读/写/锁定问题? 更新: 这可能是一个愚蠢的问题,我在Google上搜索过,但我无法找到明确的答案 – 你如何将CSV文件写入网络服务器并将其导出到C#ASP.net? 我知道如何生成它,但我想将其保存到www.mysite.com/my.csv然后导出它。