Mensajes.Cliente
Angular 응용 프로그램을 포함하는 WebAPI 프로젝트 가 있습니다.
보안상의 이유로 모든 서버 응답에 2 개의 헤더를 추가해야합니다. Global.asax에 다음을 추가하는 문제를 해결했습니다.
protected void Application_BeginRequest()
{
Response.AddHeader("X-Frame-Options", "DENY");
Response.AddHeader("X-XSS-Protection", "1");
}
컨트롤러 메서드 중 하나를 호출하면 응답에 두 헤더가 모두 포함되어 있으므로 제대로 작동합니다.
그러나 index.html을 foo.com/Mensajes.Cliente
또는 으로 가져 오려고 할 때 foo.com/Mensajes.Cliente/index.html
헤더가 설정되지 않았습니다 (모든 정적 콘텐츠가 .js 또는 .css 파일로 발생 함).
모든 서버 요청 의 응답에 이러한 헤더를 어떻게 추가 할 수 있습니까?
이러한 헤더는 web.config 또는 Global.asax 구성에서 설정해야합니까, 아니면 서버 구성에서 설정해야합니까?
web.config
. in customHeaders
아래 의 섹션 은이 헤더가 모든 파일과 응답에 포함되어 있는지 확인합니다.httpProtocol
system.webServer
예:
<system.webServer>
<!--.......-->
<httpProtocol>
<customHeaders>
<add name="X-Frame-Options" value="DENY" />
<add name="X-XSS-Protection" value="1" />
</customHeaders>
</httpProtocol>
<!--.......-->
</system.webServer>
HttpModule
. 이렇게하면 헤더를 추가해야하는 파일과 콘텐츠를 더 많이 제어 할 수 있습니다.예:
public class CustomOrgHeaderModule : IHttpModule
{
public void Init(HttpApplication context)
{
context.PreSendRequestHeaders += OnPreSendRequestHeaders;
}
public void Dispose() { }
void OnPreSendRequestHeaders(object sender, EventArgs e)
{
//To add header only for Html files
//You can add any condition as you need
if (HttpContext.Current.Request.Url.ToString().Contains(".html"))//css, js as you need
{
HttpContext.Current.Response.Headers.Add("X-Frame-Options", "DENY");
HttpContext.Current.Response.Headers.Add("X-XSS-Protection", "1");
}
}
}
그리고 등록 CustomOrgHeaderModule
에서 web.config
-
<system.webServer>
<!--.......-->
<modules>
<add name="CustomHeaderModule" type="SOFTEST.NET.API.Modules.CustomOrgHeaderModule" /><!--.SOFTEST.NET.API.Modules.CustomOrgHeaderModule is then FullNmae of the class MEANS Namesapce.CassName -->
</modules>
<!--.......-->
</system.webServer>
그리고 당신은 세트에 필요 돈 Response.AddHeader
에 Global.asax
더 이상.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다