我有一个MVC ActionResult控制器,可以下载文件。
如果是PDF,则使用此JS代码
//my server client registration code
var webClient = new IdentityServer4.EntityFramework.Entities.Client
{
ClientId = "mvc",
ClientName = "MVC Client",
Description = "Test MVC Client",
RequireConsent = false,
AlwaysIncludeUserClaimsInIdToken = true,
AllowedScopes = new List<ClientScope>
{
new ClientScope
{
Scope = IdentityServerConstants.StandardScopes.OpenId
},
new ClientScope
{
Scope = IdentityServerConstants.StandardScopes.Profile
}
}
};
//set the grant type
webClient.AllowedGrantTypes = new List<ClientGrantType>
{
new ClientGrantType
{
GrantType = GrantType.Implicit,
Client = webClient
}
};
// where to redirect to after login
webClient.RedirectUris = new List<ClientRedirectUri>
{
new ClientRedirectUri
{
RedirectUri = "http://localhost:5000/signin-oidc",
Client = webClient
}
};
// where to redirect to after logout
webClient.PostLogoutRedirectUris = new List<ClientPostLogoutRedirectUri>
{
new ClientPostLogoutRedirectUri
{
PostLogoutRedirectUri="http://localhost:5000/signout-callback-oidc",
Client = webClient
}
};
//Client configuration
services.AddAuthentication(options =>
{
options.DefaultScheme = "Cookies";
options.DefaultChallengeScheme = "oidc";
})
.AddCookie("Cookies")
.AddOpenIdConnect("oidc", options =>
{
options.Authority = "http://localhost:5010";
options.RequireHttpsMetadata = false;
options.ClientId = "mvc";
options.ClientSecret = "client secret".ToSha256();
options.SaveTokens = true;
options.CallbackPath = "/signin-oidc";
});
i have added app.UseAuthentication() to configure method
然后,我可以在应用程序中预览PDF。
我想要类似的XLSX或XLS文件。
如果我点击url,我会得到文件,但无法显示。
我尝试过
var $obj = $('<object>');
$obj.attr("type", "application/pdf");
$obj.attr("data", myurl);
$("#id").append($obj);
但不起作用。
有什么想法吗?