为什么我不能使用HttpContext
或HttpCookie
?有什么特殊用途吗?
我的实际用途:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
Run Code Online (Sandbox Code Playgroud)
我的命名空间:
namespace eCoffee.Main
Run Code Online (Sandbox Code Playgroud)
我的课程+方法:
public class AppRunCookie
{
public static string CookieName { get; set; }
public static string Key { get; set; }
public AppRunCookie(string key)
{
CookieName = "MyCookie_" + key;
}
public static void SetCookie(string key, int cookieExpireDate = 30)
{
HttpCookie myCookie = new HttpCookie(CookieName);
myCookie["Key"] = key;
myCookie.Expires = DateTime.Now.AddDays(cookieExpireDate);
HttpContext.Current.Response.Cookies.Add(myCookie);
}
public string GetCookie()
{
HttpCookie myCookie = HttpContext.Current.Request.Cookies[CookieName];
if …
Run Code Online (Sandbox Code Playgroud) 最近,我遇到了一个问题,并通过清理解决方案来解决它。但现在我遇到了同样的问题,清理解决方案并不能解决我的错误。在我的项目中,我使用模态来显示表单。因此,我使用 EditForm 创建了一个模式组件,以在数据库中生成一个新实体。
<div class="modal">
<div class="modal-body">
<div class="row">
<div class="col s12">
<h5>New Item</h5>
</div>
</div>
<div class="row">
<EditForm Model="MyEntity" OnValidSubmit="OnValidSubmit" OnInvalidSubmit="OnInvalidSubmit">
<DataAnnotationsValidator />
<ValidationSummary></ValidationSummary>
<div class="input-field fixed col s12">
<InputText id="name" @bind-Value="MyEntity.Name" />
<label class="active" for="name">Name</label>
</div>
<div class="col s12">
<button class="right btn" type="submit">Create</button>
</div>
</EditForm>
</div>
</div>
<div class="modal-footer">
<button class="modal-close btn-flat">Close</button>
</div>
</div>
@code {
[Parameter]
public MyEntityClass MyEntity {get; set;}
[Parameter]
public EventCallback<Microsoft.AspNetCore.Components.Forms.EditContext> OnValidSubmit { get; set; }
[Parameter]
public EventCallback<Microsoft.AspNetCore.Components.Forms.EditContext> OnInvalidSubmit { get; set; } …
Run Code Online (Sandbox Code Playgroud) 在使用新部署的启用身份验证的 MongoDB 容器设置新环境时,我遇到了以下异常:"An unhandled exception has occurred while executing the request. MongoDB.Driver.MongoConnectionException: An exception occurred while opening a connection to the server. ---> System.NotSupportedException: Unable to create an authenticator."
就我而言,我使用的连接字符串如下例所示:mongodb://USER:PASSWORD@HOST:27017/?authMechanism=DEFAULT
。该字符串在 MongoDB Compass 中工作得很好,但在我的 .NET 6.0 应用程序中却不行。
我正在使用分布式Redis缓存暂时缓存一些用户数据.目前我正在我的开发环境中本地测试应用程序.我本地计算机上的Redis-Server没有密码,但在生产中我使用的是随机生成的密码.
如何使用密码连接到Redis-Server?
我的Startup.cs:
//Add Redis
services.AddDistributedRedisCache(options =>
{
options.Configuration = "127.0.0.1:6379";
options.InstanceName = "Portal";
});
Run Code Online (Sandbox Code Playgroud) 我尝试在Swisscom Appcloud上运行ASP.NET Core MVC Web应用程序.但是当我启动应用程序时,我在控制台中看到以下错误消息:
2017-01-24 14:29:53 [CELL/0] ERR Timed out after 1m0s: health check never passed.
Run Code Online (Sandbox Code Playgroud)
它看起来像Appcloud无法检查我的应用程序的健康状况.我是否需要安装Nuget-Package或其他东西才能启动并运行?
谢谢你的努力
asp.net asp.net-mvc nuget-package asp.net-core-mvc swisscomdev
我想检查我的Listentry是否为null但我不知道如何.
注意:ID是整数
这是我的代码
if(MeineGaeste[i].ID !=null)
{
i++;
}
else
{
MeinGast.ID = i++;
test = false;
}
Run Code Online (Sandbox Code Playgroud) asp.net-mvc ×3
c# ×3
asp.net ×2
.net-core ×1
blazor ×1
caching ×1
cookies ×1
if-statement ×1
integer ×1
mongodb ×1
null ×1
razor ×1
redis ×1
security ×1
swisscomdev ×1