asp.net-mvc 相关问题

ASP.NET MVC框架是一个开源Web应用程序框架和工具,它实现了针对Web应用程序定制的模型 - 视图 - 控制器(MVC)模式的版本,并构建在ASP.NET技术基础之上。

在 Aspire 中使用单个 SQL Server 连接设置多个 ASP.NET MVC 端点

我最近参加了 .NET Conf 2023,其中介绍了 .NET 中的 Aspire。我正在开发一个项目,需要有关如何使用 Aspire 在解决方案中设置多个端点的指导。目前,所有...

回答 1 投票 0

ArgumentException:不支持关键字:'server'

我有一个 Asp.net MVC5 应用程序并将其发布到 Microsoft Azure。我首先将 .mdf 文件迁移到 Sql Azure 数据库。 Azure 门户中提供的数据库连接字符串不是

回答 2 投票 0

尝试创建新迁移时不断出现“未找到导航”错误

我正在尝试使用 Visual Studio 2022 创建一个网站。 我创建了一个数据库和一些模型,它们在数据库中有相应的表。 当我尝试创建新的迁移时,我不断...

回答 1 投票 0

Modal 打开后立即关闭 c#

我想使用模式(通过单击按钮)将数据插入表中(在另一个控制器中调用操作) 这是我的cshtml代码: ... 我想使用模式(通过单击按钮)将数据插入表中(在另一个控制器中调用操作) 这是我的cshtml代码: <section class="basic-elements"> <div class="row"> <div class="col-md-12"> <div class="card"> <div class="card-body"> <div class="px-3"> <form class="form"> <div class="form-body"> <div class="row"> <div class="col-xl-4 col-lg-6 col-md-12 mb-1"> <fieldset class="form-group"> <label for="roundText">Clinic Name</label> @Html.DropDownListFor(m => m.clinics, new SelectList(Model.clinics, "Id", "Name"), new { @class = "form-control round" }) </fieldset> <fieldset class="form-group"> <button class="btn btn-success btn-round dropdown-toggle mr-1" id="btnAddClinic" onclick="ShowModalAddClinic()">add new clinic</button> </fieldset> </div> </div> <button class="btn btn-success btn-round dropdown-toggle mr-1" id="btnAddClinic" data-toggle="dropdown">insert</button> </div> </div> </form> </div> </div> </div> </div> 这是我的模态代码: @section Scripts { <link href="~/SweetAlert2/sweetalert2.min.css" rel="stylesheet" /> <script src="~/SweetAlert2/sweetalert2.min.js"></script> <script> function ShowModalAddClinic() { $('#AddClinic').modal('show'); } </script> } @section Modals { <div class="modal fade" id="AddClinic" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true"> <div class="modal-dialog modal-dialog-centered" role="document"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title" id="exampleModalLongTitle">ایجاد کلینیک</h5> <button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">&times;</span> </button> </div> <div class="modal-body"> <div class="col-xl-12 col-lg-12 col-md-12 mb-1"> <fieldset class="form-group"> <label for="basicInput">Clinic Name</label> <input type="text" class="form-control round" id="ClinicName"> </fieldset> </div> </div> <div class="modal-footer"> <a class="btn btn-secondary" data-dismiss="modal">close</a> <a class="btn btn-primary" onclick="AddNewClinic()">add</a> </div> </div> </div> </div> } 但是当我点击“添加新诊所”时,模式显示并立即消失。 如果您能帮助我解决这个问题,我将不胜感激。 谢谢你 我找到了答案: 原因是使用“表单标签”。 我删除了“表单标签”,现在可以使用了。

回答 1 投票 0

ForEach 中的 db.SaveChanges 导致“不允许新事务,因为会话中还有其他线程正在运行”

我有一个大约有21000行的excel文件。我将其导入数据库中的临时表中。 现在我想对我的数据进行一些转换,然后将它们放入我的主表中。 当我执行 SaveChanges() 时

回答 4 投票 0

Ajax 函数不显示 JSON 日期列表 (Mvc5)

在我的 MVC5 视图中,我正在调用 JSON 函数。 JSON 函数返回一个AvailableDates 模型,其中定义了Userld(string) 和DateTime 对象的LIST。 我的视图只能读取用户...

回答 2 投票 0

ASPNET MVC 角色正在尝试使用 SQLServerExpress 而不是 SQLServer

我的 web.config 文件中有以下内容 我的 web.config 文件中有以下内容 <configuration> <connectionStrings> <add name="DefaultConnection" connectionString="Data Source=DESKTOP-6HOPM3U;Initial Catalog=DatabaseName;Integrated Security=True;Connect Timeout=15;" providerName="System.Data.SqlClient" /> </connectionStrings> </configuration> 我可以做我需要做的一切,直到我添加基于角色的身份验证并将其添加到我的 _Layout.cshtml 文件中 @if(User.IsInRole("Admin")) { <li>@Html.ActionLink("Admin Menu","Index","Main",new{ area = "Admin"},null)</li> } 此时会抛出一个错误,提示 A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified) Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. SQLExpress database file auto-creation error: The connection string specifies a local Sql Server Express instance using a database location within the application's App_Data directory. The provider attempted to automatically create the application services database because the provider determined that the database does not exist. The following configuration requirements are necessary to successfully check for existence of the application services database and automatically create the application services database: If the application is running on either Windows 7 or Windows Server 2008R2, special configuration steps are necessary to enable automatic creation of the provider database. Additional information is available at: http://go.microsoft.com/fwlink/?LinkId=160102. If the application's App_Data directory does not already exist, the web server account must have read and write access to the application's directory. This is necessary because the web server account will automatically create the App_Data directory if it does not already exist. If the application's App_Data directory already exists, the web server account only requires read and write access to the application's App_Data directory. This is necessary because the web server account will attempt to verify that the Sql Server Express database already exists within the application's App_Data directory. Revoking read access on the App_Data directory from the web server account will prevent the provider from correctly determining if the Sql Server Express database already exists. This will cause an error when the provider attempts to create a duplicate of an already existing database. Write access is required because the web server account's credentials are used when creating the new database. Sql Server Express must be installed on the machine. The process identity for the web server account must have a local user profile. See the readme document for details on how to create a local user profile for both machine and domain accounts. Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. Stack Trace: [SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)] System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling, SqlAuthenticationProviderManager sqlAuthProviderManager) +947 System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) +6050103 System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions) +38 System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) +531 System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +156 System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +22 System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry) +92 System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) +219 System.Data.SqlClient.SqlConnection.Open() +101 System.Web.Management.SqlServices.GetSqlConnection(String server, String user, String password, Boolean trusted, String connectionString) +78 [HttpException (0x80004005): Unable to connect to SQL Server database.] System.Web.Management.SqlServices.GetSqlConnection(String server, String user, String password, Boolean trusted, String connectionString) +131 System.Web.Management.SqlServices.SetupApplicationServices(String server, String user, String password, Boolean trusted, String connectionString, String database, String dbFileName, SqlFeatures features, Boolean install) +92 System.Web.Management.SqlServices.Install(String database, String dbFileName, String connectionString) +30 System.Web.DataAccess.SqlConnectionHelper.CreateMdfFile(String fullFileName, String dataDir, String connectionString) +410 当我删除线条时 if(User.IsInRole("Admin")) { } 它可以工作,但现在我没有基于角色的访问权限。 我没有使用 Sql Server Express。我需要更改什么才能使身份的基于角色的部分使用我的连接字符串中的数据库? 您遇到的错误表明与 SQL Server 建立连接时出现问题。如果您认为正确,请写信,以便我提供不同的解决方案。

回答 1 投票 0

在哪里存储所有页面 JavaScript 代码?

我对 Web 开发有点陌生,我一直在开发 Razor ASP.NET 应用程序,只是想知道在哪里存储每个人的所有单独 JavaScript 代码的最佳实践...

回答 1 投票 0

ASP.NET MVC 带有视图模型的部分视图

我尝试在同一个“创建”页面中列出我放入同一张发票的产品。所以我需要插入我的供应商发票,当然在这张发票中我有很多产品,我需要在同一个p中列出...

回答 1 投票 0

每个浏览器首次加载缓慢或一段时间后加载

我有一个在 Windows Server 2008 / IIS 7.5 上运行的低流量 ASP.NET MVC 4 应用程序。 我的问题是: 第一个请求很慢,大约 15 秒。 (后续要求没问题) 另一个请求

回答 3 投票 0

从 ASP.NET MVC 中的请求获取客户端 IP 地址

我在安装了 IIS 8.5 的 Web 服务器上部署了 ASP.NET MVC 应用程序(使用 .NET 4.5)。 我创建了一个自定义控制器类,我在其中做了一些事情,它继承自 System.W...

回答 2 投票 0

ASP.net 6 WebApp 在 Http 中正常工作,但不在 https 中加载图像、css 和 js

我有一个 aspnet WebApi,它正在使用 http 进行生产。 我对其进行了编辑以使用 Microsoft Azure AD 身份验证。 问题在于 Azure Ad WebApp 配置,对于生产环境...

回答 1 投票 0

具有 CLSID 错误的组件的 COM 类工厂

由于以下错误,检索 CLSID 为 {000209FF-0000-0000-C000-000000000046} 的组件的 COM 类工厂失败:80080005 服务器执行失败 (0x80080005 (CO_E_SERVER_EXEC_FA...

回答 1 投票 0

Git 添加 . ASP.NET MVC 应用程序中出现错误

我正在开发一个 ASP.NET MVC 应用程序,但在部署它时遇到了困难。当我发出命令 git add . 时,出现以下错误: git :错误:打开(“.vs/DonationSite/

回答 1 投票 0

使用 Azure AD (Azure Identity) 为 ASP.NET MVC 应用程序实现身份验证

我即将在 Azure 中托管在 .NET 4.8 上运行的现有 ASP.NET MVC 应用程序。我想使用 Azure AD (Azure Identity) 实施身份验证。 我正在寻找一些快速入门或演练,但...

回答 1 投票 0

ASP .NET MVC 上传的文件始终为空

我正在尝试上传 JSON 文件,但 MVC 控制器始终将其解释为 null。 看法: 或 @Html.TextBox("jsonFile", null, new { type = "文件...

回答 1 投票 0

如何根据模型值隐藏按钮?

我有以下逻辑: if (Model != null && Model.StatusMessage != "新覆盖") { 删除...

回答 2 投票 0

如何修复正则表达式的模式以匹配大小

我正在使用这个模式 var pattern = @"[([^]]+)] [?([^(]]+)(?:(((\w\s)+)))?]? .?(?:\sNOT\s*NULL)?(?:,|$)"; 这是我的代码 var matches = Regex.Matches(command, pattern, RegexOptions.

回答 1 投票 0

Asp.Net Core - 最简单的表单身份验证

我有这个旧的 MVC5 应用程序,它以最简单的形式使用表单身份验证。 web.config 中仅存储一个帐户,没有角色等。 我有这个旧的 MVC5 应用程序,它以最简单的形式使用表单身份验证。 web.config 中仅存储一个帐户,没有角色等。 <authentication mode="Forms"> <forms loginUrl="~/Login/Index" timeout="30"> <credentials passwordFormat="Clear"> <user name="some-user" password="some-password" /> </credentials> </forms> </authentication> 登录例程只是调用 FormsAuthentication.Authenticate(name, password); 就是这样。 ASP.NET Core 中是否有类似的东西(就简单性而言)? 事情没那么简单:) 在Startup.cs中,configure方法。 app.UseCookieAuthentication(options => { options.AutomaticAuthenticate = true; options.AutomaticChallenge = true; options.LoginPath = "/Home/Login"; }); 添加授权属性以保护您想要保护的资源。 [Authorize] public IActionResult Index() { return View(); } 在 Home Controller 的 Login Post 操作方法中,编写以下方法。 var username = Configuration["username"]; var password = Configuration["password"]; if (authUser.Username == username && authUser.Password == password) { var identity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme); HttpContext.Authentication.SignInAsync( CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(identity)); return Redirect("~/Home/Index"); } else { ModelState.AddModelError("","Login failed. Please check Username and/or password"); } 这里是 github 存储库供您参考:https://github.com/anuraj/CookieAuthMVCSample 添加 Anuraj 的答案 - .Net Core 2 已弃用许多类。仅供参考: Startup.cs - 在配置服务中: services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) .AddCookie(o => o.LoginPath = new PathString("/account/login")); Startup.cs - 在配置中: app.UseAuthentication(); 在您的帐户/登录控制器方法中/无论您在何处进行身份验证: var claims = new[] { new Claim(ClaimTypes.Name, "MyUserNameOrID"), new Claim(ClaimTypes.Role, "SomeRoleName") }; var identity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme); await context.SignInAsync( CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(identity)); // Do your redirect here 来源: https://github.com/aspnet/Announcements/issues/232 https://github.com/aspnet/Security/issues/1310 Anuraj 的回答对 MVC ASP.NET Core 6 进行了一些更新... (.net core 5 答案在 .net core 6 中不再有效) 在Program.cs中,configure方法。 // 表单验证 builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) .AddCookie(o => o.LoginPath = new PathString("/Home/Login")); ... //表单认证 app.UseAuthentication(); 添加授权属性以保护您想要保护的资源。 [授权] 公共 IActionResult 索引() { 返回视图(); } 在 Home Controller 的 Login Post 操作方法中,编写 以下方法。 var 用户名=配置[“用户名”]; var 密码 = 配置[“密码”]; if (authUser.用户名 == 用户名 && authUser.密码 == 密码) { var Claims = new[] { new Claim(ClaimTypes.Name, 用户名) }; var 身份=新的ClaimsIdentity(声明, CookieAuthenticationDefaults.AuthenticationScheme); HttpContext.SignInAsync( CookieAuthenticationDefaults.AuthenticationScheme, 新的 ClaimsPrincipal(身份)); return Redirect("~/Home/Index"); } 否则 { ModelState.AddModelError("","登录失败,请检查用户名和/或密码"); }

回答 3 投票 0

Azure 应用服务默认 404 页面上的 SSL 错误(无效 URL)

我有一个托管在 Azure 应用服务上的 ASP.NET MVC 应用程序,并且我已经设置了带有 SSL 证书的应用程序网关。当用户尝试访问无效 URL 时,我目前不处理

回答 1 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.