当前,我在IIS 10中发布了带有vue js的Web应用程序api,我从同一台PC访问以下站点:www.ollitarustica.com,以前更改了主机文件的配置:127.0.0.1 www.ollitarustica。 com,同样将axios的基本URL更改为:www.ollitarustica.com,从同一台PC可以正常访问所有内容,但是现在我需要连接到同一LAN的其他设备(PC,平板电脑,手机)进行访问直到现在,在IISS上发布的Web应用程序都进行了一些失败的尝试,并且由于我的经验不足,这非常困难,以下是发布站点的当前配置:
IIS的配置:
Startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
services.AddDbContext<DbContextSistema>(options =>
options.UseSqlServer(Configuration.GetConnectionString("Conexion")));
services.AddCors(options => {
options.AddPolicy("Todos",
builder => builder.WithOrigins("*").WithHeaders("*").WithMethods("*"));
});
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = true,
ValidateAudience = true,
ValidateLifetime = true,
ValidateIssuerSigningKey = true,
ValidIssuer = Configuration["Jwt:Issuer"],
ValidAudience = Configuration["Jwt:Issuer"],
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["Jwt:Key"]))
};
});
services.AddMvc();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseHsts();
}
app.UseCors("Todos");
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseAuthentication();
app.UseMvc(routes => {
routes.MapRoute(name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
routes.MapSpaFallbackRoute(
name: "spa-fallback",
defaults: new { controller = "Home", action = "Index" });
});
}
}
appsettings.json
"ConnectionStrings": {
//"Conexion": "Server=(localdb)\\mssqllocaldb;Database=dbsistema;Trusted_Connection=True;MultipleActiveResultSets=true"
"Conexion": "data source=.\\SQLEXPRESS;initial catalog=dbsistema;user id=sa;password=jucardi7;persist security info=True;"
},
"Logging": {
"LogLevel": {
"Default": "Warning"
}
},
"AllowedHosts": "*",
"Jwt": {
"Key": "Clave Personalizada",
"Issuer": "http://localhost:63038"
}
答案 0 :(得分:0)
由于hosts文件仅在您的本地计算机上工作,因此当您在另一台计算机上使用该域时,该域将不会映射到IP地址。
如果要让域映射到IIS服务器IP地址,则应创建一个DNS服务器并添加IP地址记录。
有关如何创建DNS服务器和添加域记录的更多详细信息,建议您参考以下文章:
https://www.vultr.com/docs/setup-a-dns-server-on-windows-server-2012