Welcome to Jonic Developer Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
486 views
in Technique[技术] by (71.8m points)

c# - Cannot generate token in Asp WebApi, XMLHttpRequest has been blocked by CORS policy

friends I am new to Asp.net WebApi, I was trying to send a post request to generate a token from my Google Chrome and it gives me this error.

Access to XMLHttpRequest at 'http://localhost:7068/token' from origin 'http://127.0.0.1:5500' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

I can send a post request to controllers since I have enabled cors in WebApiConfig.cs here is the code I used to enable cors

EnableCorsAttribute cors = new EnableCorsAttribute("*", "*", "*"); config.EnableCors(cors);

my problem is I cannot generate a token from the WebApi it gives me the above-mentioned error.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Jonic Developer Community for programmer and developer-Open, Learning and Share
...