asp.net-mvc 相关问题

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

URL 重写 webconfig 设置破坏了 iisexpress

我正在为另一个开发应用程序进行合并。 vs2013 wvc 网络应用程序,net 4.5.2。 合并的一部分是将其添加到配置中以进行 url 重写。 我正在为另一个开发应用程序进行合并。 vs2013 wvc 网络应用程序,net 4.5.2. 合并的一部分是将其添加到配置中以进行 url 重写。 <system.webServer> <caching enabled ="false" /> <rewrite> <rules> <rule name="HTTP to HTTPS Redirect" stopProcessing="true"> <match url="(.*)" /> <conditions> <add input="{HTTPS}" pattern="^OFF$" /> </conditions> <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" appendQueryString="false" /> </rule> </rules> </rewrite> <modules> 我在 iisexpress 中运行 Vs2013,现在每次运行该应用程序时都会出现此错误。 错误: 该网站无法提供安全连接 本地主机发送了无效的响应。 尝试运行 Windows 网络诊断。 ERR_SSL_PROTOCOL_ERROR 我评论了该配置的阻止,它仍然有效。 我加载了另一个应用程序,仍然如此 我安装了 URL rewrite 2.1,仍然如此 我重启机器还是这样 如果在项目 Web 设置中将应用程序从 iisexpress 更改为 iis,则可以正常工作。 如果我将其改回iisexpress..再次中断。 在我看来,iisexpress 的本地实例设置了一些已损坏的东西。 但是如果重新启动无法解决问题,我该如何修复它以便 iisexpress 再次工作? 更新,我将其添加到我的配置中,并安装了 Firefox,正如 somoen 所说,这是一个 chrome 问题,导致它一直这样。 <system.webServer> <validation validateIntegratedModeConfiguration="false" /> <security> <!--<access sslFlags="None" />--> </security> <caching enabled ="false" /> <!-- <rewrite> <rules> <rule name="HTTP to HTTPS Redirect" stopProcessing="true"> <match url="(.*)" /> <conditions> <add input="{HTTPS}" pattern="^OFF$" /> </conditions> <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" appendQueryString="false" /> </rule> </rules> </rewrite>--> iisexpress 现在可以在 Firefox 中运行。 任何人都知道 Chrome 正在做什么导致了这个问题,我需要能够在 chrome 中进行测试,唉。 好吧,我明白了。 Chrome 处于某种更安全的模式,它总是检查网站是否是 ssl,但没有设置控制行为的设置。 我将 http:\localhost 添加到受信任站点列表中, 然后打开标志,然后再次关闭,使 Chrome 检查站点是否安全。之后一切又恢复正常了。

回答 1 投票 0

.NET 8 OnActionExecuted 和 View 开始渲染之间有 >4 秒的延迟

我知道这里有很多移动部分需要考虑,但我想我应该发帖看看是否有人有任何想法。 我遇到了视图加载时间缓慢的问题。 我添加了日志...

回答 1 投票 0

当在对话框中按“确定”时,服务器方法执行,如果按“取消”,则留在我的页面上。怎么办?

我想在我的 aspx 页面中使用对话框(确定和取消)。 当我按“确定”时,我的服务器端代码应该执行,当我按“取消”时,什么都不会发生,即使回发也应该...

回答 3 投票 0

如何将动态创建的 HTML 字符串渲染到 Asp.NET Core 中的 razor 视图中

我编写了如下的html帮助器方法 公共静态类 CustomHtmlHelper { 公共静态 HtmlString SetMenuRespectiveWithRoles(此 IHtmlHelper html,HttpContext 上下文) {

回答 1 投票 0

在 ASP.NET Core 中,由于此错误而无法创建用户。无法跟踪实体类型的实例,因为另一个实例具有相同的键值

用户控制器 [http邮报] [验证防伪令牌] 公共异步任务创建(CreateUserDetailsForm createUser) { 尝试 { // 生成唯一的UserID ...

回答 1 投票 0

从 RazorPage 继承时出错<TModel>

我想在 AspCore Razor Page 中使用本地化。 但是,我遇到了以下错误: CS0108:“Pages_Index.ViewData”隐藏继承的成员“RazorPage.ViewData”。使用...

回答 1 投票 0

构造“ResizeObserver”失败:参数1不是“Function”类型

我正在尝试在textarea内渲染HTML,并且我有一个来自控制器的ajax调用来读取该值并将其解析为render()函数的var。 我在这里关注了这个问题 然而,任...

回答 1 投票 0

MVC Server 登录无效后,如何捕获返回的 Json 响应中的错误文本并将其显示给 Angular 客户端上的用户?

Angular 9 客户端登录页面——我想在 h4 元素中显示特定返回的错误消息,而不是当前显示的通用消息。 Angular 9 客户端登录页面 - 我想在 h4 元素中显示特定返回的错误消息,而不是当前显示的通用消息。 <div class="navbar bg-info mb-1"> <a class="navbar-brand text-white">The ACTS Factory Authentication</a> </div> <h4 *ngIf="showError" class="p-2 bg-danger text-white"> Invalid username or password! **I want to put the specific error condition here** </h4> <form novalidate #authForm="ngForm" class="m-3" title="LoginForm"> <div class="form-group"> <label>Name:</label> <input #name="ngModel" name="name" class="form-control" [(ngModel)]="authService.name" required /> <div *ngIf="name.invalid" class="text-danger"> Please enter your user name </div> </div> <div class="form-group"> <label>Password:</label> <input type="password" #password="ngModel" name="password" class="form-control" [(ngModel)]="authService.password" required /> <div *ngIf="password.invalid" class="text-danger"> Please enter your password </div> </div> <div class="text-center pt-2"> <button type="button" class="btn btn-primary font-weight-bold" [disabled]="authForm.invalid" (click)="login()"> Please Login </button> </div> </form> Angular 9 组件——我从这个 Angular 客户端组件登录。 当响应状态代码为 400 Bad Request 时,“result”为 false,一般错误消息显示在 h4 元素中。 这里的login()方法订阅了身份验证服务存储库中的Login()方法。 返回的 Response 对象或包含错误文本的属性必须返回此处才能添加到 html 显示中。 import { Component } from "@angular/core"; import { AuthenticationService } from "./authentication.service"; @Component({ templateUrl: "authentication.component.html" }) export class AuthenticationComponent { showError: boolean = false; constructor(public authService: AuthenticationService) { } login() { this.showError = false; this.authService.login().subscribe(result => { this.showError = !result }); } } 客户端身份验证服务存储库中的 Angular 9 登录方法——此登录方法调用数据源的 Observable login() 方法,确定是否已收到有效(真或假)响应,并将响应中包含的返回属性映射到局部变量. login(): Observable<boolean> { this.authenticated = false; return this.dataSource.login(this.userName, this.userPwd).pipe( map(response => { if (response) { this.callbackUrl = null; this.authenticated = true; this.password = null this.router.navigateByUrl(this.callbackUrl || "appmenu"); } this.profileEmail = null; this.profilePhone = null; if (this.dataSource.teamUser) { this.isTeamUser = this.dataSource.teamUser; } else { this.isTeamUser = false; } return this.authenticated = true; }), catchError(e => { this.authenticated = false; [I have tried to capture the error text here] return of(false); })); } Angular 9 客户端身份验证数据源登录方法 -- 这是客户端的数据源;它向服务器发送http请求并接收http响应。 它还将响应中的属性映射到局部变量,确定目标 URL,并跟踪必要的标头。 auth_Header: HttpHeaders = new HttpHeaders(); auth_token: string = null; login(theName: string, thePassword: string): Observable<boolean> { return this.http.post<any>("/api/account/login", { name: theName, password: thePassword }) .pipe(map(response => { [I have tried capturing the error here and exiting with response.success = false] this.auth_token = response.success ? response.token : null; // JWT token generated in server-side AccountController this.auth_Header = this.auth_Header.set("Authorization", "Bearer<" + this.auth_token + ">"); this.authCookie.JWTauthcookie = this.auth_token; // save for the other datasources this.loginTime = response.loginTime; // to return user's registered email and phonenumber to client this.profileEmail = ""; this.profileEmail = response.profileEmail; this.profilePhone = ""; this.profilePhone = response.profilePhone; } this.isAuthenticated = true; return response.success; })); MVC 帐户控制器——这是处理登录请求的 MVC 控制器,在 AspNetCore Identity 中搜索用户名和密码(代码中未显示),并在登录成功时返回 200 状态代码和 Json 对象。 我现在返回两个特定的登录错误条件(未找到用户或密码无效),我想在无效登录尝试后在客户端上显示它们。 我尝试使用“OK”而不是 BadRequest() 状态代码 400 返回错误。但是,这对客户端没有帮助。 任何和所有的想法将不胜感激。 谢谢。 [HttpPost("/api/account/login")] public async Task<IActionResult> Login([FromBody] LoginViewModel creds) { LoginError = ""; bool loginResult = false; object myReturnObject = new object(); if (ModelState.IsValid) { loginResult = await DoLogin(creds); // go look for existing Identity user and try to sign in if (loginResult) { myReturnObject = "{ " + '\n' + " " + '"' + "success" + '"' + ":" + '"' + signInResult.Succeeded.ToString() + '"' + "," + '\n' + " " + '"' + "token" + '"' + ':' + '"' + bearerJWTokenString + '"' + "," + '\n' + " " + '"' + "loginTime" + '"' + ':' + '"' + DateTime.Now.ToShortTimeString() + '"' + "," + '\n' + " " + '"' + "profileEmail" + '"' + ':' + '"' + profileEmail + '"' + "," + '\n' + " " + '"' + "profilePhone" + '"' + ':' + '"' + profilePhone + '"' + "," + '\n' + " " + '"' + "team" + '"' + ':' + '"' + loggedInUserType.ToString() + '"' + "," + '\n' + "}"; return Ok(myReturnObject); // good login returns this object as a Json file in the HTTP Response body } else { // if bad username or pwd - this returns http status code 400 "Bad Request" plus the LoginError json object return BadRequest("{" + '\n' + " " + '"' + "InvalidLogin" + '"' + ':' + '"' + "True" + '"' + '\n' + " " + '"' + "LoginError" + '"' + ':' + '"' + LoginError + '"' + '\n' + "}"); } } return BadRequest(ModelState.ValidationState.ToString()); // bad model state returns - http error 400 Bad Request } 客户端返回的Json对象图片 [![Login error text message][1]][1] .subscribe( data => {/* success action*/}, (error: HttpErrorResponse) => {/* error action */ console.error(error)}, () => {/* complite (after success OR error) action */} )

回答 1 投票 0

如何将参数从一个部分视图传递到另一个部分视图

我有一个商店详细信息页面的部分用户视图。我添加了一个部分模式来将用户标记为生病。这是我对用户的部分看法: @模特店 我通过商店详细信息页面查看了用户的部分视图。我添加了一个部分模式来将用户标记为生病。这是我对用户的部分看法: @model Shop <div class="mb-3 d-flex border-bottom align-items-center justify-content-between"> <h3 class="text-secondary">Employees in @Model.Name</h3> <a [email protected]("admin") asp-controller="User" asp-action="Register" asp-route-id="@Model.Id" class="btn-add-employee" title="Add a new user"><i class="bi bi-person-fill-add" ></i></a> </div> <table class="table table-sm"> <thead> <tr> <th>Name</th> <th>Surname</th> <th>Role</th> <th>Edit Clock In-Out and Add Holiday Leave</th> <th>Sickness</th> <th></th> </tr> </thead> <tbody> @if (Model.Users.Count == 0) { <tr> <td colspan="4">No Employees...</td> </tr> } else { @foreach (var u in Model.Users) { var rowClass = "table-danger"; // Default to red // Get today's timecard for the user var todayTimeCard = u.TimeCards.Where(tc => tc.ClockIn.Date == DateTime.Today).OrderByDescending(tc => tc.ClockIn).FirstOrDefault(); if (todayTimeCard != null) { if (todayTimeCard.Holiday) { rowClass = "table-primary"; // Blue row for holiday } else if (todayTimeCard.Sickness) { rowClass = "table-warning"; // Yellow row for sickness } else { rowClass = "table-success"; // Green row for regular time card } } <tr class="@rowClass"> <td>@u.Name</td> <td>@u.LastName</td> <td>@u.Role</td> <td>@u.ShopId</td> <td> <a [email protected]("manager,admin") asp-controller="User" asp-action="TimeCardLog" asp-route-id="@u.Id" class="btn"><i class="bi bi-pencil-fill"></i></a> </td> <td> @{ViewBag.UserId = u.Id;} <button [email protected]("manager,admin") data-bs-toggle="modal" data-bs-target="#AddSicknessTimeCardModal" class="btn btn-sm btn-outline-warning"><i class="bi bi-emoji-frown" title="mark as sick"></i>Mark as Sick</button> </td> <td class="text-end"> <a [email protected]("admin") asp-controller="User" asp-action="Edit" asp-route-id="@u.Id" class="btn btn-sm btn-outline-dark">Edit employee details</a> <br> <a [email protected]("admin") asp-controller="User" asp-action="Delete" asp-route-id="@u.Id" class="buttondelete btn-sm btn-outline-danger"> <i class="bi bi-trash" title="Delete User"></i>Remove employee</a> <br> <a [email protected]("admin") asp-controller="User" asp-action="ReassignShop" asp-route-id="@u.Id" class="buttondelete btn-sm btn-outline-danger"> <i class="bi bi-arrow-right" title="Reassign User"></i>Re-assign employee</a> </td> </tr> } } </tbody> </table> <!-- Mark as sickness Modal Confirmation --> <partial name="_AddSicknessTimeCardModal" /> 正如你所看到的,我尝试使用 ViewBag 来传递 userId,但不幸的是它在迭代所有用户之后只存储了最后一个用户的一个 id。这是加病假的模式: <!-- Modal --> <div class="modal fade" id="AddSicknessTimeCardModal" tabindex="-1" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <h1 class="modal-title fs-5" id="exampleModalLabel">Mark Absence</h1> <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> </div> <div class="modal-body"> <div class="alert alert-warning"> <h3>Are you sure you want to mark this person as being sick today?</h3> </div> <div class="modal-footer"> <form asp-action="AddSicknessTimeCard" method="post" asp-route-id="@ViewBag.UserId"> <button type="submit" class="btn btn-primary" aria-label="add">Yes</button> <button type="button" class="btn btn-danger" data-bs-dismiss="modal">Cancel</button> </form> </div> </div> </div> </div> </div> 我的控制器需要传递给它的用户 ID 来完成操作(来自 foreach 的 u.Id)。任何有关将 id 传递到模态部分的建议将不胜感激! 你应该改变 <!-- Mark as sickness Modal Confirmation --> <partial name="_AddSicknessTimeCardModal" /> 到 @foreach (var u in Model.Users) { ViewBag.UserId = u.Id; <!-- Mark as sickness Modal Confirmation --> <partial name="_AddSicknessTimeCardModal" /> } 并更改您的模式代码 <!-- Modal --> <div class="modal fade" id="AddSicknessTimeCardModal" tabindex="-1" aria-hidden="true"> <div class="modal-dialog"> ... 到 <!-- Modal --> <div class="modal fade" id="[email protected]" tabindex="-1" aria-hidden="true"> <div class="modal-dialog"> ... 然后您可以使用以下代码向每个用户显示模式: var userId = ...; $(`#AddSicknessTimeCardModal-${userId}`).modal('show');

回答 1 投票 0

WCF 服务在 ASP.NET MVC 中引发错误。无法建立具有权限的 SSL/TLS 安全通道

首先,有很多相同标题的问题,但我相信我的问题与其他问题有点不同。我想说的是,关于两个

回答 1 投票 0

无法在 VS 2022 或 2019 中打开 Sql 数据库项目

我有 VS.Net 解决方案,其中有多个项目,所有项目都可以正常打开,但是我们有 SQL 文件的 SQL 项目无法打开,如果我尝试在 VS 2022 中打开它,那就是 givi。 ..

回答 1 投票 0

为什么我的 Html Helpers 没有智能感知?

我无法为我自己的 html 助手获取智能感知。我的 CustomHtmlHelpers.cs 如下所示: 使用 System.Web.Mvc; 使用系统文本; 使用系统.Web; 命名空间 laget.Web.Helpers {

回答 11 投票 0

API上是否有httpClient请求取消订单?

我想在我的应用程序中以 API 形式取消(而不是删除)Shopify 上的订单。 目前我正在使用这段代码来取消订单 公共 IActionResult 取消(双?id) { _httpClient.BaseAddress...

回答 1 投票 0

.NET MVC Core 6.0 在视图中获取会话和cookie

[浏览器>应用程序>Cookies] 我正在尝试在 .net MVC 项目中创建会话和 cookie。 当我在我的电脑上本地调试项目时,会话和 cookie 按预期工作,...

回答 1 投票 0

如何使用 Azure AD 令牌和 ASP.NET MVC 应用程序中的自定义声明对 ASP.NET Core Web API 进行身份验证?

我有两个应用程序:一个使用 ASP.NET MVC 构建,另一个使用 ASP.NET Core Web API。用户使用 Azure Active Directory (Azure AD) 登录到 ASP.NET MVC 应用程序。登录成功后...

回答 1 投票 0

jquery 验证如果另一字段不为空,则使一个字段为必填

我在使用 jQuery.validate 1.11 、.Net 4.8 和 MVC 5 with Razor 时遇到一些问题。 我的班级有这两个属性: [StringLength(500, ErrorMessage = "{0} 的最大值为 {1}

回答 1 投票 0

如何从 appsettings.json 获取密钥到 .Net8 中的 JavaScript 页面

我想从 appsettings.json 文件中获取密钥到 .net 8 MVC 项目中的 JavaScript 代码。 我已按以下方式在 appsetting.json 中添加了密钥。 应用程序设置.json { “请求计数限制&...

回答 1 投票 0

使用 Asp.Net Core Identity 进行干净架构的授权和身份验证

我是第一次学习干净和垂直切片架构,如果我们使用 ASP.NET Core Ide,我很难理解授权和身份验证将在哪里适合......

回答 1 投票 0

C# 创建 API 和 ASP.NET MVC Web 应用程序 - 需要帮助才能收到输入错误参数的警告

我正在使用 SQL Server 创建 ASP.NET Web API 和 MVC Web 应用程序。它运行良好,授权成功,但是当我测试登录屏幕时,如果我输入错误的内容,例如错误的密码...

回答 1 投票 0

为什么 ASP.Net MVC 客户端验证不触发输入位于表单元素外部但通过 form="formid" 属性链接的情况?

我正在使用 ASP.Net 8.0 MVC... ScenarioName 属性在模型中有一个必需的属性。 当我使用以下内容时,单击“提交”按钮,并将所有这些元素都包含在表单标记内...

回答 1 投票 0

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