小编JK.*_*JK.的帖子

MVC RequireHttps并重定向,如果不是https

我已经阅读了很多关于ASP.NET MVC的问题[RequireHttps]- 但是找不到这个问题的答案:

[RequireHttps]如果不是https开始,如何使属性将URL切换为https?

我有这个代码:

public ActionResult DoSomething()
{
    return View("AnotherAction");
}

[RequireHttps]
public ActionResult AnotherAction()
{
    return View();
}
Run Code Online (Sandbox Code Playgroud)

但我得到一个错误说:"所请求的资源只能通过SSL访问."

MVC期货项目具有类似的属性[RequireSsl(Redirect = true)].但现在已经过时了...... MVC 2中的等价物是什么?

当有人类型的网址http://example.com/home/dosomething或网址http://example.com/home/anotheraction,我需要他们被自动重定向到http 小号://示例.com /家/ anotheraction

编辑这是一系列事件:

从其他网站调用URL http://example.com/home/dosomething.他们将用户重定向到此网址(使用response.redirect或类似网址).

DoSomething()然后尝试返回AnotherAction(),但失败并显示错误消息"所请求的资源只能通过SSL访问".

c# ssl requirehttps asp.net-mvc-2

13
推荐指数
2
解决办法
3万
查看次数

ASP.NET MVC路由字符串ID?

在ASP.NET 2中,如何创建允许通过字符串id(例如ProductCode)查找对象(例如Product)的路由?通过它的整数id(例如ProductId)查找同一个对象的路由是自动的,所以我实际上并不知道它是如何工作的.

id的自动路由是:

/Product/1
Run Code Online (Sandbox Code Playgroud)

如何创建使用字符串ID的第二条路线?

/Product/red-widget
Run Code Online (Sandbox Code Playgroud)

我该怎么做才能使这两条路线都可用?

asp.net-mvc routes asp.net-mvc-routing

13
推荐指数
1
解决办法
9291
查看次数

ASP.NET MVC 2 - Html.Editor对于可以为空的类型?

我有两个编辑器模板:一个用于十进制,一个用于十进制?(可为空的)

但是当我的模型中有一个可以为空的小数时,它会尝试加载普通的十进制编辑器:

<%: Html.EditorFor(model => model.SomeDecimal )%>
<%: Html.EditorFor(model => model.SomeNullableDecimal )%>
Run Code Online (Sandbox Code Playgroud)

第一个工作正常,并加载十进制编辑器模板.第二个也尝试加载十进制模板(并且因为它不是十进制字段而失败).

错误消息是:

The model item passed into the dictionary is null, but this dictionary requires 
a non-null model item of type 'System.Decimal'. 
Run Code Online (Sandbox Code Playgroud)

我的模板声明如下:

十进制模板:

<%@ Control Language="C#" 
Inherits="System.Web.Mvc.ViewUserControl<System.Decimal>" %>
Run Code Online (Sandbox Code Playgroud)

可空的十进制模板:

<%@ Control Language="C#" 
Inherits="System.Web.Mvc.ViewUserControl<System.Decimal?>" %>
Run Code Online (Sandbox Code Playgroud)

我知道我可以通过传递模板名称来使其工作,例如

但我真的更喜欢它只是像所有其他模板一样使用类型自动工作.

<%: Html.EditorFor(model => model.SomeNullableDecimal, 
"NullableDecimalTemplate" )%>
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc mvc-editor-templates editortemplates asp.net-mvc-2

12
推荐指数
1
解决办法
9906
查看次数

ASP.NET成员身份更改密码不起作用

我有这个代码用于在用户单击密码重置按钮时更改用户的密码(使用额外的代码登录到ELMAH,这样我就可以尝试找出出错的地方).

这是在ASP.NET MVC 2中,使用标准的aspnet成员资格提供程序,使用这样的简单视图:

New Password:     ______
Confirm Password: ______
[Reset] [Cancel]
Run Code Online (Sandbox Code Playgroud)

此视图的路径是/Account/Reset/guid,其中guid是aspnet成员资格数据库中的用户ID.

代码的关键部分是它调用的地方user.ChangePassword().您可以看到它在成功时记录消息.问题是对于某些用户,会记录成功消息,但他们无法使用新密码登录.对于其他用户,它会记录成功消息,并且可以登录.

if (user.ChangePassword(pwd, confirmPassword))
{
    ErrorSignal.FromCurrentContext().Raise(
        new Exception("ResetPassword - changed successfully!"));
    return Json(new { 
        Msg = "You have reset your password successfully." }, 
        JsonRequestBehavior.AllowGet);
 }
Run Code Online (Sandbox Code Playgroud)

完整的代码清单是:

[HttpPost]
public JsonResult ResetPassword(string id, string newPassword, string confirmPassword)
{
    ErrorSignal.FromCurrentContext().Raise(new Exception("ResetPassword started for " + id));

    ViewData["PasswordLength"] = Membership.MinRequiredPasswordLength;

    if (string.IsNullOrWhiteSpace(newPassword))
    {
        ErrorSignal.FromCurrentContext().Raise(
            new Exception("ResetPassword - new password was blank."));
        ModelState.AddModelError("_FORM", "Please enter a new password."); …
Run Code Online (Sandbox Code Playgroud)

.net c# asp.net-mvc asp.net-membership

12
推荐指数
1
解决办法
2万
查看次数

Elmah没有记录HttpRequestValidationException

在我的ASP.NET MVC2应用程序中,Elmah无法记录任何内容HttpRequestValidationException(除非您通过远程桌面登录到Web服务器并将该站点作为localhost浏览)

例如,如果我&#39使用我得到的域名从我的电脑正常浏览时输入文本框

Server Error in '/' Application.
Runtime Error 

Description: An application error occurred on the server. The current custom 
error settings for this application prevent the details of the application 
error from being viewed remotely (for security reasons). It could, however, 
be viewed by browsers running on the local server machine.

Details: To enable the details of this specific error message to be viewable on 
remote machines, please create a <customErrors> tag within a …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc elmah

12
推荐指数
1
解决办法
1591
查看次数

你如何覆盖"-moz-user-select:none;" 在一个儿童元素?

此问题禁用文本选择突出显示的CSS规则显示了如何防止元素上的文本选择.一旦阻止了选择,那么如何允许选择特定的子元素?例如

<div class="no-select">
    <p>some text that cannot be selected</p>
    <p class="select">some text that can be selected</p>
    <p>some text that cannot be selected</p>
</div>

table.no-select {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

td.select {
    -webkit-touch-callout: all !important;
    -webkit-user-select: all !important;
    -khtml-user-select: all !important;
    -moz-user-select: all !important;
    -ms-user-select: all !important;
    user-select: all !important;
}
Run Code Online (Sandbox Code Playgroud)

.no-select上面的规则有效,但我对.select规则的尝试却没有,这样做的正确方法是什么?

css cross-browser textselection

12
推荐指数
1
解决办法
9097
查看次数

C#Entity Framework 4导航属性导致提交性能降低

我为这个问题缺乏细节而道歉 - 我需要帮助的第一件事就是知道在哪里寻找更多细节.

我有一个enity框架4导航属性的问题,显然在提交更改时导致性能不佳:

this.ObjectContext.SaveChanges();
Run Code Online (Sandbox Code Playgroud)

当其中一个导航属性(收据表)包含大约8000行(这不是很多,所以应该没问题)时,需要30多秒.

我使用过SQL分析器,可以看到EF从Receipts发出select*并且它非常慢:

exec sp_executesql N'SELECT 
[Extent1].[Id] AS [Id], 
// full field list cut for brevity 
FROM [dbo].[Receipts] AS [Extent1]
WHERE [Extent1].[WarehouseId] = @EntityKeyValue1',
N'@EntityKeyValue1 int',@EntityKeyValue1=1
Run Code Online (Sandbox Code Playgroud)

目前,当调用ObjectContext.SaveChanges()时,我甚至无法理解为什么需要从该表中选择所有行.

它确实需要在此表中插入1行,但这并不能解释为什么它首先执行select - 并且不能解释为什么select会花费这么长时间(同一查询在查询管理器中占用<1秒)

所以我现在的问题 - 我还不知道问题是什么 - 是:

  • 我在哪里/如何查找有关该问题的更多详细信息?我无法调试到ObjectContext.SaveChanges(),所以我不知道它内部发生了什么.
  • 为什么EF会尝试从收据中选择*?
  • 为什么这么慢?复制+粘贴到查询管理器的完全相同的查询几乎是即时的

编辑:

我已经通过注释掉对此方法的调用来确认收据代码很慢:

    private void AddReceipt(PurchaseInvoice invoice, 
                               PurchaseInvoiceLine invoiceLine)
    {
        if (invoice != null && invoiceLine != null)
        {
            Product product = invoiceLine.Product;
            if (product != null)
            {
                Receipt receipt = new Receipt{ foo = bar }; …
Run Code Online (Sandbox Code Playgroud)

c# sql-server performance entity-framework objectcontext

9
推荐指数
1
解决办法
2417
查看次数

避免太多转换

我当前的Go代码中有一些部分看起来像这样:

i := int(math.Floor(float64(len(l)/4)))
Run Code Online (Sandbox Code Playgroud)

冗长似乎是必要的,因为一些函数类型签名,如一个math.Floor,但它可以简化?

go

9
推荐指数
1
解决办法
155
查看次数

Dapper的IEnumerable <T>是否已推迟或立即执行?

当我在Dapper中执行查询并且只想要检索一个记录块时,我可以使用.Skip().Take(),还是需要在SQL中使用select top n*?

例如,给定一个包含10,000条记录的表,我只想要前200条,因为我的列表页面每页只显示200条.我跑这个吗?

conn.Query<Widget>("select * from Widgets").Skip((page - 1) * size).Take(size);
Run Code Online (Sandbox Code Playgroud)

或这个:

conn.Query<Widget>("select top 200 * from Widgets");
Run Code Online (Sandbox Code Playgroud)

Dapper的.Query<T>方法是否延期?

c# ienumerable orm deferred-execution dapper

8
推荐指数
1
解决办法
1738
查看次数

调整大小时,锐利图像库会旋转图像吗?

对于node.js 使用清晰图像调整大小库https://github.com/lovell/sharp时,图像正在旋转.

我没有代码说.rotate(),为什么它被旋转,我怎么能阻止它旋转?

我使用的是由AWS提供的无服务器,图像缩放例如: https://github.com/awslabs/serverless-image-resizing使用拉姆达在飞行中调整图像如果缩略图不存在

S3.getObject({Bucket: BUCKET, Key: originalKey}).promise()
.then(data => Sharp(data.Body)
      .resize(width, height)
      .toFormat('png')
      .toBuffer()
    )
.then(buffer => S3.putObject({
        Body: buffer,
        Bucket: BUCKET,
        ContentType: 'image/png',
        Key: key,
      }).promise()
    )
.then(() => callback(null, {
        statusCode: '301',
        headers: {'location': `${URL}/${key}`},
        body: '',
      })
    )
.catch(err => callback(err))
Run Code Online (Sandbox Code Playgroud)

原始大图:

在此输入图像描述

已调整大小的图片:请注意它已被旋转:

在此输入图像描述

amazon-s3 image-resizing node.js aws-lambda sharp

8
推荐指数
2
解决办法
2144
查看次数