jexus手动跨域设置
AP.NET MVC默认跨域方法如下:
- <system.webServer>
- <validation validateIntegratedModeConfiguration="false" />
- <modules runAllManagedModulesForAllRequests="true" />
- <httpProtocol>
- <customHeaders>
- <add name="Access-Control-Allow-Origin" value="*" />
- <add name="Access-Control-Allow-Headers" value="Content-Type" />
- <add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE, OPTIONS" />
- </customHeaders>
- </httpProtocol>
但是这个在Jexus好像不起使用,于是手动增加代码,ASP.NET MVC 手动增加跨域设置,在basecontrol中增加如下代码:
- protected override void OnResultExecuted(ResultExecutedContext filterContext)
- {
- base.OnResultExecuted(filterContext);
- filterContext.HttpContext.Response.AddHeader("Access-Control-Allow-Origin", "*");
- filterContext.HttpContext.Response.AddHeader("Access-Control-Allow-Methods", "POST,GET");
- db.Dispose();
- }
最后效果如下:
============ 欢迎各位老板打赏~ ===========
与本文相关的文章
- · 关于AJAX跨域调用ASP.NET MVC或者WebAPI服务的问题及解决方案
- · centos安装node18
- · The instance of entity type ‘Customer’ cannot be tracked because another instance with the same key value for {‘Id’} is already being tracked.
- · .NET8实时更新nginx ip地址归属地
- · 解决.NET Blazor子组件不刷新问题
- · nginx日志按天分割
- · .NET8如何在普通类库中引用 Microsoft.AspNetCore
- · 解决Linux实例磁盘空间满问题
- · .NET8 Mysql SSL error
- · ASP.NET Core MVC的Razor视图渲染中文乱码的问题
- · centos yum安装Python3.8(史上最简单)
- · linux查看端口占用 netstat -tln|grep 8080