Tag: asp.net

Int32的值太大或太小

可能重复: int32的最大值是多少? Mobileno = Convert.ToInt32(txmobileno.Text); 我插入数据库时​​遇到的错误

entity framework核心:与同一实体的多对多关系

我试图与同一个实体映射多对多关系。 User实体具有用于Contacts的IList数据字段,用于存储用户的联系人/朋友信息: public class User : DomainModel { public virtual IList Contacts { get; protected set; } //irrelevant code omitted } 当我尝试使用流畅的API来映射这么多对多的关系时,它给我带来了一些麻烦。 显然,当我在user.Contacts属性上使用HasMany()时,它没有WithMany()方法来调用next。 Visual Studio中的intellisense仅显示WithOne() ,但不显示WithMany() 。 modelBuilder.Entity().HasMany(u => u.Contacts).WithMany() // gives compile time error: CS1061 ‘CollectionNavigationBuilder’ does not contain a definition for ‘WithMany’ and no extension method ‘WithMany’ accepting a first argument of type […]

使用reflection在类实例中按名称获取属性的值

可以说我有 class Person { public Person(int age, string name) { Age = age; Name = name; } public int Age{get;set} public string Name{get;set} } 我想创建一个接受包含“age”或“name”的字符串的方法,并返回一个具有该属性值的对象。 像下面的伪代码: public object GetVal(string propName) { return .value; } 我怎么能用reflection做到这一点? 我使用asp.net 3.5编译,c#3.5

System.Net.Mail.SmtpException:操作已超时。 asp.net中的错误使用godaddy托管发送邮件代码

我正在使用以下代码安静使用godaddy托管发送邮件。 但它抛出System.Net.Mail.SmtpException: The operation has timed out. protected void sendmail() { var fromAddress = “frommailid@site.com”; // any address where the email will be sending var toAddress = “to@gmail.com”; //Password of your gmail address const string fromPassword = “mypassword”; // Passing the values and make a email formate to display string subject = “HI test mail […]

在页面中查找控件

HTML 码 protected void a_Click(object sender,EventArgs e) { Response.Write(((Button)FindControl(“a”)).Text); } 这段代码工作正常。 但是,这段代码: HTML 码 protected void a_Click(object sender, EventArgs e) { Response.Write(((Button)FindControl(“a”)).Text); } 此代码不起作用, FindControl返回Null – 为什么这样? FindControl方法适用于一个简单的页面,但在母版页中,它不起作用吗? a的ID更改为ctl00_ContentPlaceHolder1_a – 如何找到控件?

名称空间’System.Management’中不存在’ManagementClass’

嗨,我正在使用此方法获取mac地址 public string GetMACAddress() { System.Management.ManagementClass mc = default(System.Management.ManagementClass); ManagementObject mo = default(ManagementObject); mc = new ManagementClass(“Win32_NetworkAdapterConfiguration”); ManagementObjectCollection moc = mc.GetInstances(); foreach (var mo in moc) { if (mo.Item(“IPEnabled”) == true) { return mo.Item(“MacAddress”).ToString(); }else return null; } } 但我收到这个错误 Compiler Error Message: CS0234: The type or namespace name ‘ManagementClass’ does not exist in the […]

DbContext已经处理完毕

我使用ASP.NET MVC 4和SQL Server 2008开发了一个Web应用程序,我创建了ContextManager类,在所有页面中只有一个数据库上下文。 public static class ContextManager { public static HotelContext Current { get { var key = “Hotel_” + HttpContext.Current.GetHashCode().ToString(“x”) + Thread.CurrentContext.ContextID.ToString(); var context = HttpContext.Current.Items[key] as HotelContext; if (context == null) { context = new HotelContext(); HttpContext.Current.Items[key] = context; } return context; } } } 它在大多数页面中都能正常工作,但是在注册页面出现了问题,我的上下文因以下错误而被废弃: 由于已经处理了DbContext,因此无法完成操作。 public ActionResult Register ( […]

无法更新数据库,因为它是只读的

我已经设置了我的网站以使用ASP.NET成员资格。 尝试在我的开发机器上使用它时一切正常但是当我把它放在Web服务器上并尝试登录时,我收到此错误: “Failed to update database “C:\INETPUB\WWWROOT\APP_DATA\ASPNETDB.MDF” because the database is read-only. “

将SqlDataSource转换为DataTable和DataView

我有以下SqlDataSource ,我想将其转换为DataView并从中读取一列: SELECT dbo.Divisions.DivisionShortcut, COUNT(DISTINCT dbo.UserQuiz.Username) AS [Number of Participants] FROM dbo.Divisions INNER JOIN dbo.employee ON dbo.Divisions.SapCode = dbo.employee.DivisionCode INNER JOIN dbo.UserQuiz ON dbo.employee.Username = dbo.UserQuiz.Username INNER JOIN dbo.Quiz ON dbo.UserQuiz.QuizID = dbo.Quiz.QuizID WHERE (dbo.Quiz.QuizID = @QuizID) GROUP BY dbo.Divisions.DivisionShortcut 此SqlDataSource允许用户输入测验的编号,它将检索该测验中的参与者总数。 我想将此SqlDataSource转换为DataTable并从中读取一列。 那怎么办呢?

System.Web.HttpException文件不存在 – 页面加载很好(ASP.NET)

每次我的ASP.NET-Application抛出错误时,我都在使用Log4Net并进行日志记录: protected void Application_Error(object sender, EventArgs e) { Exception ex = Server.GetLastError(); Log.Error(“An error occurred”, ex); } 唉,每次我访问我的应用程序页面时,都会捕获到System.Web.HttpException ,“文件不存在”。 这是堆栈跟踪: bei System.Web.StaticFileHandler.GetFileInfo(String virtualPathWithPathInfo, String physicalPath, HttpResponse response) bei System.Web.StaticFileHandler.ProcessRequestInternal(HttpContext context, String overrideVirtualPath) bei System.Web.DefaultHttpHandler.BeginProcessRequest(HttpContext context, AsyncCallback callback, Object state) bei System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() bei System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) 我没有任何线索如何调试,这发生在我的ASP.NET开发服务器和IIS 7.5上我部署它。