如何替换页眉/页脚中的"FIELD"?
例如:带有文件名和日期的Word doc文件.代替文件路径 - [FilePath]而不是C://Documents/Location/Filename.doc, [Date]而不是18/07/2013.
我可以用范围替换任何文本.
foreach (Microsoft.Office.Interop.Word.Section section in wordDocument.Sections)
{
section.Headers[WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.Text.Replace(sourceDocPath, "[File Path]");
section.Footers[WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.Text.Replace(sourceDocPath, "[File Path]");
}
Run Code Online (Sandbox Code Playgroud)
这适用于文件名,但是对于Date,无法猜测要替换的格式.这都是因为我无法捕获要替换的确切字段信息.
以下代码也是我无法使用的
wordApp.Selection.Find.Execute(ref textToReplace, ref typeMissing,
ref typeMissing, ref typeMissing, ref typeMissing, ref typeMissing,
ref typeMissing, ref typeMissing, ref typeMissing, ref typeMissing,
ref replaceTextWith, ref replaceAll, ref typeMissing, ref typeMissing,
ref typeMissing, ref typeMissing);
Run Code Online (Sandbox Code Playgroud)
我现在看到的唯一方法是处理所有可能的日期格式并替换,但这对我来说似乎不是一个好方法.
根据使用Storyrange给出的评论进行更新.
没有给我确切的字段信息说[日期].当我遍历故事范围时,我得到的类型信息是wdstorytype,这是关于部分信息,关于字段信息.
foreach (Microsoft.Office.Interop.Word.Range tmpRange in wordDocument.StoryRanges)
{
string strtype = tmpRange.StoryType.ToString();
tmpRange.Find.Text = "18/07/2013";
tmpRange.Find.Replacement.Text = "";
tmpRange.Find.Replacement.ParagraphFormat.Alignment =
Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphJustify;
tmpRange.Find.Wrap = Microsoft.Office.Interop.Word.WdFindWrap.wdFindContinue;
object …
Run Code Online (Sandbox Code Playgroud) 在 swashbuckle 2.2.0(带有 swagger 2.0)中,授权后响应位于弹出窗口上,这与 1.1.0(以前是页面加载)不同
如果上下文用户身份验证未经过身份验证,我们会进行类似隐藏/显示未经授权的 api 的操作,反之亦然。
Github Swashbuckle 问题 希望有人能找到解决方案或已经尝试过。
不会发送身份验证上下文来重新加载踢出 IdocumentFilter 的页面。
public class HideUnauthorizedOperations : IDocumentFilter
{
private IHttpContextAccessor _httpContext;
public HideUnauthorizedOperations(IHttpContextAccessor httpContext)
{
_httpContext = httpContext;
}
public void Apply(SwaggerDocument swaggerDoc, DocumentFilterContext context)
{
var authenticated = _httpContext.HttpContext.User.Identity.IsAuthenticated;
//TODO context user is null, need to fix the authentication
//if (!authenticated)
//{
// foreach (var values in swaggerDoc.Paths.Values)
// {
// var nullifyThese = new List<Operation>();
// foreach (var operation in values.EnumerateOperations())
// {
// …
Run Code Online (Sandbox Code Playgroud) Swagger UI端点与登台时的dev不同(不包括域名)
IIS配置
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
app.UseSwagger(c=>
{
//Change the path of the end point , should also update UI middle ware for this change
c.RouteTemplate = "api-docs/{documentName}/swagger.json";
});
app.UseSwaggerUI(c =>
{
//Include virtual directory if site is configured so
c.SwaggerEndpoint(Configuration["Appsettings:VirtualDirectory"]+"api-docs/v1/swagger.json", "Api v1");
});
services.AddSwaggerGen(c =>
{
var xmlDocPath = Path.Combine(PlatformServices.Default.Application.ApplicationBasePath, "Api.xml");
c.IncludeXmlComments(xmlDocPath);
c.DescribeAllEnumsAsStrings();
Run Code Online (Sandbox Code Playgroud)
具有上述配置
发展
"AppSettings": {
"VirtualDirectory": "/"
Run Code Online (Sandbox Code Playgroud)
}
分期
"AppSettings": {
"VirtualDirectory": "/Api/"
Run Code Online (Sandbox Code Playgroud)
}
启动计算机上UI的结束点,暂存时间为ON
http://localhost:5001/api-docs/v1/swagger.json
Run Code Online (Sandbox Code Playgroud)
但在登台服务器上是相同的
http://xxxx:5002/swagger/Api/api-docs/v1/swagger.json
Run Code Online (Sandbox Code Playgroud)
而不是(应该是什么)
http://xxxx:5002/Api/api-docs/v1/swagger.json
Run Code Online (Sandbox Code Playgroud)