小编Din*_*h M的帖子

通过ASP NET Core中的HTTP请求记录IIS自定义字段

我为我的网站启用了带有自定义字段的IIS日志记录。

在此处输入图片说明

以前在MVC中,我曾使用HTTPHandlers和Module将上述字段添加到HTTP Request标头中。

web.config:

 <modules runAllManagedModulesForAllRequests="true">
     <!--Handler to process the IIS logs of the site Pagevisit logs-->
    <add name="IISLogger" type="MySite.Website.MvcApplication.Utils.IISLogHandler, MySite.Website.MvcApplication" />
</modules>
Run Code Online (Sandbox Code Playgroud)

IISLogHandler类:

public class IISLogHandler : IHttpModule
    {
        public void Init(HttpApplication context)
        {
            context.BeginRequest += new EventHandler(context_BeginRequest);
        }

        private void context_BeginRequest(object sender, EventArgs e)
        {
              var request = (sender as HttpApplication).Request;
              request.Headers["IIID"] = iiid;
              request.Headers["IID"] = !string.IsNullOrEmpty(customerId) ? 
               customerId : iid;

        }
}
Run Code Online (Sandbox Code Playgroud)

我生成的日志:

在此处输入图片说明

如何将其迁移到ASPNET Core 2.2.0?

c# middleware iis-logs httprequest asp.net-core

10
推荐指数
1
解决办法
104
查看次数

如何在 ASP.NET MVC 4 中为 CSP 使用动态随机数

我在 ASP.NET MVC 4 中开发了 MVC 应用程序。我在几个页面中使用了 javascripts。一些 javascripts 被引用为

@Scripts.Render("~/Scripts/bootstrap")
@Scripts.Render("~/Scripts/js")
Run Code Online (Sandbox Code Playgroud)

还有一些内联脚本,比如

<script type="javascript">

   // javascript code
</script>
Run Code Online (Sandbox Code Playgroud)

我想为这个网站实施内容安全政策。该站点托管在 IIS 中。所以在 IIS 中,我在 HTTP 响应头中添加 content-security-policy 头作为

object-src 'none';
?script-src 'nonce-{random}' 'unsafe-inline' 'unsafe-eval' 'strict-dynamic' https: http:;
?base-uri 'self';
?report-uri https://csp.withgoogle.com/csp/<unique_id>/<application_version>
Run Code Online (Sandbox Code Playgroud)

因此,每个响应都将包含此标头。

问题:

  1. 我如何将随机生成的 nonce 添加到脚本标签中,重要的是 IIS 如何知道随机生成的 nonce 值,以便它可以包含在响应标头中?(我假设每个响应都具有唯一的 nonce 值)

javascript iis asp.net-mvc nonce content-security-policy

7
推荐指数
1
解决办法
3828
查看次数

AMP 页面未在我的开发站点中重定向 [非 Wordpress]

我为现有页面添加了一个新的放大器页面。

下面是在我的原始页面中添加的标记

<link rel="canonical" href="https://staging.example.com/blazor">

<link rel="amphtml" href="https://staging.example.com/blazor/amp">
Run Code Online (Sandbox Code Playgroud)

下面是在我的 AMP 页面中添加的标记

<link rel="canonical" href="https://staging.example.com/blazor">
Run Code Online (Sandbox Code Playgroud)

但是,当我在移动设备中打开我的开发网站页面(此页面在robots.txt文件中除外)时,该页面不会重定向到 AMP 页面。

我是否需要为此行为添加任何重定向代码,还是因为我的开发网站页面未在 google 中编入索引?

我的网站托管在IIS 中,并使用ASP.NET MVC Web 应用程序开发

html c# iis asp.net-mvc amp-html

6
推荐指数
1
解决办法
232
查看次数

在 Firefox 中加载后备背景图像

我一直致力于提高我的网站页面速度。我计划使用 AVIF 格式的图像。此图像格式仅在最新的 Chrome 浏览器版本中受支持。为了提供后备图像,我使用了这个 CSS:

.banner-bg {
  background-image: url('https://cdn.xyz.com/content/images/desktop_banner_bg.jpg'), linear-gradient(90deg, rgb(246, 250, 255) 0%, rgb(244, 249, 255) 33%, rgb(213, 227, 255) 70%, rgb(211, 225, 255) 100%);
}

.banner-bg{
  background: url('https://cdn.xyz.com/content/images/desktop_banner_bg-updated.avif'), linear-gradient(90deg, rgb(246, 250, 255) 0%, rgb(244, 249, 255) 33%, rgb(213, 227, 255) 70%, rgb(211, 225, 255) 100%);
}
Run Code Online (Sandbox Code Playgroud)

这在 Chrome 中工作正常,其中仅加载 AVIF bg 图像并忽略 jpg 格式。在旧版本的 Chrome 中,忽略 AVIF 格式,加载 jpg 格式。

页面中只加载了一张图片。而在 Firefox 和其他浏览器中,忽略 AVIF 格式并且不加载 jpg。我尝试使用下面的代码,它有效,但两种格式的图像都加载到页面中,这增加了我的页面大小。

.banner-bg {
  background-image: url('https://cdn.xyz.com/content/images/desktop_banner_bg.jpg'), url('https://cdn.xyz.com/content/images/desktop_banner_bg-updated.avif'), linear-gradient(90deg, rgb(246, 250, 255) 0%, rgb(244, …
Run Code Online (Sandbox Code Playgroud)

html css fallback pagespeed avif

6
推荐指数
1
解决办法
272
查看次数

Azure AD API将System.Security.Principal.GenericIdentity.IsAuthenticated返回为false

我正在尝试集成我的Web服务以使用Azure AD进行身份验证.Azure AD的响应每次都有所不同.当我在firefox普通浏览器中打开我的网站时,IsAuthenticated为true.

IsAuthenticatedAsTrue

在私人浏览器中打开,IsAuthenticated是错误的.

IsAuthenticatedAsFalse

我能看到的唯一区别是,IsAuthenticated true来自ClaimsIdentity而IsAuthenticated false来自GenericIdentity.

以下是我的startup.auth代码.

public partial class Startup
{
    private static string clientId = ConfigurationManager.AppSettings["ClientId"];
    private static string aadInstance = ConfigurationManager.AppSettings["AADInstance"];
    private static string tenantId = ConfigurationManager.AppSettings["TenantId"];
    private static string postLogoutRedirectUri = ConfigurationManager.AppSettings["PostLogoutRedirectUri"];
    private static string authority = aadInstance + tenantId;

    public void ConfigureAuth(IAppBuilder app)
    {
        app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);

        app.UseCookieAuthentication(new CookieAuthenticationOptions());

        app.UseOpenIdConnectAuthentication(
            new OpenIdConnectAuthenticationOptions
            {
                ClientId = clientId,
                Authority = authority,
                PostLogoutRedirectUri = postLogoutRedirectUri
            });
    }
}
Run Code Online (Sandbox Code Playgroud)

以下是我将身份验证请求发送到AzureAD的代码

    public void LoginUsingAzure()
    {
        HttpContext.GetOwinContext().Authentication.Challenge(new AuthenticationProperties { RedirectUri …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc azure dotnetopenauth azure-active-directory

5
推荐指数
1
解决办法
650
查看次数

MS SQL Server 中的默认索引

当我使用下面的查询为 MS SQL Server 中的列创建索引时

create index IX_indexname on tablename(columnname);
Run Code Online (Sandbox Code Playgroud)

如果不提及它是聚集索引还是非聚集索引,那么将创建什么索引?默认索引是哪个?

sql sql-server indexing clustered-index non-clustered-index

5
推荐指数
1
解决办法
2878
查看次数

在Firefox和IE中使用jquery防止onbeforeunload警报

onbeforeunload当用户尝试离开页面时,我使用事件来显示默认警报框。

此对话框显示在“表单发布”操作中。

我曾经使用过event.preventDefault()(对于return nullSafari 浏览器除外的浏览器)和Safari,以防止在Form post操作中显示此对话框。但这在Firefox和IE中不起作用。

下面是jQuery代码示例

if (!isSafari) {
        window.addEventListener("beforeunload", function (event) {
            if (!hideDefaultAlert) {
                event.returnValue = "Your unsaved changes will be lost";
            } else {
                event.preventDefault();
                hideDefaultAlert = false;
            }
        });
    } else if (isSafari) {
        $(window).on("beforeunload", function () {
            if (!hideDefaultAlert) {
                return "Your unsaved changes will be lost";
            } else {
                hideDefaultAlert = false;
                return null;
            }           
        });
    }
Run Code Online (Sandbox Code Playgroud)

请为此提供解决方案,以防止Firefox和Safari中出现此警报。

提前致谢。

firefox jquery internet-explorer onbeforeunload

5
推荐指数
1
解决办法
109
查看次数

如何使用C#将交易数据记录到GA E-Commerce

当前正在使用GTag将购买数据记录到Google Analytics(分析)电子商务中。我正在使用标准电子商务。现在将把这个过程作为后期处理。(即)需要使用C#应用程序将购买数据记录到GA E-Commerce。Google是否为此过程提供任何C#API?

c# google-analytics-api e-commerce

5
推荐指数
1
解决办法
37
查看次数

嵌套Using语句影响性能

     using (var db1 = new DataBase1Entities())
        {
           using (var db2 = new DataBase2Entities())
           {
                var list = (from obj in db2.Table1
                            where !db1.Table2.Any(i => i.Table2Col == obj.Table1Col)
                            select obj).ToList();
           }
        }
Run Code Online (Sandbox Code Playgroud)

有谁知道如何从一个数据库表中检索值并将其与另一个数据库表进行比较?如果上面的代码是正确的,那么会导致性能问题吗?

c# linq performance ado.net using

1
推荐指数
1
解决办法
556
查看次数