我试图将一个接口注入我的HomeController,我收到此错误:
InvalidOperationException:尝试激活时无法解析类型"Microsoft.Extensions.Configuration.IConfiguration"的服务
我的Startup类如下:
public Startup(IApplicationEnvironment appEnv)
{
var builder = new ConfigurationBuilder()
.SetBasePath(appEnv.ApplicationBasePath)
.AddEnvironmentVariables()
.AddJsonFile("appsettings.json");
Configuration = builder.Build();
}
public IConfigurationRoot Configuration { get; set; }
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddApplicationInsightsTelemetry(Configuration);
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<ApplicationDbContext>(options => options
.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
services.AddMvc();
services.AddSingleton(provider => Configuration);
// Add application services.
services.AddTransient<IEmailSender, AuthMessageSender>();
services.AddTransient<ISmsSender, AuthMessageSender>();
}
public void Configure(
IApplicationBuilder app,
IHostingEnvironment env,
ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
app.UseApplicationInsightsRequestTelemetry();
if (env.IsDevelopment())
{
app.UseBrowserLink();
app.UseDeveloperExceptionPage();
app.UseDatabaseErrorPage();
}
else …Run Code Online (Sandbox Code Playgroud) 我有一个 SPA 应用程序,它使用 AAD v2 身份验证与我的后端 Web API 进行通信。现在,我正在开发一个控制台应用程序来代表登录到 SPA 应用程序的用户调用 Microsoft Graph。
我有用户的有效访问令牌(用于调用后端 Web API)。我想使用此访问令牌来请求用于访问 MS Graph 的新令牌。
以下是使用 MSAL.NET 请求具有 MS Graph 范围的新访问令牌的控制台应用程序的代码:
string clientId = "<clientId>";
string clientSecret = "<clientSecret>";
string accessToken = "<validAccessTokenForWebApi>";
string assertionType = "urn:ietf:params:oauth:grant-type:jwt-bearer";
string[] scopes = new string[] { "User.Read", "Mail.Send" };
string graphAccessToken = null;
try
{
var app = ConfidentialClientApplicationBuilder
.Create(clientId).WithClientSecret(clientSecret).Build();
var userAssertion = new UserAssertion(accessToken, assertionType);
var result = app.AcquireTokenOnBehalfOf(scopes, userAssertion)
.ExecuteAsync().GetAwaiter().GetResult();
graphAccessToken = result.AccessToken;
}
catch (MsalServiceException ex) …Run Code Online (Sandbox Code Playgroud) 我正在C#asp.net中创建定时在线测试.我使用本地机器时间创建了它.但是在数据库断开连接或系统挂起的情况下,倒数计时器必须从机器挂起或意外数据库断开连接的时间开始.例如,用户正在回答问题10分钟并且意外地系统被绞死.恢复后,倒计时必须从10分钟开始.有谁能帮我用C#编码?
我使用了以下代码,但它在上面的场景中没用.
int totalTime = (Convert.ToInt32(ViewState["totaltime"])) * 60;
DateTime startTime = (DateTime)ViewState["startTime"];
TimeSpan elaspedTime = DateTime.Now.Subtract(startTime);
Literal1.Text = elaspedTime.Hours.ToString() + "h" + ":" + elaspedTime.Minutes.ToString() +
"m" + ":" + elaspedTime.Seconds.ToString() + "s";
int finish = Convert.ToInt32(elaspedTime.TotalSeconds);
int remaingsec = (totalTime - finish);
TimeSpan remainingtime = TimeSpan.FromSeconds(remaingsec);
string answer = string.Format("{0:D2}h:{1:D2}m:{2:D2}s",
remainingtime.Hours,
remainingtime.Minutes,
remainingtime.Seconds,
remainingtime.Milliseconds);
LIteral2.Text = answer;
if (totalTime == finish)
{
lnkFinish_Click(sender, e);
Response.Redirect(@"~/Error.aspx");
}
Run Code Online (Sandbox Code Playgroud) 有人可以解释为什么section计数器值在所有h2标签中都打印0 ?
这是源代码:
<!DOCTYPE html>
<html>
<head>
<style>
body {
counter-reset: section;
counter-reset: subsection;
}
h1::before {
counter-increment: section;
content: "Section " counter(section) ". ";
}
h2::before {
counter-increment: subsection;
content: counter(section) "." counter(subsection) " ";
}
</style>
</head>
<body>
<h1>HTML tutorials:</h1>
<h2>HTML Tutorial</h2>
<h2>CSS Tutorial</h2>
<h1>Scripting tutorials:</h1>
<h2>JavaScript</h2>
<h2>VBScript</h2>
<h1>XML tutorials:</h1>
<h2>XML</h2>
<h2>XSL</h2>
<p><b>Note:</b> IE8 supports these properties only if a !DOCTYPE is specified.</p>
</body>
</html>Run Code Online (Sandbox Code Playgroud)
我可以通过这样的请求访问我的一个驱动器上的文档:
https://graph.microsoft.com/v1.0/me/drive/root/children
Run Code Online (Sandbox Code Playgroud)
我可以通过这样的请求访问我公司的根共享点站点的文档库:
https://graph.microsoft.com/v1.0/drive/root/children
Run Code Online (Sandbox Code Playgroud)
它给了我“根”库的内容:
https://<my company>.sharepoint.com/Shared%20Documents
Run Code Online (Sandbox Code Playgroud)
我无法访问我创建的 SP 子站点的文档库。例如这个:
https://<my company>.sharepoint.com/samplesp/Shared%20Documents
Run Code Online (Sandbox Code Playgroud)
如何使用 MS Graph 访问这样的文档库?
c# ×2
asp.net ×1
asp.net-core ×1
asp.net-mvc ×1
countdown ×1
css ×1
javascript ×1
office365 ×1
sharepoint ×1
timer ×1