全部,如果在会话超时时进行ajax调用,我试图重定向到登录页面.这是我到目前为止所做的.
为所有操作定义操作筛选器.
public class AuthenticateFilterAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
base.OnActionExecuting(filterContext);
var routeDataSet = filterContext.RouteData;
if (LoginUser.LoginAdministrator == null)
{
//if the useinfo stored in session is timeout.
if (routeDataSet != null
&& routeDataSet.Values["controller"] != null
&& routeDataSet.Values["controller"].ToString().ToLower().Equals("login")
&& routeDataSet.Values["action"] != null
&& routeDataSet.Values["action"].ToString().ToLower().Equals("login"))
{
//if it is login action itself.let it be. don't do anything.
}
else
{
//redirect to login page.
filterContext.Result = new RedirectToRouteResult(
new RouteValueDictionary { { "controller", "Login" }, { "action", …Run Code Online (Sandbox Code Playgroud) 我曾在一个项目中使用32feet的 .NET库,我正在寻找移植到Mono Runtime的项目.
但是,由于32feet是用C/C++ for Windows编写的,然后包装在.NET中使用,我正在寻找一个等价的.
在过去的3天里,我一直在网上寻找替代方案,空手而归,所以现在是时候寻求帮助
我目前正在使用MVC4数据注释来处理验证.我正在开发一个非常国际化的网站,因此我将所有文本保存在资源文件中.
我还想在资源文件中保留正则表达式以进行验证,这样我就可以使用相同的代码来检查,例如,Post Codes(UK)和Zip Codes(US),只需使用不同的RegEx(以及不同名称的资源等) ).
我有以下属性已经从资源文件中提取错误消息.我怎样才能从资源文件中获取正则表达式?
[RegularExpression(@"^[\w]{1,2}[0-9]{1,2}[\w]?\s?[0-9]{1,2}[\w]{1,2}$", ErrorMessageResourceType = typeof(Resources.ValidationMessages), ErrorMessageResourceName = "validPostcode")]
Run Code Online (Sandbox Code Playgroud)
编辑(再次)
我现在在哪里
按照下面的答案和一些额外的搜索,我有以下内容:
在Global.asax.cs我添加了以下行,以确保调用客户端验证
DataAnnotationsModelValidatorProvider.RegisterAdapter(typeof(LocalisedAttribute), typeof(RegularExpressionAttributeAdapter));
Run Code Online (Sandbox Code Playgroud)
在我的模型中,我调用了属性扩展
[Localised(typeof(Resources.FormValidation), "postcodeRegEx", "postcodeMsg")]
Run Code Online (Sandbox Code Playgroud)
最后,本地化正则表达式验证的属性扩展
public class LocalisedAttribute : RegularExpressionAttribute
{
public LocalisedAttribute(Type resource, string regularExpression, string errorMessage)
: base(GetRegex(regularExpression))
{
ErrorMessageResourceType = resource;
ErrorMessageResourceName = errorMessage;
}
private static string GetRegex(string value)
{
return Resources.FormValidation.ResourceManager.GetString(value);
}
}
Run Code Online (Sandbox Code Playgroud)
这是有效的,但只是我第一次在启动应用程序时使用它.
我将打开另一个问题来解决这个问题 - 它与原始请求没有直接关系,似乎与大多数人的实现没有关系,似乎并不特定于数据注释.
asp.net asp.net-mvc custom-attributes data-annotations asp.net-mvc-4
我在模型中使用Composite类型的字段.
我的模型中有一个名为PersonDetails的字段
public Phone PhoneDetails{get;set;}
Run Code Online (Sandbox Code Playgroud)
Phone是另一个包含三个其他字段的模型
int MobilePhone;
int WorkPhone;
int HomePhone;
Run Code Online (Sandbox Code Playgroud)
PersonDetails是我传递添加弹出窗口的模型.PersonDetails有以下字段:
public String Name{get;set;}
public Phone PhoneDetails{get;set;}
public string Address{get;set;}
Run Code Online (Sandbox Code Playgroud)
我可以将RequiredField属性应用于其余字段,但我想将Required属性应用于PhoneDetails字段.条件是三个中的至少一个,即MobilePhone,WorkPhone或HomePhone应该具有值.
我怎么解决这个问题?
我向MVC4网站添加了一些新功能。我刚刚添加了一个全局静态类和一个全局变量来保存一个值,该值在用户访问网站期间的某个时刻确定,并将在以后用作条件。
然后我想到,我不确定在这种情况下静态值的全局性。
我是否必须将全局值指定为会话变量?
还是无论如何,站点的每个用户都可以在自己的会话中访问它,而我不必担心一个用户将其设置为一个值,而另一个用户可以访问此设置值。
我有一个ASP.NET身份2实现(没有用户数据,只有基表),我有一个类型为UNIQUEIDENTIFIER的userId.
该应用程序首先是代码,我使用的是EF6.
这是DDL:
CREATE TABLE [dbo].[AspNetUsers] (
[Id] UNIQUEIDENTIFIER NOT NULL,
[FirstName] NVARCHAR (MAX) NULL,
[LastName] NVARCHAR (MAX) NULL,
[Email] NVARCHAR (256) NULL,
[EmailConfirmed] BIT NOT NULL,
[PasswordHash] NVARCHAR (MAX) NULL,
[SecurityStamp] NVARCHAR (MAX) NULL,
[PhoneNumber] NVARCHAR (MAX) NULL,
[PhoneNumberConfirmed] BIT NOT NULL,
[TwoFactorEnabled] BIT NOT NULL,
[LockoutEndDateUtc] DATETIME NULL,
[LockoutEnabled] BIT NOT NULL,
[AccessFailedCount] INT NOT NULL,
[UserName] NVARCHAR (256) NOT NULL,
[SubjectId] INT DEFAULT ((0)) NOT NULL,
[SubjectIds] VARCHAR (50) NULL,
[OrganizationId] INT DEFAULT ((0)) NOT NULL,
[OrganizationIds] …Run Code Online (Sandbox Code Playgroud) asp.net asp.net-mvc asp.net-mvc-5 asp.net-identity asp.net-identity-2
创建MVC 3 Razor项目.有一个非常涉及的UI设计.我想通过_layout将@renderbody()放入部分视图源中.编译器不会让我.有没有办法做到这一点?
我正在使用jquery ui对话框,我想看看是否有任何方法在对话框的按钮之间包含水平空间?我在文档或谷歌搜索中看不到任何内容.
这个观点:
@Using Html.BeginForm
SimpleMessage
End Using
@Helper SimpleMessage()
@<p>This is a simple message</p>
End Helper
Run Code Online (Sandbox Code Playgroud)
结果是
<form action="/Controller/Action" method="post"></form>
Run Code Online (Sandbox Code Playgroud)
但
@* Now let's not call it from within a using *@
@SimpleMessage
@Helper SimpleMessage()
@<p>This is a simple message</p>
End Helper
Run Code Online (Sandbox Code Playgroud)
结果是
<p>This is a simple message</p>
Run Code Online (Sandbox Code Playgroud)
为什么我的助手在我的Using Html.BeginForm?
我的页面上有一些字段会出现并消失,具体取决于您在页面上的下拉选项.
所以,例如,我有
<section>
@Html.LabelFor(model => model.AuctionTypeId)
<div> @Html.DropDownList("AuctionTypeId", Model.AuctionTypes, @AuctionControllerResource.SelectAuctionType, new { id="auctionType", required = "required" })
@Html.ValidationMessageFor(model => model.AuctionTypeId) </div>
</section>
<section>
@Html.LabelFor(model => model.AutomaticExtensionType, new { hidden = "true", id = "automaticExtensionTypeLabel" })
<div> @Html.DropDownList("AutomaticExtensionType", Model.AutomaticExtensions, @AuctionControllerResource.SelectAutomaticExtensionType, new { hidden="hidden", required = "required", id = "automaticExtensionTypeList" })
@Html.ValidationMessageFor(model => model.AutomaticExtensionType) </div>
</section>
Run Code Online (Sandbox Code Playgroud)
我对此的JQuery代码是
$('#auctionType').change(function () {
var selectedAuctionType = $("#auctionType").val();
var englishAuctionType = $("#englishAuctionTypeId").val();
if (selectedAuctionType == englishAuctionType) {
$("#automaticExtensionTypeList").show();
$("#automaticExtensionTypeLabel").show();
} else {
$("#automaticExtensionTypeList").hide();
$("#automaticExtensionTypeLabel").hide();
}
}); …Run Code Online (Sandbox Code Playgroud)