Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var apiUrl = "http://andrewgodfroyportfolioapi.azurewebsites.net/api/Authentication";
- //alert(username + "|" + password + "|" + apiUrl);
- $.ajax({
- url: apiUrl,
- type: "POST",
- data: {
- username: username,
- password: password
- },
- contentType: "application/json; charset=utf-8",
- dataType: "json",
- success: function (response) {
- var authenticatedUser = JSON.parse(response);
- //alert("Data Loaded: " + authenticatedUser);
- if (onComplete != null) {
- onComplete(authenticatedUser);
- }
- },
- error: function (xhr, status, error) {
- //alert(xhr.responseText);
- if (onComplete != null) {
- onComplete(xhr.responseText);
- }
- }
- });
- // This method gets called by the runtime. Use this method to add services to the container.
- public void ConfigureServices(IServiceCollection services)
- {
- // Add Cors
- services.AddCors(o => o.AddPolicy("MyPolicy", builder =>
- {
- builder.AllowAnyOrigin()
- .AllowAnyMethod()
- .AllowAnyHeader();
- }));
- // Add framework services.
- services.AddMvc();
- services.Configure<MvcOptions>(options =>
- {
- options.Filters.Add(new CorsAuthorizationFilterFactory("MyPolicy"));
- });
- ...
- ...
- ...
- }
- // This method gets called by the runtime. Use this method to configure
- //the HTTP request pipeline.
- public void Configure(IApplicationBuilder app, IHostingEnvironment env,
- ILoggerFactory loggerFactory)
- {
- loggerFactory.AddConsole(Configuration.GetSection("Logging"));
- loggerFactory.AddDebug();
- // Enable Cors
- app.UseCors("MyPolicy");
- //app.UseMvcWithDefaultRoute();
- app.UseMvc();
- ...
- ...
- ...
- }
- [Route("api/[controller]")]
- [EnableCors("MyPolicy")]
- public class AdminController : Controller
- .AddCustomHeader("Access-Control-Allow-Origin", "*")
- .AddCustomHeader("Access-Control-Allow-Methods", "*")
- .AddCustomHeader("Access-Control-Allow-Headers", "*")
- .AddCustomHeader("Access-Control-Max-Age", "86400")
- .AddCustomHeader("Access-Control-Allow-Methods", "GET, POST, PUT, PATCH, DELETE")
- .AddCustomHeader("Access-Control-Allow-Headers", "content-type, accept, X-PINGOTHER")
- .AddCustomHeader("Access-Control-Allow-Headers", "X-PINGOTHER, Host, User-Agent, Accept, Accept: application/json, application/json, Accept-Language, Accept-Encoding, Access-Control-Request-Method, Access-Control-Request-Headers, Origin, Connection, Content-Type, Content-Type: application/json, Authorization, Connection, Origin, Referer")
- app.UseSecurityHeadersMiddleware(new SecurityHeadersBuilder()
- .AddDefaultSecurePolicy()
- .AddCustomHeader("Access-Control-Allow-Origin", "http://localhost:3000")
- .AddCustomHeader("Access-Control-Allow-Methods", "OPTIONS, GET, POST, PUT, PATCH, DELETE")
- .AddCustomHeader("Access-Control-Allow-Headers", "X-PINGOTHER, Content-Type, Authorization"));
- Install-Package Microsoft.AspNetCore.Cors
- public void ConfigureServices(IServiceCollection services)
- {
- services.AddCors();
- }
- public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
- {
- app.UseMvc();
- app.UseCors(
- options => options.WithOrigins("http://example.com").AllowAnyMethod()
- );
- }
- var JSON = JSON || {};
- // implement JSON.stringify serialization
- JSON.stringify = JSON.stringify || function (obj) {
- var t = typeof (obj);
- if (t != "object" || obj === null) {
- // simple data type
- if (t == "string") obj = '"' + obj + '"';
- return String(obj);
- }
- else {
- // recurse array or object
- var n, v, json = [], arr = (obj && obj.constructor == Array);
- for (n in obj) {
- v = obj[n]; t = typeof (v);
- if (t == "string") v = '"' + v + '"';
- else if (t == "object" && v !== null) v = JSON.stringify(v);
- json.push((arr ? "" : '"' + n + '":') + String(v));
- }
- return (arr ? "[" : "{") + String(json) + (arr ? "]" : "}");
- }
- };
- // implement JSON.parse de-serialization
- JSON.parse = JSON.parse || function (str) {
- if (str === "") str = '""';
- eval("var p=" + str + ";");
- return p;
- };
- data: JSON.stringify({
- username: username,
- password: password
- }),
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement