Tag: asp.net

我可以按任何顺序将中间件应用于应用程序吗?

在C#ASP.NET中,中间件应用程序的顺序是否重要? 以下2个代码段: public class Startup { … public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { setUpMVCRoutes(app); app.UseSwaggerUi(“foobar/api”, “/foobar/v3/api.json”); app.UseSwaggerGen(“foobar/{apiVersion}/api.json”); app.UseDefaultFiles(); app.UseIISPlatformHandler(options => options.AuthenticationDescriptions.Clear()); app.UseStaticFiles(); app.UseIdentity(); app.UseCookieAuthentication(); } … } 还有这个 public class Startup { … public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { app.UseIdentity(); app.UseCookieAuthentication(); app.UseIISPlatformHandler(options => options.AuthenticationDescriptions.Clear()); app.UseDefaultFiles(); app.UseStaticFiles(); setUpMVCRoutes(app); app.UseSwaggerGen(“foobar/{apiVersion}/api.json”); app.UseSwaggerUi(“foobar/api”, […]

将加载配置添加到asp.net核心中的注入依赖项中

在我的Asp.Net Core API中,我有一些我正在使用我的Startup.cs中的services.AddTransient方法注入的存储库类。 services.AddTransient(); 我还将我的appsettings.json的一部分加载到Startup.cs中的自定义对象中 services.Configure(Configuration.GetSection(“AppSettings”)); 我的存储库类需要从appsettings.json加载数据库连接字符串。 有没有办法将这些设置直接注入存储库类? 或者是由控制器的构造函数将连接字符串传递给存储库类?

在ASPX脚本块中声明一个类然后将其存储在会话中

我在做一些我认为应该非常可行的事情时遇到了麻烦。 也许有人可以告诉我我错过了什么。 我只能将我的C#代码添加到服务器端脚本块中的.aspx页面(后面没有代码)。 我想在ASPX页面上定义一个新类(同样不创建任何其他文件)(这将是一个嵌套类),然后在Session中存储这些对象的List以在回发之间和用户花费一些时间之后保留其他页面然后返回到有问题的页面。 这是我的代码…… protected List AssignmentSearchResults { get { if (Session[“SearchResults”] == null) Session[“SearchResults”] = new List(); return (List)Session[“SearchResults”]; } set { Session[“SearchResults”] = value; } } public class Part { public string Id { get; set; } public string Description { get; set; } public string Type { get; set; } public […]

将对象数组作为TempData 传递给视图

我想将一个post操作中的两个值返回到RedirectToAction的视图。 TempData[]似乎是理想的选项,因为数据仅用于在用户保存后显示成功消息。 我想在成功消息中显示用户刚刚保存的图像的小缩略图和已保存项目的标题。 目前我将所有数据作为new MvcHtmlString TempData[“SaveMsg”] = new MvcHtmlString(” ” + model.Name + ” has been saved. ” ) ; 我想把它作为object[]发送object[] TempData[“SaveMsg”] = new object[]{model.ImageUrl , model.Name} 然后我就可以将对象传递给HtmlHelper并编写消息显示的条件。 我只是不知道如何访问视图中的对象 @TempData[“SaveMsg”][0] // (Oo) // Error Cannot apply indexing with // [] to an expression of type ‘object’ 这有可能吗?

正则表达式在ASP.net中的强密码

我需要检查包含以下4个中的3个的密码: 小写字母 大写字母 数字字符 特殊字符(如%,$,#,…) 密码长度必须在6到20个字符之间。 我目前有这个: public void ChangePassword(string password) { Regex regex1 = new Regex(“^(?=.*[0-9])(?=.*[az])(?=.*[AZ]){6,20}$”); Regex regex2 = new Regex(“^(?=.*[0-9])(?=.*[az])(?=.*?[#?!@$%^&*-]){6,20}$”); Regex regex3 = new Regex(“^(?=.*[0-9])(?=.*[AZ])(?=.*?[#?!@$%^&*-]){6,20}$”); Regex regex4 = new Regex(“^(?=.*[az])(?=.*[AZ])(?=.*?[#?!@$%^&*-]){6,20}$”); Regex regex5 = new Regex(“^(?=.*[0-9])(?=.*[az])(?=.*[AZ])(?=.*?[#?!@$%^&*-]){6,20}$”); Match match1 = regex1.Match(password); Match match2 = regex2.Match(password); Match match3 = regex3.Match(password); Match match4 = regex4.Match(password); Match match5 […]

错误消息:初始化字符串的格式不符合从索引0开始的规范

我搜索了SO,但没有找到我的错误的解决方案。 我正在使用VS 2013和SQL Server 2014。 以下是我的连接字符串: using (SqlConnection sqlConnection = new SqlConnection(“cnInvestTracker”)) { } 我的web.config是: 当代码执行using行时,我收到一条错误消息。 错误消息是: 初始化字符串的格式不符合从索引0开始的规范。 导致错误的原因是什么?

unit testingASP.Net Web应用程序的App_Code

我想创建一个ASP.Net Web应用程序,我想为它编写unit testing。 但我的unit testing项目在我的Web应用程序的App_Code目录中看不到任何类型。 重现步骤 (如果您已经知道如何创建默认的webforms Web应用程序并添加app_code文件夹,请跳过图像) 打开Visual Studio。 选择File-> New-> Project。 选择模板 – > Visual C# – > Web。 选择ASP.Net Web应用程序。 选择“确定”。 选择“Web窗体”。 选中“添加unit testing”。 单击确定。 在解决方案资源管理器中,右键单击Web应用程序,然后选择“添加 – >添加ASP.Net文件夹 – > App_Code”。 将新项添加到App_Code,名为“Util.cs”。 向文件添加一个函数,所以内容是: using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace WebApplication1.App_Code { public class Util { public static int getMeaningOfLife() […]

viewstate在response.redirect上消失

在我的asp.net c#页面上,我有两个带有ajax CalendarExtenders的文本框(开始和结束日期)。 用户选择开始日期然后选择结束日期。 在选择结束日期时,我绑定我的网格,如下所示; protected void calEndDate_TextChanged(object sender, EventArgs e) { BindGrid(); } 在网格中,我有一个带有以下代码的命令按钮 protected void gvAllRoomStatus_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == “Manage”) { GridViewRow row = gvAllRoomStatus.Rows[Convert.ToInt16(e.CommandArgument)]; int BookingID = Convert.ToInt32(row.Cells[1].Text); DataClassesDataContext context = new DataClassesDataContext(); Session[“BookingID”] = BookingID; Response.Redirect(“CheckIn.aspx”); } } 当用户转到该页面并单击后退按钮时,所有选定的日期和gridview数据都会消失。 任何想法为什么观点正在消失?

从Crystal Report中的多个表推送数据

我有一个名为CR1的水晶报告。 现在我想将多个表中的数据填充到我的水晶报告CR1中。 我正在使用VS2008,编码语言是ASP.net中的C#任何帮助将不胜感激。

DropDownList asp.net中所选项目的文本

在页面加载中,我填充下拉列表,如下所示: protected void Page_Load(object sender, EventArgs e) { string buildingTypeSoldier = “soldier”; var soldierBuilding = from b in dc.Buildings where b.buildingtype == buildingTypeSoldier select b.buildingname; ddlSoldierBuildings.DataSource =soldierBuilding; ddlSoldierBuildings.DataBind(); } 但是当我尝试将同一页面上的标签文本设置为selectetitem.text时,我只获得列表中的第一项,而不是我选择的项目。 我尝试使用这样的按钮设置文本: protected void btnBuySoldierBuilding_Click(object sender, EventArgs e) { lblTestlabel.Text = ddlSoldierBuildings.SelectedItem.Text; } 下拉列表包含从我的数据库中获取的树项目,营房,射手范围和稳定。 单击按钮时页面加载是否覆盖我的选择? 我怎么解决这个问题?