我被CORS政策屏蔽。我已允许在我的startup.cs中访问所有内容。这是我的startup.cs
<form method="post" id="loginForm">
Username <input action='/userLogin' placeholder="email" class="form-control" name="email" id="email" type="text" required="">
Password <input placeholder="Password" id="password" class="form-control" name="password" type="password">
<input type="checkbox" id="user" checked="checked"> User
<input type="checkbox" id="adminAction"> Admin
<a href="#" class="text-right text-white text-capitalize">forgot password?</a>
<input type="submit" value="Log In">
<a href="/register" class="text-white font-weight-bold"> Register Now</a>
</form>
<script>
$(document).ready(function(){
$('#adminAction').change(function(){
var checked = $('#adminAction').is(':checked');
if(checked){
$('#loginForm').attr('action','/adminLogin');
}
else{
$('#loginForm').attr('action','/userLogin');
}
})
});
</script>
答案 0 :(得分:0)
只需在您的ConfigureServices
部分中添加以下行,它就可以正常工作:
var corsBuilder = new CorsPolicyBuilder();
corsBuilder.AllowAnyHeader();
corsBuilder.WithMethods("GET", "POST");
corsBuilder.AllowAnyOrigin();
services.AddCors(options => options.AddPolicy("AllowAll",corsBuilder.Build()));
答案 1 :(得分:0)
请遵循documentation。
首先,您需要在ConfigureServices()
内启用CORS中间件
其次,您需要告诉应用程序在Configure()
示例:
在ConfigureServices()
中:
services.AddCors(options =>
{
options.AddPolicy("AllowAllOrigins",
builder =>
{
builder
.AllowAnyOrigin()
.AllowAnyHeader()
.AllowAnyMethod();
});
});
在Configure()
中:
app.UseCors("AllowAllOrigins");