正如标题所说,这可能吗?我有一个项目,在某些情况下,我需要禁用页面上的按钮.我已经设置了一个标志,根据该标志在控制器中进行一些判断,相应地设置按钮禁用.如果要禁用该按钮,则包括"disabled"(如果不禁用),则没有文本,因为我发现disabled="enabled"仍然禁用该按钮.

我的问题是如何阻止某人通过F12开发人员工具改变这一点?我可以加载该元素,删除禁用属性,嘿,立即它不再禁用.我如何/可以停止这种行为?有没有办法让它比这更永久?

我正在使用System.Web.Mvc.dll v5.2.9.0

推荐答案

As others have mentioned, you can't control what other users are doing. If you are already checking in your controller if the button should be enabled, then the proper solution is to also disable the endpoint at the same time so nothing happens or it returns an error page if they click on it anyway.
As a side note: You are correct, it only cares if the word disabled is there. Disabled="disabled" is normally done to make it compatible with xhtml. It does not matter at all what is in the quotes. They are ignored.

我们项目中的真实代码:

if (!order.CanEdit())
    return PartialView("_ErrorDialog", "Order cannot be edited.");
else if (!order.CanBeTransferred())
    return PartialView("_ErrorDialog", "Invalid status.  Cannot transfer this order");
else if (order.IsTransfer)
    return PartialView("_ErrorDialog", "Cannot transfer an existing transfer.");

您不应该仅仅依赖html来阻止功能. 或者,如果这是所有回发,您不能仅仅将按钮呈现为禁用,您可以将操作更改为#.但这并不是愚蠢的证据,因为有人仍然可以try 直接呼叫您的端点.

Csharp相关问答推荐

List T.AddRange在传递ConcurrentDictionary作为参数时引发ArgumentExcellent

使用GeneratedComInterfaceProperty的.NET 8 COM类对于VB 6/SYS或ALEViewer不可见

Serilog SQL服务器接收器使用UTC作为时间戳

哪个nuget包含SecurityStampValidatorOptions

如何在Reflection. Emit中使用具有运行时定义的类型参数的泛型类型

为什么我的ASP.NET核心MVC应用程序要为HTML元素添加一些标识符?

选取器与.NET Maui MVVM的绑定属性

用C#调用由缓冲区指针参数组成的C API

共享暂存/生产环境中Azure事件中心的建议配置

在.NET MAUI.NET 8中如何防止按钮点击时出现灰色反馈

TagHelpers在新区域不起作用

如何在C#中正确类型化带有泛型的嵌套类

在同一个捕获中可以有多种类型的异常吗?

我应该为C#12中的主构造函数参数创建私有属性吗?

使用可空引用类型时C#接口实现错误

C#-如何将int引用获取到byte[]

.NET8支持Vector512,但为什么向量不能达到512位?

使用生产环境调试我的应用程序的快速方法

在c#中,使用Okta和Blazor时,LocalReDirect()陷入循环,出现错误&请求太多.

自定义ConsoleForMatter中的DI/Http上下文