Tag: asp.net

ASP.NET在Javascript中设置hiddenfield值

我不知道如何在Javascript中设置hiddenField的值。 有人可以告诉我该怎么做吗? 使用Javascript: document.getElementById(‘hdntxtbxTaksit’).value = “”; HTML: 错误:“无法获取属性值”的值:’对象为空或未定义”

ASP.NET MVC 5从特定角色获取用户

如何显示特定角色中所有用户的列表。 我将IdentityRole模型附加到我的View,并为其分配了“Admin”角色。 到目前为止我只能得到UserId。 @model Microsoft.AspNet.Identity.EntityFramework.IdentityRole @Html.DisplayNameFor(model => model.Name) // Shows ‘Admin’ @foreach (var item in Model.Users) { @Html.DisplayFor(modelItem => item.UserId) } 一种可能的解决方案是在控制器中创建用户列表并将其附加到视图。 问题是我还需要角色本身的数据。

有条件地禁用ASP.NET MVC控制器

有条件地禁用ASP.NET MVC控制器的最佳方法是什么? 如果web.config中的某些值为“true”,我希望能够访问控制器操作,如果是“false”,则我想访问404 我应该写自己的属性吗? 更新 :寻找比动作filter属性更优雅的解决方案(能够将非常量参数传递给属性构造函数) [AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = true)] public class CloseForSomeSettingAttribute : ActionFilterAttribute { public override void OnActionExecuting(ActionExecutingContext filterContext) { bool mySettingValue = MySettingManager.GetMySettingValue(); if (mySettingValue) { filterContext.Result = new HttpStatusCodeResult(404); } else { base.OnActionExecuting(filterContext); } } }

将Class的实例作为参数传递给Attribute构造函数

我需要在我的自定义属性中使用类/模型的实例(用于访问非静态成员)。 public class LoginModel { [AutoComplete(currentInstance)] //pass instance of class or CompanyNames public string DepartmentName { get; set; } public string[] DepartmentNames { get {…} } } 有没有办法在不使用new()或Reflection的情况下执行此操作。

删除小时:秒:DateTime对象中的毫秒数

我正在尝试从DateTime对象创建一个字符串,产生格式mm:dd:yyyy 。 通常, DateTime对象为mm:dd:yyyy hrs:min:sec AM/PM 。 有没有办法快速删除hrs:min:sec AM/PM DateTime的hrs:min:sec AM/PM部分,这样当我将其转换为ToString()它只会导致mm:dd:yyyy ?

即使在Asp.Net流中使用ConfigureAwait(false)后死锁也是如此

即使在使用ConfigureAwait(false)后我也遇到了死锁,下面是示例代码。 根据示例http://blog.stephencleary.com/2012/02/async-and-await.html(#Avoding Context),这不应该达到死锁。 这是我的class级 : public class ProjectsRetriever { public string GetProjects() { … var projects = this.GetProjects(uri).Result; … … } private async Task<IEnumerable> GetProjects(Uri uri) { return await this.projectSystem.GetProjects(uri, Constants.UserName).ConfigureAwait(false); } } 该类来自共享库: public class ProjectSystem { public async Task<IEnumerable> GetProjects(Uri uri, string userName) { var projectClient = this.GetHttpClient(uri); var projects = await projectClient.GetProjects(); […]

将dd / MM / yyyy hh:mm:ss.fff从String转换为C#中的DateTime

我试图将以下格式的字符串dd / MM / yyyy hh:mm:ss.fff转换为DateTime值 最简单的方法? BTW IFormatProvider culture = new CultureInfo(“en-US”, true); DateTime.ParseExact(timeString, “dd/MM/yyyy hh:mm:ss.fff”,culture); 引发无效的时间exception 例如。 11/12/2009 13:30:00.000其中12是月份(我知道很奇怪)

添加服务引用提供exception:无法连接到远程服务器

从控制台应用程序客户端调用时,我的WCF服务返回结果。 然而,它正在显示 例外:无法连接到远程服务器 实际错误: 无法调用该服务。 可能的原因:服务离线或无法访问; 客户端配置与代理不匹配; 现有代理无效。 有关更多详细信息,请参阅堆栈跟踪。 您可以尝试通过启动新代理,还原到默认配置或刷新服务来进行恢复。 错误详情: 由于内部错误,服务器无法处理请求。 有关错误的更多信息,请在服务器上启用IncludeExceptionDetailInFaults(来自ServiceBehaviorAttribute或配置行为)以将exception信息发送回客户端,或者根据Microsoft .NET Framework SDK文档启用跟踪和检查服务器跟踪日志。 服务器堆栈跟踪:System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(消息回复,MessageFault错误,字符串操作,MessageVersion版本,FaultConverter faultConverter),位于System的System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime操作,ProxyRpc和rpc)。 ServiceModel.Channels.ServiceChannel.Call(String action,Boolean oneway,ProxyOperationRuntime operation,Object [] ins,Object [] outs,TimeSpan timeout)在System的System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall,ProxyOperationRuntime操作)。 ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage消息) 在[0]处重新抛出exception:在System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg,IMessage retMsg)处于IJiraService.GetProjects的System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&msgData,Int32类型)处( )在JiraServiceClient.GetProjects() 请注意,当Fiddler运行时,该服务工作正常。但是,如果我关闭Fiddler,那么它显示exception: 这是Fiddler日志(当我得到数据时): TTP / 1.1 200连接成立日期:2015年8月6日星期四14:39:22 GMT代理连接:Keep-Alive Via:1.1 localhost.localdomain 加密的HTTPS流量流经此CONNECT隧道。 在Fiddler中启用了HTTPS解密,因此在此隧道中运行的解密会话将显示在“Web会话”列表中。 安全协议:Tls Cipher:Aes128 128bits哈希算法:Sha1 160bits密钥交换:ECDHE_RSA(0xae06)256bits ==服务器证书========== [主题] CN = * .atlassian.net,O =“Atlassian […]

服务器控件的内联页面代码永远不会起作用

我尝试了下面的代码,我尝试使用内联表达式,如<%,, <%=,为什么我不能使用内联表达式与服务器端控件? 在我的第一行代码中,我试图遵循这篇文章,但它不起作用。 为什么? http://todotnet.com/post/2009/04/18/Working-around-Cannot-create-an-object-of-type-SystemBoolean-from-its-string-representation.aspx <asp:TextBox ID="txtDate" runat="server" Text='’ meta:code=”> <asp:TextBox ID="TextBox1" runat="server" Text='’> <asp:TextBox ID="TextBox2" runat="server" Text='’>

如何在我的自定义表而不是aspnet用户中使用哈希密码保存新记录?

我使用asp.net身份创建新用户但收到错误: 无法将值NULL插入列’Id’,表’Mydb.dbo.AspNetUsers’; 列不允许空值。 INSERT失败。\ r \ n语句已终止 但是在这里我没有像AspNetUsers这样的表,而是我拥有自己的用户表。 代码: Web.config:2个连接字符串 IdentityModel.cs: public class ApplicationUser : IdentityUser { public async Task GenerateUserIdentityAsync(UserManager manager) { // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType this.SecurityStamp = Guid.NewGuid().ToString(); var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie); // Add custom user claims here return userIdentity; } public string Id […]