首页 \ 问答 \ 为什么我在DLL代码中获得断点(Why am I getting breakpoints in DLL code)

为什么我在DLL代码中获得断点(Why am I getting breakpoints in DLL code)

我有两个解决方案,A和B.在解决方案A中,我有一个项目A1(输出到DLL)。 A1最初仅在解决方案A中使用,但由于某些无法预料的情况,解决方案B中的一个项目最终需要它。

我将项目A1的DLL文件从解决方案A复制到解决方案B,并将其添加为参考。 我是以手工方式做到的; 我必须在A1发生变化时手动复制和替换DLL。

一切都很好,直到有一天,我意识到我在调试期间得到了断点。 令我惊讶的是,断点属于A1级。 我能够看到我在解决方案A上写的完整代码,包括注释。 当我从那里删除断点时,它会在我下次调试时返回。 不过,它似乎在第二天就消失了。

现在我的问题是:当我没有将A1的来源复制到解决方案B时,为什么我能够看到完整的代码? 我的理解是DLL需要反编译器返回其代码状态。 即使使用反编译器,它也应该只给我类似的东西,但不是很精确。 最令人惊讶的是我甚至可以看到我写的所有评论。

我正在使用VS2012 Pro,使用.NET 4.5。


I have two solutions, A and B. In solution A, I have a project A1 (which outputs to a DLL). A1 is originally used only within solution A, but because of some unforeseen circumstances, one of the project in solution B ended up requiring it.

I copied the DLL file of project A1 from solution A, to solution B, adding it as a reference. I did it in a manual manner; I have to copy and replace the DLL manually whenever there is a change in A1.

Everything is fine until one day, I realized that I am getting breakpoints during debug. To my surprise, the breakpoints are in the class from A1. I am able to see the full codes that I wrote on solution A, including the comments. When I remove the breakpoints from there, it would come back when I debug the next time. It seemed to disappeared the next day, though.

Now my question is: Why am I able to see the full codes when I did not copy the source of A1 to solution B? My understanding is that DLLs require a decompiler to return to its code state. Even with a decompiler, it should only give me just something similar, but not exact. The most amazing part is that I can even see the all the comments that I wrote.

I am using VS2012 Pro, using .NET 4.5.


原文:https://stackoverflow.com/questions/40580479
更新时间:2022-07-12 13:07

最满意答案

这是一种截然不同的方法,它使用内联中间件来阻止对特定路径的未经身份验证的请求:

app.Use((context, next) => {
    // Ignore requests that don't point to static files.
    if (!context.Request.Path.StartsWithSegments("/app")) {
        return next();
    }

    // Don't return a 401 response if the user is already authenticated.
    if (context.User.Identities.Any(identity => identity.IsAuthenticated)) {
        return next();
    }

    // Stop processing the request and return a 401 response.
    context.Response.StatusCode = 401;
    return Task.FromResult(0);
});

确保在您的身份验证中间件(或不会填充context.User )之后和其他中间件(在您的情况下,在静态文件中间件之前)之前注册它。 您还必须确保使用自动身份验证( AutomaticAuthenticate = true )。 如果没有,您将不得不使用身份验证API:

app.Use(async (context, next) => {
    // Ignore requests that don't point to static files.
    if (!context.Request.Path.StartsWithSegments("/app")) {
        await next();
        return;
    }

    // Don't return a 401 response if the user is already authenticated.
    var principal = await context.Authentication.AuthenticateAsync("Cookies");
    if (principal != null && principal.Identities.Any(identity => identity.IsAuthenticated)) {
        await next();
        return;
    }

    // Stop processing the request and trigger a challenge.
    await context.Authentication.ChallengeAsync("Cookies");
});

注意:如果您想阻止cookie中间件通过302重定向替换401响应,请按以下步骤操作:

使用Identity时(在ConfigureServices ):

services.AddIdentity<ApplicationUser, IdentityRole>(options => {
    options.Cookies.ApplicationCookie.Events = new CookieAuthenticationEvents {
        OnValidatePrincipal = options.Cookies.ApplicationCookie.Events.ValidatePrincipal,
        OnRedirectToLogin = context => {
            // When the request doesn't correspond to a static files path,
            // simply apply a 302 status code to redirect the user agent.
            if (!context.Request.Path.StartsWithSegments("/app")) {
                context.Response.Redirect(context.RedirectUri);
            }

            return Task.FromResult(0);
        }
    };
});

使用不带身份的cookie中间件时(在Configure ):

app.UseCookieAuthentication(options => {
    options.Events = new CookieAuthenticationEvents {
        OnRedirectToLogin = context => {
            // When the request doesn't correspond to a static files path,
            // simply apply a 302 status code to redirect the user agent.
            if (!context.Request.Path.StartsWithSegments("/app")) {
                context.Response.Redirect(context.RedirectUri);
            }

            return Task.FromResult(0);
        }
    };
});

Here's a sightly different approach, that uses an inline middleware to block unauthenticated requests for specific paths:

app.Use((context, next) => {
    // Ignore requests that don't point to static files.
    if (!context.Request.Path.StartsWithSegments("/app")) {
        return next();
    }

    // Don't return a 401 response if the user is already authenticated.
    if (context.User.Identities.Any(identity => identity.IsAuthenticated)) {
        return next();
    }

    // Stop processing the request and return a 401 response.
    context.Response.StatusCode = 401;
    return Task.FromResult(0);
});

Make sure to register it after your authentication middleware (or context.User won't be populated) and before the other middleware (in your case, before the static files middleware). You'll also have to make sure you're using automatic authentication (AutomaticAuthenticate = true). If not, you'll have to use the authentication API:

app.Use(async (context, next) => {
    // Ignore requests that don't point to static files.
    if (!context.Request.Path.StartsWithSegments("/app")) {
        await next();
        return;
    }

    // Don't return a 401 response if the user is already authenticated.
    var principal = await context.Authentication.AuthenticateAsync("Cookies");
    if (principal != null && principal.Identities.Any(identity => identity.IsAuthenticated)) {
        await next();
        return;
    }

    // Stop processing the request and trigger a challenge.
    await context.Authentication.ChallengeAsync("Cookies");
});

Note: if you want to prevent the cookies middleware from replacing the 401 response by a 302 redirect, here's how you can do:

When using Identity (in ConfigureServices):

services.AddIdentity<ApplicationUser, IdentityRole>(options => {
    options.Cookies.ApplicationCookie.Events = new CookieAuthenticationEvents {
        OnValidatePrincipal = options.Cookies.ApplicationCookie.Events.ValidatePrincipal,
        OnRedirectToLogin = context => {
            // When the request doesn't correspond to a static files path,
            // simply apply a 302 status code to redirect the user agent.
            if (!context.Request.Path.StartsWithSegments("/app")) {
                context.Response.Redirect(context.RedirectUri);
            }

            return Task.FromResult(0);
        }
    };
});

When using the cookies middleware without Identity (in Configure):

app.UseCookieAuthentication(options => {
    options.Events = new CookieAuthenticationEvents {
        OnRedirectToLogin = context => {
            // When the request doesn't correspond to a static files path,
            // simply apply a 302 status code to redirect the user agent.
            if (!context.Request.Path.StartsWithSegments("/app")) {
                context.Response.Redirect(context.RedirectUri);
            }

            return Task.FromResult(0);
        }
    };
});

相关问答

更多
  • 今天这不是很好的支持,但你可以通过在应用设置中设置一些东西来使它工作: SCM_REPOSITORY_PATH=..\repository SCM_TARGET_PATH=.. 这基本上告诉它直接在VirtualDirectory0 (而不是VirtualDirectory0\site ),然后部署到VirtualDirectory0\site (而不是VirtualDirectory0\site\wwwroot )回购回购。 这假定您的repo包含一个名为wwwroot的文件夹。 这些路径的一些信息在这 ...
  • 以下步骤适用于我,并应帮助您在IIS上托管您的项目。 使用Visual Studio 2015 Preview作为IDE, 创建一个ASP .NET 5 Starter App。 检查它是否在IIS之外工作。 完成后,发布应用程序。 在这个例子中,我选择了位置C:\PublishWebApp 。 3.1。 发布您的应用程序时,请确保您拥有: 禁用预编译 选定amd64 (见下图) 成功发布后,请转至C:\PublishWebApp 。您应该看到里面的文件夹approot和wwwroot 。 现在打开IIS管 ...
  • 去第二条路线。 wwwroot只是作为服务器默认网站的容器。 如果从IIS中删除默认网站,则可以安全地删除此目录。 无论如何,您的网站与默认值无关,因此它们应该在inetpub下的自己的文件夹中。 也就是说,我们有时在同一台服务器上有多个“类型”的网站。 例如DEV和QA。 在这种情况下,我将其结构如下: C:\的Inetpub \ dev的\ SITE1 C:\的Inetpub \ dev的\站点2 C:\的Inetpub \ QA \ SITE1 C:\的Inetpub \ QA \站点2 Go the ...
  • 像这样添加另一个排除条件: # If the request is not from /some-folder/ RewriteCond %{REQUEST_URI} !^/some-folder/ [NC] # If the file is NOT the index.php file RewriteCond %{REQUEST_FILENAME} !index.php # Hide all PHP files so none can be accessed by HTTP RewriteRule ^(. ...
  • 当我第一次使用.NET 5时,我花了很长时间试图弄清楚这一点。 不要在.NET 5中使用NuGet安装客户端软件包。使用Bower。 要使用Bower进行安装,请在解决方案资源管理器中展开项目中的“依赖关系”项。 你应该在那里看到一个“Bower”文件夹。 右键单击它并选择“Manage Bower Packages”。 在打开的窗口顶部,您可以选择“浏览”,然后搜索“jquery-ui”。 它应该显示在下面的列表中,您可以选择它并单击安装按钮。 安装完成后,您可以在wwwroot / lib / jque ...
  • 您可以将所有参考文件复制到wwwroot或更好,但创建一个吞咽/咕噜任务来做到这一点。 至于文件/目录长度问题 - 在更高版本的NPM中已修复此问题,但Visual Studio默认使用较早版本,但您可以更改它:以下是方法 。 我推荐第二种选择,对我来说非常适合。 执行此操作后,只需删除node_modules并恢复NPM包,就不应该再次出现该错误。 更新:你不需要引用任何typescpript文件,你需要的只是在你使用angular的html中: